use of java.util.concurrent.atomic.LongAdder 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 LongAdder sum = new LongAdder();
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 java.util.concurrent.atomic.LongAdder 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 LongAdder sum = new LongAdder();
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 java.util.concurrent.atomic.LongAdder in project ignite by apache.
the class GridBoundedConcurrentLinkedHashSetLoadTest method main.
/**
* @param args Arguments.
*/
public static void main(String[] args) throws Exception {
QueuePolicy qPlc = args.length > 0 ? QueuePolicy.valueOf(args[0]) : SINGLE_Q;
int threadCnt = args.length > 1 ? Integer.valueOf(args[1]) : Runtime.getRuntime().availableProcessors();
X.println("Queue policy: " + qPlc);
X.println("Threads: " + threadCnt);
ExecutorService pool = Executors.newFixedThreadPool(threadCnt);
final Collection<IgniteUuid> set = new GridBoundedConcurrentLinkedHashSet<>(10240, 32, 0.75f, 128, qPlc);
X.println("Set: " + set);
final LongAdder execCnt = new LongAdder();
final AtomicBoolean finish = new AtomicBoolean();
// Thread that measures and outputs performance statistics.
Thread collector = new Thread(new Runnable() {
@SuppressWarnings({ "BusyWait", "InfiniteLoopStatement" })
@Override
public void run() {
GridCumulativeAverage avgTasksPerSec = new GridCumulativeAverage();
try {
while (!finish.get()) {
Thread.sleep(UPDATE_INTERVAL_SEC * 1000);
long curTasksPerSec = execCnt.sumThenReset() / UPDATE_INTERVAL_SEC;
X.println(">>> Tasks/s: " + curTasksPerSec);
avgTasksPerSec.update(curTasksPerSec);
}
} catch (InterruptedException ignored) {
X.println(">>> Interrupted.");
Thread.currentThread().interrupt();
}
}
});
collector.start();
Collection<Callable<Object>> producers = new ArrayList<>(threadCnt);
for (int i = 0; i < threadCnt; i++) producers.add(new Callable<Object>() {
@SuppressWarnings({ "unchecked", "InfiniteLoopStatement" })
@Override
public Object call() throws Exception {
UUID id = UUID.randomUUID();
try {
while (!finish.get()) {
set.add(IgniteUuid.fromUuid(id));
execCnt.increment();
}
return null;
} catch (Throwable t) {
t.printStackTrace();
throw new Exception(t);
} finally {
X.println("Thread finished.");
}
}
});
pool.invokeAll(producers);
}
use of java.util.concurrent.atomic.LongAdder in project ignite by apache.
the class GridJobExecutionSingleNodeSemaphoreLoadTest method main.
/**
* @param args Command line arguments:
* 1-st: Number of worker threads. Default equals to available CPU number / 2.
* 2-nd: Concurrent tasks count. Default: 1024.
* 3-rd: Test duration in seconds. 0 means infinite. Default: 0.
* 4-th: File to output test results to.
* @throws Exception If failed.
*/
public static void main(String[] args) throws Exception {
GridFileLock fileLock = GridLoadTestUtils.fileLock();
fileLock.lock();
try {
// Command line arguments.
//
// NOTE: on MacOS better numbers are shown if public pool core and max sizes are
// equal to CPU count. And producer threads count is equal to CPU count.
//
int threadCnt = args.length > 0 ? Integer.parseInt(args[0]) : Runtime.getRuntime().availableProcessors() / 2;
int taskCnt = args.length > 1 ? Integer.parseInt(args[1]) : 1024;
final int duration = args.length > 2 ? Integer.parseInt(args[2]) : 0;
final String outputFileName = args.length > 3 ? args[3] : null;
final LongAdder execCnt = new LongAdder();
try {
final Ignite g = G.start("modules/tests/config/grid-job-load.xml");
X.println("Thread count: " + threadCnt);
X.println("Task count: " + taskCnt);
X.println("Duration: " + duration);
X.println("Warming up...");
g.compute().execute(GridJobExecutionLoadTestTask.class, null);
g.compute().execute(GridJobExecutionLoadTestTask.class, null);
runTest(g, threadCnt, taskCnt, WARM_UP_DURATION, execCnt);
System.gc();
execCnt.reset();
X.println("Running main test.");
IgniteInternalFuture<Void> collectorFut = GridTestUtils.runAsync(new Callable<Void>() {
@Override
public Void call() throws Exception {
GridCumulativeAverage avgTasksPerSec = new GridCumulativeAverage();
try {
while (!Thread.currentThread().isInterrupted()) {
U.sleep(UPDATE_INTERVAL_SEC * 1000);
long curTasksPerSec = execCnt.sumThenReset() / UPDATE_INTERVAL_SEC;
X.println(">>> Tasks/s: " + curTasksPerSec);
avgTasksPerSec.update(curTasksPerSec);
}
} catch (IgniteInterruptedCheckedException ignored) {
X.println(">>> Interrupted.");
Thread.currentThread().interrupt();
}
X.println(">>> Average tasks/s: " + avgTasksPerSec);
if (outputFileName != null) {
X.println("Writing test results to a file: " + outputFileName);
try {
GridLoadTestUtils.appendLineToFile(outputFileName, "%s,%d", GridLoadTestUtils.DATE_TIME_FORMAT.format(new Date()), avgTasksPerSec.get());
} catch (IOException e) {
X.error("Failed to output to a file", e);
}
}
return null;
}
});
runTest(g, threadCnt, taskCnt, duration * 1000, execCnt);
X.println("All done, stopping.");
collectorFut.cancel();
} finally {
G.stopAll(true);
}
} finally {
fileLock.close();
}
}
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;
pool.shutdownNow();
pool.awaitTermination(Long.MAX_VALUE, TimeUnit.MILLISECONDS);
}
Aggregations