use of org.jsr166.LongAdder8 in project ignite by apache.
the class HadoopExecutorServiceTest method testShutdown.
/**
* @throws Exception If failed.
*/
public void testShutdown() throws Exception {
for (int i = 0; i < 5; i++) {
final HadoopExecutorService exec = new HadoopExecutorService(log, "_GRID_NAME_", 10, 5);
final LongAdder8 sum = new LongAdder8();
final AtomicBoolean finish = new AtomicBoolean();
IgniteInternalFuture<?> fut = multithreadedAsync(new Callable<Object>() {
@Override
public Object call() throws Exception {
while (!finish.get()) {
exec.submit(new Callable<Void>() {
@Override
public Void call() throws Exception {
sum.increment();
return null;
}
});
}
return null;
}
}, 19);
Thread.sleep(200);
assertTrue(exec.shutdown(50));
long res = sum.sum();
assertTrue(res > 0);
finish.set(true);
fut.get();
// Nothing was executed after shutdown.
assertEquals(res, sum.sum());
X.println("_ ok");
}
}
use of org.jsr166.LongAdder8 in project ignite by apache.
the class HadoopExecutorServiceTest method testExecutesAll.
/**
* @throws Exception If failed.
*/
public void testExecutesAll() throws Exception {
final HadoopExecutorService exec = new HadoopExecutorService(log, "_GRID_NAME_", 10, 5);
for (int i = 0; i < 5; i++) {
final int loops = 5000;
int threads = 17;
final LongAdder8 sum = new LongAdder8();
multithreaded(new Callable<Object>() {
@Override
public Object call() throws Exception {
for (int i = 0; i < loops; i++) {
exec.submit(new Callable<Void>() {
@Override
public Void call() throws Exception {
sum.increment();
return null;
}
});
}
return null;
}
}, threads);
while (exec.active() != 0) {
X.println("__ active: " + exec.active());
Thread.sleep(200);
}
assertEquals(threads * loops, sum.sum());
X.println("_ ok");
}
assertTrue(exec.shutdown(0));
}
use of org.jsr166.LongAdder8 in project ignite by apache.
the class IgniteDataStreamerPerformanceTest method doTest.
/**
* @throws Exception If failed.
*/
private void doTest() throws Exception {
System.gc();
System.gc();
System.gc();
try {
useCache = true;
startGridsMultiThreaded(GRID_CNT);
useCache = false;
Ignite ignite = startGrid();
final IgniteDataStreamer<Integer, String> ldr = ignite.dataStreamer(DEFAULT_CACHE_NAME);
ldr.perNodeBufferSize(8192);
ldr.receiver(DataStreamerCacheUpdaters.<Integer, String>batchedSorted());
ldr.autoFlushFrequency(0);
final LongAdder8 cnt = new LongAdder8();
long start = U.currentTimeMillis();
Thread t = new Thread(new Runnable() {
@SuppressWarnings("BusyWait")
@Override
public void run() {
while (true) {
try {
Thread.sleep(10000);
} catch (InterruptedException ignored) {
break;
}
info(">>> Adds/sec: " + cnt.sumThenReset() / 10);
}
}
});
t.setDaemon(true);
t.start();
//Runtime.getRuntime().availableProcessors();
int threadNum = 2;
multithreaded(new Callable<Object>() {
@SuppressWarnings("InfiniteLoopStatement")
@Override
public Object call() throws Exception {
ThreadLocalRandom8 rnd = ThreadLocalRandom8.current();
while (true) {
int i = rnd.nextInt(ENTRY_CNT);
ldr.addData(i, vals[rnd.nextInt(vals.length)]);
cnt.increment();
}
}
}, threadNum, "loader");
info("Closing loader...");
ldr.close(false);
long duration = U.currentTimeMillis() - start;
info("Finished performance test. Duration: " + duration + "ms.");
} finally {
stopAllGrids();
}
}
use of org.jsr166.LongAdder8 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 LongAdder8 adder = new LongAdder8();
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 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;
}
Aggregations