Search in sources :

Example 1 with GridIoManager

use of org.apache.ignite.internal.managers.communication.GridIoManager in project ignite by apache.

the class GridJobProcessor method start.

/** {@inheritDoc} */
@Override
public void start(boolean activeOnStart) throws IgniteCheckedException {
    if (metricsUpdateFreq < -1)
        throw new IgniteCheckedException("Invalid value for 'metricsUpdateFrequency' configuration property " + "(should be greater than or equals to -1): " + metricsUpdateFreq);
    if (metricsUpdateFreq == -1)
        U.warn(log, "Job metrics are disabled (use with caution).");
    if (!jobAlwaysActivate)
        ctx.collision().setCollisionExternalListener(new CollisionExternalListener());
    GridIoManager ioMgr = ctx.io();
    ioMgr.addMessageListener(TOPIC_JOB_CANCEL, cancelLsnr);
    ioMgr.addMessageListener(TOPIC_JOB, jobExecLsnr);
    ctx.event().addLocalEventListener(discoLsnr, EVT_NODE_FAILED, EVT_NODE_LEFT, EVT_NODE_METRICS_UPDATED);
    if (log.isDebugEnabled())
        log.debug("Job processor started.");
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridIoManager(org.apache.ignite.internal.managers.communication.GridIoManager)

Example 2 with GridIoManager

use of org.apache.ignite.internal.managers.communication.GridIoManager in project ignite by apache.

the class GridJobProcessor method start.

/**
 * {@inheritDoc}
 */
@Override
public void start() throws IgniteCheckedException {
    if (metricsUpdateFreq < -1)
        throw new IgniteCheckedException("Invalid value for 'metricsUpdateFrequency' configuration property " + "(should be greater than or equals to -1): " + metricsUpdateFreq);
    if (metricsUpdateFreq == -1)
        U.warn(log, "Job metrics are disabled (use with caution).");
    if (!jobAlwaysActivate)
        ctx.collision().setCollisionExternalListener(new CollisionExternalListener());
    GridIoManager ioMgr = ctx.io();
    ioMgr.addMessageListener(TOPIC_JOB_CANCEL, cancelLsnr);
    ioMgr.addMessageListener(TOPIC_JOB, jobExecLsnr);
    ctx.event().addLocalEventListener(discoLsnr, EVT_NODE_FAILED, EVT_NODE_LEFT, EVT_NODE_METRICS_UPDATED);
    if (log.isDebugEnabled())
        log.debug("Job processor started.");
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridIoManager(org.apache.ignite.internal.managers.communication.GridIoManager)

Example 3 with GridIoManager

use of org.apache.ignite.internal.managers.communication.GridIoManager in project ignite by apache.

the class GridJobProcessor method onKernalStop.

/**
 * {@inheritDoc}
 */
@Override
public void onKernalStop(boolean cancel) {
    // Stop receiving new requests and sending responses.
    GridIoManager commMgr = ctx.io();
    commMgr.removeMessageListener(TOPIC_JOB, jobExecLsnr);
    commMgr.removeMessageListener(TOPIC_JOB_CANCEL, cancelLsnr);
    if (!jobAlwaysActivate)
        // Ignore external collision events.
        ctx.collision().unsetCollisionExternalListener();
    rwLock.writeLock();
    try {
        stopping = true;
        cancelOnStop = cancel;
    } finally {
        rwLock.writeUnlock();
    }
    // Rejected jobs.
    if (!jobAlwaysActivate) {
        for (GridJobWorker job : passiveJobs.values()) if (removeFromPassive(job))
            rejectJob(job, false);
    }
    // Cancel only if we force grid to stop
    if (cancel) {
        for (GridJobWorker job : activeJobs.values()) {
            job.onStopping();
            cancelJob(job, false);
        }
    }
    U.join(activeJobs.values(), log);
    U.join(cancelledJobs.values(), log);
    // Ignore topology changes.
    ctx.event().removeLocalEventListener(discoLsnr);
    if (log.isDebugEnabled())
        log.debug("Finished executing job processor onKernalStop() callback.");
}
Also used : GridIoManager(org.apache.ignite.internal.managers.communication.GridIoManager)

Example 4 with GridIoManager

use of org.apache.ignite.internal.managers.communication.GridIoManager in project ignite by apache.

the class IgniteSlowClientDetectionSelfTest method testSlowClient.

/**
 * @throws Exception If failed.
 */
@Test
public void testSlowClient() throws Exception {
    final IgniteEx slowClient = grid(nodeCount() - 1);
    final ClusterNode slowClientNode = slowClient.localNode();
    final CountDownLatch evtSegmentedLatch = new CountDownLatch(1);
    slowClient.events().localListen(new IgnitePredicate<Event>() {

        @Override
        public boolean apply(Event evt) {
            assertEquals("Unexpected event: " + evt, evt.type(), EventType.EVT_NODE_SEGMENTED);
            DiscoveryEvent evt0 = (DiscoveryEvent) evt;
            assertEquals(slowClientNode, evt0.eventNode());
            assertEquals(5L, evt0.topologyVersion());
            evtSegmentedLatch.countDown();
            return false;
        }
    }, EventType.EVT_NODE_SEGMENTED);
    final CountDownLatch evtFailedLatch = new CountDownLatch(nodeCount() - 1);
    for (int i = 0; i < nodeCount() - 1; i++) {
        grid(i).events().localListen(new IgnitePredicate<Event>() {

            @Override
            public boolean apply(Event evt) {
                assertEquals("Unexpected event: " + evt, evt.type(), EventType.EVT_NODE_FAILED);
                DiscoveryEvent evt0 = (DiscoveryEvent) evt;
                assertEquals(slowClientNode, evt0.eventNode());
                assertEquals(6L, evt0.topologyVersion());
                assertEquals(4, evt0.topologyNodes().size());
                evtFailedLatch.countDown();
                return false;
            }
        }, EventType.EVT_NODE_FAILED);
    }
    assertTrue(slowClient.cluster().localNode().isClient());
    IgniteCache<Object, Object> cache = slowClient.getOrCreateCache(PARTITIONED);
    IgniteEx client0 = grid(nodeCount() - 2);
    assertTrue(client0.cluster().localNode().isClient());
    IgniteCache<Object, Object> cache0 = client0.getOrCreateCache(PARTITIONED);
    cache.query(new ContinuousQuery<>().setLocalListener(new Listener()));
    for (int i = 0; i < 100; i++) cache0.put(0, i);
    GridIoManager ioMgr = slowClient.context().io();
    TcpCommunicationSpi commSpi = (TcpCommunicationSpi) ((Object[]) U.field(ioMgr, "spis"))[0];
    GridNioServer nioSrvr = ((GridNioServerWrapper) GridTestUtils.getFieldValue(commSpi, "nioSrvWrapper")).nio();
    GridTestUtils.setFieldValue(nioSrvr, "skipRead", true);
    // Initiate messages for client.
    for (int i = 0; i < 100; i++) cache0.put(0, new byte[10 * 1024]);
    boolean wait = GridTestUtils.waitForCondition(new GridAbsPredicate() {

        @Override
        public boolean apply() {
            return Ignition.state(slowClient.name()) == IgniteState.STOPPED_ON_SEGMENTATION;
        }
    }, getTestTimeout());
    assertTrue(wait);
    assertTrue("Failed to wait for client failed event", evtFailedLatch.await(5000, MILLISECONDS));
    assertTrue("Failed to wait for client segmented event", evtSegmentedLatch.await(5000, MILLISECONDS));
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) CacheEntryUpdatedListener(javax.cache.event.CacheEntryUpdatedListener) GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) GridNioServerWrapper(org.apache.ignite.spi.communication.tcp.internal.GridNioServerWrapper) CountDownLatch(java.util.concurrent.CountDownLatch) TcpCommunicationSpi(org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi) GridNioServer(org.apache.ignite.internal.util.nio.GridNioServer) ContinuousQuery(org.apache.ignite.cache.query.ContinuousQuery) GridIoManager(org.apache.ignite.internal.managers.communication.GridIoManager) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) Event(org.apache.ignite.events.Event) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 5 with GridIoManager

