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