Search in sources :

Example 21 with Message

use of org.apache.ignite.plugin.extensions.communication.Message in project ignite by apache.

the class GridIoManagerBenchmark0 method testThroughput.

/**
     * @throws Exception If failed.
     */
@SuppressWarnings("deprecation")
public void testThroughput() throws Exception {
    final IgniteKernal sndKernal = (IgniteKernal) grid(0);
    final IgniteKernal rcvKernal = (IgniteKernal) grid(1);
    final ClusterNode sndNode = sndKernal.localNode();
    final ClusterNode rcvNode = rcvKernal.localNode();
    final GridIoManager snd = sndKernal.context().io();
    final GridIoManager rcv = rcvKernal.context().io();
    info("Senders: " + THREADS);
    info("Messages: " + CONCUR_MSGS);
    final Semaphore sem = new Semaphore(CONCUR_MSGS);
    final LongAdder8 msgCntr = new LongAdder8();
    final String topic = "test-topic";
    rcv.addMessageListener(topic, new GridMessageListener() {

        @Override
        public void onMessage(UUID nodeId, Object msg) {
            try {
                rcv.sendToCustomTopic(sndNode, topic, (Message) msg, PUBLIC_POOL);
            } catch (IgniteCheckedException e) {
                error("Failed to send message.", e);
            }
        }
    });
    snd.addMessageListener(topic, new GridMessageListener() {

        @Override
        public void onMessage(UUID nodeId, Object msg) {
            msgCntr.increment();
            sem.release();
        }
    });
    Timer t = new Timer("results-reporter");
    t.schedule(new TimerTask() {

        private long ts = System.currentTimeMillis();

        @Override
        public void run() {
            long newTs = System.currentTimeMillis();
            long qrys = msgCntr.sumThenReset();
            long time = newTs - ts;
            X.println("Communication benchmark [qps=" + qrys * 1000 / time + ", executed=" + qrys + ", time=" + time + ']');
            ts = newTs;
        }
    }, 10000, 10000);
    final AtomicBoolean finish = new AtomicBoolean();
    IgniteInternalFuture<?> f = GridTestUtils.runMultiThreadedAsync(new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            try {
                IgniteUuid msgId = IgniteUuid.randomUuid();
                while (!finish.get()) {
                    sem.acquire();
                    snd.sendToCustomTopic(rcvNode, topic, new GridTestMessage(msgId, (String) null), PUBLIC_POOL);
                }
            } catch (IgniteCheckedException e) {
                X.println("Message send failed", e);
            } catch (InterruptedException ignored) {
            // No-op.
            }
            return null;
        }
    }, THREADS, "send-thread");
    Thread.sleep(TEST_TIMEOUT);
    finish.set(true);
    sem.release(CONCUR_MSGS * 2);
    t.cancel();
    f.get();
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteKernal(org.apache.ignite.internal.IgniteKernal) Message(org.apache.ignite.plugin.extensions.communication.Message) GridMessageListener(org.apache.ignite.internal.managers.communication.GridMessageListener) Semaphore(java.util.concurrent.Semaphore) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) Timer(java.util.Timer) TimerTask(java.util.TimerTask) GridIoManager(org.apache.ignite.internal.managers.communication.GridIoManager) IgniteUuid(org.apache.ignite.lang.IgniteUuid) UUID(java.util.UUID) LongAdder8(org.jsr166.LongAdder8)

Example 22 with Message

use of org.apache.ignite.plugin.extensions.communication.Message in project ignite by apache.

the class GridIoManagerBenchmark0 method testVariableLoad.

/**
     * @throws Exception If failed.
     */
