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.");
}
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.");
}
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.");
}
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));
}
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();
}
Aggregations