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 LongAdder msgCntr = new LongAdder();
final String topic = "test-topic";
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) {
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 LongAdder msgCntr = new LongAdder();
final String topic = "test-topic";
final Map<IgniteUuid, CountDownLatch> latches = 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) {
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 IgniteCachePartitionedQuerySelfTest method testScanQueryPagination.
/**
* @throws Exception If failed.
*/
public void testScanQueryPagination() throws Exception {
final int pageSize = 5;
final AtomicInteger pages = new AtomicInteger(0);
IgniteCache<Integer, Integer> cache = jcache(Integer.class, Integer.class);
for (int i = 0; i < 50; i++) cache.put(i, i);
CommunicationSpi spi = ignite().configuration().getCommunicationSpi();
assert spi instanceof TestTcpCommunicationSpi;
TestTcpCommunicationSpi commSpi = (TestTcpCommunicationSpi) spi;
commSpi.filter = new IgniteInClosure<Message>() {
@Override
public void apply(Message msg) {
if (!(msg instanceof GridIoMessage))
return;
Message msg0 = ((GridIoMessage) msg).message();
if (msg0 instanceof GridCacheQueryRequest) {
assertEquals(pageSize, ((GridCacheQueryRequest) msg0).pageSize());
pages.incrementAndGet();
} else if (msg0 instanceof GridCacheQueryResponse)
assertTrue(((GridCacheQueryResponse) msg0).data().size() <= pageSize);
}
};
try {
ScanQuery<Integer, Integer> qry = new ScanQuery<Integer, Integer>();
qry.setPageSize(pageSize);
List<Cache.Entry<Integer, Integer>> all = cache.query(qry).getAll();
assertTrue(pages.get() > ignite().cluster().forDataNodes(DEFAULT_CACHE_NAME).nodes().size());
assertEquals(50, all.size());
} finally {
commSpi.filter = null;
}
}
use of org.apache.ignite.plugin.extensions.communication.Message in project ignite by apache.
the class DirectByteBufferStreamImplV1 method readMessage.
/**
* {@inheritDoc}
*/
@SuppressWarnings("unchecked")
@Override
public <T extends Message> T readMessage(MessageReader reader) {
if (!msgTypeDone) {
if (buf.remaining() < Message.DIRECT_TYPE_SIZE) {
lastFinished = false;
return null;
}
short type = readShort();
msg = type == Short.MIN_VALUE ? null : msgFactory.create(type);
msgTypeDone = true;
}
if (msg != null) {
try {
reader.beforeInnerMessageRead();
reader.setCurrentReadClass(msg.getClass());
lastFinished = msg.readFrom(buf, reader);
} finally {
reader.afterInnerMessageRead(lastFinished);
}
} else
lastFinished = true;
if (lastFinished) {
Message msg0 = msg;
msgTypeDone = false;
msg = null;
return (T) msg0;
} else
return null;
}
use of org.apache.ignite.plugin.extensions.communication.Message in project ignite by apache.
the class DirectByteBufferStreamImplV2 method readMessage.
/**
* {@inheritDoc}
*/
@SuppressWarnings("unchecked")
@Override
public <T extends Message> T readMessage(MessageReader reader) {
if (!msgTypeDone) {
if (buf.remaining() < Message.DIRECT_TYPE_SIZE) {
lastFinished = false;
return null;
}
short type = readShort();
msg = type == Short.MIN_VALUE ? null : msgFactory.create(type);
msgTypeDone = true;
}
if (msg != null) {
try {
reader.beforeInnerMessageRead();
reader.setCurrentReadClass(msg.getClass());
lastFinished = msg.readFrom(buf, reader);
} finally {
reader.afterInnerMessageRead(lastFinished);
}
} else
lastFinished = true;
if (lastFinished) {
Message msg0 = msg;
msgTypeDone = false;
msg = null;
return (T) msg0;
} else
return null;
}
Aggregations