use of org.jsr166.LongAdder8 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 LongAdder8 cnt = new LongAdder8();
final ConcurrentLinkedDeque8<GridFutureAdapter<Object>> futs = new ConcurrentLinkedDeque8<>();
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;
pool.shutdownNow();
pool.awaitTermination(Long.MAX_VALUE, TimeUnit.MILLISECONDS);
}
use of org.jsr166.LongAdder8 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 LongAdder8 cnt = new LongAdder8();
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 org.jsr166.LongAdder8 in project ignite by apache.
the class GridCircularBufferPerformanceTest method testDequeueThroughput.
/**
* @throws Exception If failed.
*/
public void testDequeueThroughput() throws Exception {
final ConcurrentLinkedDeque8<Integer> buf = new ConcurrentLinkedDeque8<>();
final LongAdder8 cnt = new LongAdder8();
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 org.jsr166.LongAdder8 in project ignite by apache.
the class IntMaxValueEntriesTest method test.
/** {@inheritDoc} */
@Override
public boolean test(Map<Object, Object> ctx) throws Exception {
final IgniteCache<Integer, Object> cache = cache();
final IgniteDataStreamer<Integer, Object> stmr = ignite().dataStreamer(cache.getName());
final List<Thread> threads = new ArrayList<>(THREADS);
final LongAdder8 addedCnt = new LongAdder8();
int delta = (int) ((KEYS_HI + Math.abs(KEYS_LO)) / THREADS);
System.out.println("Delta: " + delta);
for (int i = 0; i < THREADS; i++) {
final int lo = i == 0 ? KEYS_LO : delta * i + 1;
final int hi = i == THREADS - 1 ? (int) KEYS_HI : (int) ((long) delta * (i + 1));
Thread t = new Thread(new Runnable() {
@Override
public void run() {
ThreadLocalRandom rnd = ThreadLocalRandom.current();
byte val = (byte) rnd.nextInt();
println("Start from " + lo + " to " + hi);
for (int j = lo, k = 0; j < hi; j++, k++) {
stmr.addData(j, val++);
addedCnt.increment();
if (k % REPORT_DELTA == 0)
println(addedCnt.sum() + " entries");
}
println("Thread finished. " + addedCnt.sum() + " entries.");
}
});
threads.add(t);
t.start();
}
for (Thread thread : threads) thread.join();
println("All threads finished. " + addedCnt.sum() + " entries.");
println("Streamer flush");
stmr.flush();
println("Streamer flushed");
println("Calculating cache size");
println("Cache size: " + cache.size());
println("Calculating long cache size");
println("Cache size long: " + cache.sizeLong());
Thread.sleep(10000);
println("Iterating started");
long cnt = 0;
for (Cache.Entry<Integer, Object> ignored : cache) {
cnt++;
if (cnt > 0 && cnt % REPORT_DELTA == 0)
println("Iterated via " + cnt + " entries");
}
println("Iterated via " + cnt + " entries");
cache.destroy();
return true;
}
use of org.jsr166.LongAdder8 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 LongAdder8 cnt = new LongAdder8();
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);
}
}
Aggregations