use of java.util.concurrent.atomic.LongAdder in project ignite by apache.
the class GridIoManager method runIoTest.
/**
* @param warmup Warmup duration in milliseconds.
* @param duration Test duration in milliseconds.
* @param threads Thread count.
* @param latencyLimit Max latency in nanoseconds.
* @param rangesCnt Ranges count in resulting histogram.
* @param payLoadSize Payload size in bytes.
* @param procFromNioThread {@code True} to process requests in NIO threads.
* @param nodes Nodes participating in test.
*/
public void runIoTest(final long warmup, final long duration, final int threads, final long latencyLimit, final int rangesCnt, final int payLoadSize, final boolean procFromNioThread, final List<ClusterNode> nodes) {
ExecutorService svc = Executors.newFixedThreadPool(threads + 1);
final AtomicBoolean warmupFinished = new AtomicBoolean();
final AtomicBoolean done = new AtomicBoolean();
final CyclicBarrier bar = new CyclicBarrier(threads + 1);
final LongAdder cnt = new LongAdder();
final long sleepDuration = 5000;
final byte[] payLoad = new byte[payLoadSize];
final Map<UUID, IoTestThreadLocalNodeResults>[] res = new Map[threads];
boolean failed = true;
try {
svc.execute(new Runnable() {
@Override
public void run() {
boolean failed = true;
try {
bar.await();
long start = System.currentTimeMillis();
if (log.isInfoEnabled())
log.info("IO test started " + "[warmup=" + warmup + ", duration=" + duration + ", threads=" + threads + ", latencyLimit=" + latencyLimit + ", rangesCnt=" + rangesCnt + ", payLoadSize=" + payLoadSize + ", procFromNioThreads=" + procFromNioThread + ']');
for (; ; ) {
if (!warmupFinished.get() && System.currentTimeMillis() - start > warmup) {
if (log.isInfoEnabled())
log.info("IO test warmup finished.");
warmupFinished.set(true);
start = System.currentTimeMillis();
}
if (warmupFinished.get() && System.currentTimeMillis() - start > duration) {
if (log.isInfoEnabled())
log.info("IO test finished, will wait for all threads to finish.");
done.set(true);
bar.await();
failed = false;
break;
}
if (log.isInfoEnabled())
log.info("IO test [opsCnt/sec=" + (cnt.sumThenReset() * 1000 / sleepDuration) + ", warmup=" + !warmupFinished.get() + ", elapsed=" + (System.currentTimeMillis() - start) + ']');
Thread.sleep(sleepDuration);
}
// At this point all threads have finished the test and
// stored data to the resulting array of maps.
// Need to iterate it over and sum values for all threads.
printIoTestResults(res);
} catch (InterruptedException | BrokenBarrierException e) {
U.error(log, "IO test failed.", e);
} finally {
if (failed)
bar.reset();
}
}
});
for (int i = 0; i < threads; i++) {
final int i0 = i;
res[i] = U.newHashMap(nodes.size());
svc.execute(new Runnable() {
@Override
public void run() {
boolean failed = true;
ThreadLocalRandom rnd = ThreadLocalRandom.current();
int size = nodes.size();
Map<UUID, IoTestThreadLocalNodeResults> res0 = res[i0];
try {
boolean warmupFinished0 = false;
bar.await();
for (; ; ) {
if (done.get())
break;
if (!warmupFinished0)
warmupFinished0 = warmupFinished.get();
ClusterNode node = nodes.get(rnd.nextInt(size));
List<IgniteIoTestMessage> msgs = sendIoTest(node, payLoad, procFromNioThread).get();
cnt.increment();
for (IgniteIoTestMessage msg : msgs) {
UUID nodeId = msg.senderNodeId();
assert nodeId != null;
IoTestThreadLocalNodeResults nodeRes = res0.get(nodeId);
if (nodeRes == null)
res0.put(nodeId, nodeRes = new IoTestThreadLocalNodeResults(rangesCnt, latencyLimit));
nodeRes.onResult(msg);
}
}
bar.await();
failed = false;
} catch (Exception e) {
U.error(log, "IO test worker thread failed.", e);
} finally {
if (failed)
bar.reset();
}
}
});
}
failed = false;
} finally {
if (failed)
U.shutdownNow(GridIoManager.class, svc, log);
}
}
use of java.util.concurrent.atomic.LongAdder in project ignite by apache.
the class GridCircularBufferPerformanceTest method testAdderThroughput.
/**
* @throws Exception If failed.
*/
public void testAdderThroughput() 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()) cnt.increment();
return null;
}
}, 8);
info("Buffer: " + buf);
}
use of java.util.concurrent.atomic.LongAdder in project ignite by apache.
the class GridCircularBufferPerformanceTest method testThroughput.
/**
* @throws Exception If failed.
*/
public void testThroughput() throws Exception {
int size = 256 * 1024;
final GridCircularBuffer<Integer> buf = new GridCircularBuffer<>(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);
cnt.increment();
}
return null;
}
}, 8);
info("Buffer: " + buf);
}
use of java.util.concurrent.atomic.LongAdder in project ignite by apache.
the class GridTestCacheStore method loadCache.
/**
* Preload data from store. In this case we just auto-generate random values.
*
* @param clo Callback for every key.
* @param args Optional arguments.
*/
@Override
public void loadCache(final IgniteBiInClosure<GridTestKey, Long> clo, Object... args) {
// Number of threads is passed in as argument by caller.
final int numThreads = (Integer) args[0];
int entryCnt = (Integer) args[1];
log.info("Number of load threads: " + numThreads);
log.info("Number of cache entries to load: " + entryCnt);
ExecutorService execSvc = Executors.newFixedThreadPool(numThreads);
try {
ExecutorCompletionService<Object> completeSvc = new ExecutorCompletionService<>(execSvc);
final IgniteCache<GridTestKey, Long> cache = ignite.cache("partitioned");
assert cache != null;
final LongAdder adder = new LongAdder();
for (int i = 0; i < numThreads; i++) {
final int threadId = i;
final int perThreadKeys = entryCnt / numThreads;
final int mod = entryCnt % numThreads;
completeSvc.submit(new Callable<Object>() {
@Override
public Object call() throws Exception {
int start = threadId * perThreadKeys;
int end = start + perThreadKeys;
if (threadId + 1 == numThreads)
end += mod;
for (long i = start; i < end; i++) {
if (ignite.affinity(cache.getName()).mapKeyToNode(GridTestKey.affinityKey(i)).isLocal()) {
// Only add if key is local.
clo.apply(new GridTestKey(i), i);
adder.increment();
}
if (i % 10000 == 0)
log.info("Loaded " + adder.intValue() + " keys.");
}
return null;
}
});
}
// Wait for threads to complete.
for (int i = 0; i < numThreads; i++) {
try {
completeSvc.take().get();
} catch (InterruptedException | ExecutionException e) {
throw new CacheLoaderException(e);
}
}
// Final print out.
log.info("Loaded " + adder.intValue() + " keys.");
} finally {
execSvc.shutdown();
}
}
use of java.util.concurrent.atomic.LongAdder 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();
}
Aggregations