@SuppressWarnings("deprecation")
public void testVariableLoad() throws Exception {
    final IgniteKernal sndKernal = (IgniteKernal) grid(0);
    final IgniteKernal rcvKernal = (IgniteKernal) grid(1);
    final ClusterNode sndNode = sndKernal.localNode();
    final ClusterNode rcvNode = rcvKernal.localNode();
    final GridIoManager snd = sndKernal.context().io();
    final GridIoManager rcv = rcvKernal.context().io();
    info("Senders: " + THREADS);
    info("Messages: " + CONCUR_MSGS);
    final Semaphore sem = new Semaphore(CONCUR_MSGS);
    final LongAdder8 msgCntr = new LongAdder8();
    final String topic = "test-topic";
    final Map<IgniteUuid, CountDownLatch> latches = new ConcurrentHashMap8<>();
    rcv.addMessageListener(topic, new GridMessageListener() {

        @Override
        public void onMessage(UUID nodeId, Object msg) {
            try {
                rcv.sendToCustomTopic(sndNode, topic, (Message) msg, PUBLIC_POOL);
            } catch (IgniteCheckedException e) {
                error("Failed to send message.", e);
            }
        }
    });
    snd.addMessageListener(topic, new GridMessageListener() {

        @Override
        public void onMessage(UUID nodeId, Object msg) {
            msgCntr.increment();
            sem.release();
            CountDownLatch latch = latches.get(((GridTestMessage) msg).id());
            if (latch != null)
                latch.countDown();
        }
    });
    final AtomicBoolean finish = new AtomicBoolean();
    final AtomicReference<CountDownLatch> latchRef = new AtomicReference<>();
    IgniteInternalFuture<?> f = GridTestUtils.runMultiThreadedAsync(new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            while (!finish.get()) {
                CountDownLatch latch = latchRef.get();
                if (latch != null)
                    U.await(latch);
                IgniteUuid msgId = IgniteUuid.randomUuid();
                sem.acquire();
                snd.sendToCustomTopic(rcvNode, topic, new GridTestMessage(msgId, (String) null), PUBLIC_POOL);
            }
            return null;
        }
    }, THREADS, "send-thread");
    IgniteInternalFuture<?> f1 = GridTestUtils.runMultiThreadedAsync(new Callable<Object>() {

        private long ts = System.currentTimeMillis();

        @Override
        public Object call() throws Exception {
            try {
                while (!finish.get()) {
                    info(U.nl() + ">>>" + U.nl() + ">>> High load." + U.nl() + ">>>");
                    U.sleep(15 * 1000);
                    reportNumbers();
                    info(U.nl() + ">>>" + U.nl() + ">>> Low load." + U.nl() + ">>>");
                    CountDownLatch latch = new CountDownLatch(1);
                    try {
                        // Here will be a pause.
                        latchRef.set(latch);
                        U.sleep(7 * 1000);
                        reportNumbers();
                    } finally {
                        latch.countDown();
                    }
                }
            } catch (IgniteCheckedException e) {
                X.println("Message send failed", e);
            }
            return null;
        }

        /**
             *
             */
        void reportNumbers() {
            long newTs = System.currentTimeMillis();
            long qrys = msgCntr.sumThenReset();
            long time = newTs - ts;
            X.println("Communication benchmark [qps=" + qrys * 1000 / time + ", executed=" + qrys + ", time=" + time + ']');
            ts = newTs;
        }
    }, 1, "load-dispatcher");
    IgniteInternalFuture<?> f2 = GridTestUtils.runMultiThreadedAsync(new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            while (!finish.get()) {
                U.sleep(1000);
                IgniteUuid msgId = IgniteUuid.randomUuid();
                CountDownLatch latch = new CountDownLatch(1);
                latches.put(msgId, latch);
                snd.sendToCustomTopic(rcvNode, topic, new GridTestMessage(msgId, (String) null), PUBLIC_POOL);
                long start = System.currentTimeMillis();
                latch.await();
                info("Response time: " + (System.currentTimeMillis() - start));
            }
            return null;
        }
    }, THREADS, "low-loader");
    Thread.sleep(TEST_TIMEOUT);
    finish.set(true);
    sem.release(CONCUR_MSGS * 2);
    f.get();
    f1.get();
    f2.get();
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteKernal(org.apache.ignite.internal.IgniteKernal) Message(org.apache.ignite.plugin.extensions.communication.Message) ConcurrentHashMap8(org.jsr166.ConcurrentHashMap8) GridMessageListener(org.apache.ignite.internal.managers.communication.GridMessageListener) AtomicReference(java.util.concurrent.atomic.AtomicReference) Semaphore(java.util.concurrent.Semaphore) CountDownLatch(java.util.concurrent.CountDownLatch) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridIoManager(org.apache.ignite.internal.managers.communication.GridIoManager) IgniteUuid(org.apache.ignite.lang.IgniteUuid) UUID(java.util.UUID) LongAdder8(org.jsr166.LongAdder8)

Example 23 with Message

use of org.apache.ignite.plugin.extensions.communication.Message in project ignite by apache.

the class GridAbstractCommunicationSelfTest method startSpis.

/**
     * @throws Exception If failed.
     */
