use of org.apache.ignite.internal.managers.communication.GridIoManager 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();
}
use of org.apache.ignite.internal.managers.communication.GridIoManager in project ignite by apache.
the class GridCacheMessageSelfTest method doSend.
/**
* @throws Exception If failed.
*/
private void doSend() throws Exception {
GridIoManager mgr0 = ((IgniteKernal) grid(0)).context().io();
GridIoManager mgr1 = ((IgniteKernal) grid(1)).context().io();
String topic = "test-topic";
final CountDownLatch latch = new CountDownLatch(SAMPLE_CNT);
mgr1.addMessageListener(topic, new GridMessageListener() {
@Override
public void onMessage(UUID nodeId, Object msg) {
try {
latch.countDown();
Collection<TestMessage1> messages = ((TestMessage) msg).entries();
assertEquals(10, messages.size());
int count = 0;
for (TestMessage1 msg1 : messages) {
assertTrue(msg1.body().contains(TEST_BODY));
int i = Integer.parseInt(msg1.body().substring(TEST_BODY.length() + 1));
assertEquals(count, i);
TestMessage2 msg2 = (TestMessage2) msg1.message();
assertEquals(TEST_BODY + "_" + i + "_2", msg2.body());
assertEquals(grid(0).localNode().id(), msg2.nodeId());
assertEquals(i, msg2.id());
GridTestMessage msg3 = (GridTestMessage) msg2.message();
assertEquals(count, msg3.getMsgId());
assertEquals(grid(1).localNode().id(), msg3.getSourceNodeId());
count++;
}
} catch (Exception e) {
fail("Exception " + e.getMessage());
}
}
});
TestMessage msg = new TestMessage();
for (int i = 0; i < 10; i++) {
TestMessage2 mes1 = new TestMessage2();
mes1.init(new GridTestMessage(grid(1).localNode().id(), i, 0), grid(0).localNode().id(), i, TEST_BODY + "_" + i + "_2");
TestMessage1 mes2 = new TestMessage1();
mes2.init(mes1, TEST_BODY + "_" + i);
msg.add(mes2);
}
mgr0.sendToCustomTopic(grid(1).localNode(), topic, msg, GridIoPolicy.PUBLIC_POOL);
assert latch.await(3, SECONDS);
}
use of org.apache.ignite.internal.managers.communication.GridIoManager in project ignite by apache.
the class GridTaskProcessor method sendSessionAttributes.
/**
* This method will make the best attempt to send attributes to all jobs.
*
* @param attrs Deserialized session attributes.
* @param ses Task session.
* @throws IgniteCheckedException If send to any of the jobs failed.
*/
@SuppressWarnings({ "SynchronizationOnLocalVariableOrMethodParameter", "BusyWait" })
private void sendSessionAttributes(Map<?, ?> attrs, GridTaskSessionImpl ses) throws IgniteCheckedException {
assert attrs != null;
assert ses != null;
Collection<ComputeJobSibling> siblings = ses.getJobSiblings();
GridIoManager commMgr = ctx.io();
long timeout = ses.getEndTime() - U.currentTimeMillis();
if (timeout <= 0) {
U.warn(log, "Session attributes won't be set due to task timeout: " + attrs);
return;
}
Set<UUID> rcvrs = new HashSet<>();
UUID locNodeId = ctx.localNodeId();
synchronized (ses) {
if (ses.isClosed()) {
if (log.isDebugEnabled())
log.debug("Setting session attributes on closed session (will ignore): " + ses);
return;
}
ses.setInternal(attrs);
// ID will be associated with a certain session state.
for (ComputeJobSibling s : siblings) {
GridJobSiblingImpl sib = (GridJobSiblingImpl) s;
UUID nodeId = sib.nodeId();
if (!nodeId.equals(locNodeId) && !sib.isJobDone() && !rcvrs.contains(nodeId))
rcvrs.add(nodeId);
}
}
if (ctx.event().isRecordable(EVT_TASK_SESSION_ATTR_SET)) {
Event evt = new TaskEvent(ctx.discovery().localNode(), "Changed attributes: " + attrs, EVT_TASK_SESSION_ATTR_SET, ses.getId(), ses.getTaskName(), ses.getTaskClassName(), false, null);
ctx.event().record(evt);
}
IgniteCheckedException ex = null;
// Every job gets an individual message to keep track of ghost requests.
for (ComputeJobSibling s : ses.getJobSiblings()) {
GridJobSiblingImpl sib = (GridJobSiblingImpl) s;
UUID nodeId = sib.nodeId();
// Pair can be null if job is finished.
if (rcvrs.remove(nodeId)) {
ClusterNode node = ctx.discovery().node(nodeId);
// Check that node didn't change (it could happen in case of failover).
if (node != null) {
boolean loc = node.id().equals(ctx.localNodeId()) && !ctx.config().isMarshalLocalJobs();
GridTaskSessionRequest req = new GridTaskSessionRequest(ses.getId(), null, loc ? null : U.marshal(marsh, attrs), attrs);
// should be preserved here.
try {
commMgr.sendOrderedMessage(node, sib.jobTopic(), req, SYSTEM_POOL, timeout, false);
} catch (IgniteCheckedException e) {
node = ctx.discovery().node(nodeId);
if (node != null) {
try {
// Since communication on remote node may stop before
// we get discovery notification, we give ourselves the
// best effort to detect it.
Thread.sleep(DISCO_TIMEOUT);
} catch (InterruptedException ignore) {
U.warn(log, "Got interrupted while sending session attributes.");
}
node = ctx.discovery().node(nodeId);
}
String err = "Failed to send session attribute request message to node " + "(normal case if node left grid) [node=" + node + ", req=" + req + ']';
if (node != null)
U.warn(log, err);
else if (log.isDebugEnabled())
log.debug(err);
if (ex == null)
ex = e;
}
}
}
}
if (ex != null)
throw ex;
}
use of org.apache.ignite.internal.managers.communication.GridIoManager in project ignite by apache.
the class GridMarshallerMappingProcessor method start.
/** {@inheritDoc} */
@Override
public void start(boolean activeOnStart) throws IgniteCheckedException {
GridDiscoveryManager discoMgr = ctx.discovery();
GridIoManager ioMgr = ctx.io();
MarshallerMappingTransport transport = new MarshallerMappingTransport(ctx, mappingExchangeSyncMap, clientReqSyncMap);
marshallerCtx.onMarshallerProcessorStarted(ctx, transport);
discoMgr.setCustomEventListener(MappingProposedMessage.class, new MarshallerMappingExchangeListener());
discoMgr.setCustomEventListener(MappingAcceptedMessage.class, new MappingAcceptedListener());
if (ctx.clientNode())
ioMgr.addMessageListener(TOPIC_MAPPING_MARSH, new MissingMappingResponseListener());
else
ioMgr.addMessageListener(TOPIC_MAPPING_MARSH, new MissingMappingRequestListener(ioMgr));
if (ctx.clientNode())
ctx.event().addLocalEventListener(new GridLocalEventListener() {
@Override
public void onEvent(Event evt) {
DiscoveryEvent evt0 = (DiscoveryEvent) evt;
if (!ctx.isStopping()) {
for (ClientRequestFuture fut : clientReqSyncMap.values()) fut.onNodeLeft(evt0.eventNode().id());
}
}
}, EVT_NODE_LEFT, EVT_NODE_FAILED);
}
use of org.apache.ignite.internal.managers.communication.GridIoManager in project ignite by apache.
the class ClientReconnectContinuousQueryTest method skipRead.
/**
* @param igniteClient Ignite client.
* @param skip Skip.
*/
private void skipRead(IgniteEx igniteClient, boolean skip) {
GridIoManager ioMgr = igniteClient.context().io();
TcpCommunicationSpi commSpi = (TcpCommunicationSpi) ((Object[]) U.field(ioMgr, "spis"))[0];
GridNioServer nioSrvr = U.field(commSpi, "nioSrvr");
GridTestUtils.setFieldValue(nioSrvr, "skipRead", skip);
}
Aggregations