use of java.util.concurrent.atomic.LongAdder 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 java.util.concurrent.atomic.LongAdder in project ignite by apache.
the class GridCacheQuerySimpleBenchmark method testPerformance.
/**
* @throws Exception If failed.
*/
public void testPerformance() throws Exception {
Random rnd = new GridRandom();
final IgniteCache<Long, Person> c = ignite.cache("offheap-cache");
X.println("___ PUT start");
final int cnt = 100_000;
final int maxSalary = cnt / 10;
for (long i = 0; i < cnt; i++) c.put(i, new Person(rnd.nextInt(maxSalary), "Vasya " + i));
X.println("___ PUT end");
final AtomicBoolean end = new AtomicBoolean();
final LongAdder puts = new LongAdder();
IgniteInternalFuture<?> fut0 = multithreadedAsync(new Callable<Void>() {
@Override
public Void call() throws Exception {
Random rnd = new GridRandom();
while (!end.get()) {
long i = rnd.nextInt(cnt);
c.put(i, new Person(rnd.nextInt(maxSalary), "Vasya " + i));
puts.increment();
}
return null;
}
}, 10);
final LongAdder qrys = new LongAdder();
IgniteInternalFuture<?> fut1 = multithreadedAsync(new Callable<Void>() {
@Override
public Void call() throws Exception {
Random rnd = new GridRandom();
while (!end.get()) {
int salary = rnd.nextInt(maxSalary);
c.query(new SqlFieldsQuery("select name from Person where salary = ?").setArgs(salary)).getAll();
qrys.increment();
}
return null;
}
}, 10);
int runTimeSec = 600;
for (int s = 0; s < runTimeSec; s++) {
Thread.sleep(1000);
long puts0 = puts.sum();
long qrys0 = qrys.sum();
puts.add(-puts0);
qrys.add(-qrys0);
X.println("___ puts: " + puts0 + " qrys: " + qrys0);
}
end.set(true);
fut0.get();
fut1.get();
X.println("___ STOP");
}
Aggregations