private void startSpis() throws Exception {
    spis.clear();
    nodes.clear();
    spiRsrcs.clear();
    Map<ClusterNode, GridSpiTestContext> ctxs = new HashMap<>();
    for (int i = 0; i < getSpiCount(); i++) {
        CommunicationSpi<Message> spi = getSpi(i);
        GridTestUtils.setFieldValue(spi, IgniteSpiAdapter.class, "igniteInstanceName", "grid-" + i);
        IgniteTestResources rsrcs = new IgniteTestResources();
        GridTestNode node = new GridTestNode(rsrcs.getNodeId());
        node.order(i);
        GridSpiTestContext ctx = initSpiContext();
        ctx.setLocalNode(node);
        info(">>> Initialized context: nodeId=" + ctx.localNode().id());
        spiRsrcs.add(rsrcs);
        rsrcs.inject(spi);
        if (useSsl) {
            IgniteMock ignite = GridTestUtils.getFieldValue(spi, IgniteSpiAdapter.class, "ignite");
            IgniteConfiguration cfg = ignite.configuration().setSslContextFactory(GridTestUtils.sslFactory());
            ignite.setStaticCfg(cfg);
        }
        spi.setListener(new MessageListener(rsrcs.getNodeId()));
        node.setAttributes(spi.getNodeAttributes());
        node.setAttribute(ATTR_MACS, F.concat(U.allLocalMACs(), ", "));
        nodes.add(node);
        spi.spiStart(getTestIgniteInstanceName() + (i + 1));
        spis.put(rsrcs.getNodeId(), spi);
        spi.onContextInitialized(ctx);
        ctxs.put(node, ctx);
    }
    // For each context set remote nodes.
    for (Entry<ClusterNode, GridSpiTestContext> e : ctxs.entrySet()) {
        for (ClusterNode n : nodes) {
            if (!n.equals(e.getKey()))
                e.getValue().remoteNodes().add(n);
        }
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) GridSpiTestContext(org.apache.ignite.testframework.GridSpiTestContext) Message(org.apache.ignite.plugin.extensions.communication.Message) HashMap(java.util.HashMap) GridTestNode(org.apache.ignite.testframework.GridTestNode) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) IgniteTestResources(org.apache.ignite.testframework.junits.IgniteTestResources) IgniteMock(org.apache.ignite.testframework.junits.IgniteMock)

Example 24 with Message

use of org.apache.ignite.plugin.extensions.communication.Message in project ignite by apache.

the class GridAbstractCommunicationSelfTest method testSendToManyNodes.

/**
     * @throws Exception If failed.
     */
@SuppressWarnings("WaitWithoutCorrespondingNotify")
public void testSendToManyNodes() throws Exception {
    msgDestMap.clear();
    // Send message from each SPI to all SPI's, including itself.
    for (Entry<UUID, CommunicationSpi<Message>> entry : spis.entrySet()) {
        UUID sndId = entry.getKey();
        CommunicationSpi<Message> commSpi = entry.getValue();
        for (ClusterNode node : nodes) {
            synchronized (mux) {
                if (!msgDestMap.containsKey(sndId))
                    msgDestMap.put(sndId, new HashSet<UUID>());
                msgDestMap.get(sndId).add(node.id());
            }
            commSpi.sendMessage(node, new GridTestMessage(sndId, msgId++, 0));
        }
    }
    long now = System.currentTimeMillis();
    long endTime = now + getMaxTransmitMessagesTime();
    synchronized (mux) {
        while (now < endTime && !msgDestMap.isEmpty()) {
            mux.wait(endTime - now);
            now = System.currentTimeMillis();
        }
        if (!msgDestMap.isEmpty()) {
            for (Entry<UUID, Set<UUID>> entry : msgDestMap.entrySet()) {
                error("Failed to receive all messages [sender=" + entry.getKey() + ", dest=" + entry.getValue() + ']');
            }
        }
        assert msgDestMap.isEmpty() : "Some messages were not received.";
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) HashSet(java.util.HashSet) Set(java.util.Set) Message(org.apache.ignite.plugin.extensions.communication.Message) UUID(java.util.UUID) HashSet(java.util.HashSet)

Example 25 with Message

use of org.apache.ignite.plugin.extensions.communication.Message in project ignite by apache.

the class GridAbstractCommunicationSelfTest method afterTestsStopped.

/** {@inheritDoc} */
@Override
protected void afterTestsStopped() throws Exception {
    for (CommunicationSpi<Message> spi : spis.values()) {
        spi.onContextDestroyed();
        spi.setListener(null);
        spi.spiStop();
    }
    for (IgniteTestResources rsrcs : spiRsrcs) rsrcs.stopThreads();
}
Also used : Message(org.apache.ignite.plugin.extensions.communication.Message) IgniteTestResources(org.apache.ignite.testframework.junits.IgniteTestResources)

Aggregations

Message (org.apache.ignite.plugin.extensions.communication.Message)48 ClusterNode (org.apache.ignite.cluster.ClusterNode)25 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)12 Ignite (org.apache.ignite.Ignite)10 UUID (java.util.UUID)9 IgniteException (org.apache.ignite.IgniteException)9 GridTestMessage (org.apache.ignite.spi.communication.GridTestMessage)9 IgniteTestResources (org.apache.ignite.testframework.junits.IgniteTestResources)8 HashMap (java.util.HashMap)7 TestRecordingCommunicationSpi (org.apache.ignite.internal.TestRecordingCommunicationSpi)7 GridIoMessage (org.apache.ignite.internal.managers.communication.GridIoMessage)7 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)6 Collection (java.util.Collection)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)5 GridDhtPartitionSupplyMessage (org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionSupplyMessage)5 ArrayList (java.util.ArrayList)4 CountDownLatch (java.util.concurrent.CountDownLatch)4 GridMessageListener (org.apache.ignite.internal.managers.communication.GridMessageListener)4 GridDhtPartitionsSingleMessage (org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsSingleMessage)4