use of java.util.concurrent.atomic.LongAdder in project ignite by apache.
the class GridCircularBufferPerformanceTest method testDequeueThroughput.
/**
* @throws Exception If failed.
*/
public void testDequeueThroughput() throws Exception {
final FastSizeDeque<Integer> buf = new FastSizeDeque<>(new ConcurrentLinkedDeque<>());
final LongAdder cnt = new LongAdder();
final AtomicBoolean finished = new AtomicBoolean();
multithreadedAsync(new Callable<Object>() {
@Override
public Object call() throws Exception {
while (!finished.get()) {
U.sleep(5000);
info("Ops/sec: " + cnt.sumThenReset() / 5);
}
return null;
}
}, 1);
final int size = 256 * 1024;
multithreaded(new Callable<Object>() {
@Override
public Object call() throws Exception {
while (!finished.get()) {
buf.add(1);
if (buf.sizex() > size)
buf.poll();
cnt.increment();
}
return null;
}
}, 8);
info("Buffer: " + buf);
}
use of java.util.concurrent.atomic.LongAdder in project ignite by apache.
the class GridCircularBufferPerformanceTest method testArrayBlockingQueueThroughput.
/**
* @throws Exception If failed.
*/
public void testArrayBlockingQueueThroughput() throws Exception {
final int size = 256 * 1024;
final ArrayBlockingQueue<Integer> buf = new ArrayBlockingQueue<>(size);
final LongAdder cnt = new LongAdder();
final AtomicBoolean finished = new AtomicBoolean();
multithreadedAsync(new Callable<Object>() {
@Override
public Object call() throws Exception {
while (!finished.get()) {
U.sleep(5000);
info("Ops/sec: " + cnt.sumThenReset() / 5);
}
return null;
}
}, 1);
multithreaded(new Callable<Object>() {
@Override
public Object call() throws Exception {
while (!finished.get()) {
buf.add(1);
buf.poll();
cnt.increment();
}
return null;
}
}, 8);
info("Buffer: " + buf);
}
use of java.util.concurrent.atomic.LongAdder in project ignite by apache.
the class GridFutureListenPerformanceTest method main.
/**
* @param args Args.
* @throws InterruptedException If failed.
*/
public static void main(String[] args) throws InterruptedException {
final LongAdder cnt = new LongAdder();
final ConcurrentLinkedDeque<GridFutureAdapter<Object>> futs = new ConcurrentLinkedDeque<>();
ExecutorService pool = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
Thread statThread = new Thread() {
@SuppressWarnings("BusyWait")
@Override
public void run() {
while (!done) {
try {
Thread.sleep(5000);
} catch (InterruptedException ignored) {
return;
}
System.out.println(new Date() + " Notifications per sec: " + (cnt.sumThenReset() / 5));
}
}
};
statThread.setDaemon(true);
statThread.start();
for (int i = 0; i < Runtime.getRuntime().availableProcessors(); i++) {
pool.submit(new Callable<Object>() {
@Override
public Object call() throws Exception {
Random rnd = new Random();
while (!done) {
for (int j = 0; j < rnd.nextInt(10); j++) {
GridFutureAdapter<Object> fut = new GridFutureAdapter<>();
futs.add(fut);
for (int k = 1; k < rnd.nextInt(3); k++) {
fut.listen(new IgniteInClosure<IgniteInternalFuture<Object>>() {
@Override
public void apply(IgniteInternalFuture<Object> t) {
try {
t.get();
} catch (IgniteCheckedException e) {
e.printStackTrace();
}
cnt.increment();
}
});
}
}
GridFutureAdapter<Object> fut;
while ((fut = futs.poll()) != null) fut.onDone();
}
return null;
}
});
}
Thread.sleep(5 * 60 * 1000);
done = true;
}
use of java.util.concurrent.atomic.LongAdder in project ignite by apache.
the class BlockingQueueTest method testBlockingQueueMultithreaded.
/**
* @param testName Test name.
* @param q Queue.
* @throws Exception If failed.
*/
private static void testBlockingQueueMultithreaded(String testName, final BlockingQueue<Object> q) throws Exception {
waitGc();
X.println(">>> Starting test for: " + testName);
final LongAdder adder = new LongAdder();
GridTestUtils.runMultiThreaded(new Callable<Object>() {
@Override
public Object call() throws Exception {
adder.add(testBlockingQueue(q));
return null;
}
}, THREAD_CNT, "queue-test-worker");
X.println(">>> Tested queue [testName=" + testName + ", dur=" + adder.sum() + "ms]");
assert q.isEmpty();
}
use of java.util.concurrent.atomic.LongAdder in project ignite by apache.
the class GridIoManagerBenchmark0 method testLatency.
/**
* @throws Exception If failed.
*/
@SuppressWarnings("deprecation")
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