use of org.apache.ignite.internal.managers.communication.GridIoManager in project ignite by apache.

the class GridIoManagerBenchmark0 method testLatency.

/**
 * @throws Exception If failed.
 */
@Test
public void testLatency() 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();
    final LongAdder msgCntr = new LongAdder();
    final Integer topic = 1;
    final Map<IgniteUuid, CountDownLatch> map = new ConcurrentHashMap<>();
    rcv.addMessageListener(topic, new GridMessageListener() {

        @Override
        public void onMessage(UUID nodeId, Object msg, byte plc) {
            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, byte plc) {
            map.get(((GridTestMessage) msg).id()).countDown();
        }
    });
    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()) {
                    CountDownLatch latch = new CountDownLatch(1);
                    map.put(msgId, latch);
                    snd.sendToCustomTopic(rcvNode, topic, new GridTestMessage(msgId, (String) null), PUBLIC_POOL);
                    latch.await();
                    msgCntr.increment();
                }
            } catch (IgniteCheckedException e) {
                X.println("Message send failed", e);
            } catch (InterruptedException ignored) {
            // No-op.
            }
            return null;
        }
    }, 1, "send-thread");
    Thread.sleep(TEST_TIMEOUT);
    finish.set(true);
    t.cancel();
    f.get();
}
Also used : Message(org.apache.ignite.plugin.extensions.communication.Message) GridMessageListener(org.apache.ignite.internal.managers.communication.GridMessageListener) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) TimerTask(java.util.TimerTask) IgniteUuid(org.apache.ignite.lang.IgniteUuid) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) UUID(java.util.UUID) ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteKernal(org.apache.ignite.internal.IgniteKernal) CountDownLatch(java.util.concurrent.CountDownLatch) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) LongAdder(java.util.concurrent.atomic.LongAdder) Timer(java.util.Timer) GridIoManager(org.apache.ignite.internal.managers.communication.GridIoManager) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Aggregations

GridIoManager (org.apache.ignite.internal.managers.communication.GridIoManager)22 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)12 ClusterNode (org.apache.ignite.cluster.ClusterNode)9 UUID (java.util.UUID)8 GridMessageListener (org.apache.ignite.internal.managers.communication.GridMessageListener)7 GridDiscoveryManager (org.apache.ignite.internal.managers.discovery.GridDiscoveryManager)7 DiscoveryEvent (org.apache.ignite.events.DiscoveryEvent)6 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)5 Event (org.apache.ignite.events.Event)5 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)5 Test (org.junit.Test)5 CountDownLatch (java.util.concurrent.CountDownLatch)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 LongAdder (java.util.concurrent.atomic.LongAdder)3 IgniteKernal (org.apache.ignite.internal.IgniteKernal)3 GridEventStorageManager (org.apache.ignite.internal.managers.eventstorage.GridEventStorageManager)3 RuntimeMXBean (java.lang.management.RuntimeMXBean)2 DecimalFormat (java.text.DecimalFormat)2 Collection (java.util.Collection)2 HashMap (java.util.HashMap)2