use of org.jsr166.LongAdder8 in project ignite by apache.
the class GridCacheBinaryObjectsAbstractMultiThreadedSelfTest method testGetPut.
/**
* @throws Exception If failed.
*/
@SuppressWarnings("BusyWait")
public void testGetPut() throws Exception {
final AtomicBoolean flag = new AtomicBoolean();
final LongAdder8 cnt = new LongAdder8();
IgniteInternalFuture<?> f = multithreadedAsync(new Callable<Object>() {
@Override
public Object call() throws Exception {
int threadId = idxGen.getAndIncrement() % 2;
ThreadLocalRandom rnd = ThreadLocalRandom.current();
while (!flag.get()) {
IgniteCache<Object, Object> c = jcache(rnd.nextInt(gridCount()));
switch(threadId) {
case 0:
// Put/get/remove binary -> binary.
c.put(new TestObject(rnd.nextInt(10000)), new TestObject(rnd.nextInt(10000)));
IgniteCache<Object, Object> p2 = ((IgniteCacheProxy<Object, Object>) c).keepBinary();
BinaryObject v = (BinaryObject) p2.get(new TestObject(rnd.nextInt(10000)));
if (v != null)
v.deserialize();
c.remove(new TestObject(rnd.nextInt(10000)));
break;
case 1:
// Put/get int -> binary.
c.put(rnd.nextInt(10000), new TestObject(rnd.nextInt(10000)));
IgniteCache<Integer, BinaryObject> p4 = ((IgniteCacheProxy<Object, Object>) c).keepBinary();
BinaryObject v1 = p4.get(rnd.nextInt(10000));
if (v1 != null)
v1.deserialize();
p4.remove(rnd.nextInt(10000));
break;
default:
assert false;
}
cnt.add(3);
}
return null;
}
}, THREAD_CNT);
for (int i = 0; i < 30 && !f.isDone(); i++) Thread.sleep(1000);
flag.set(true);
f.get();
info("Operations in 30 sec: " + cnt.sum());
}
use of org.jsr166.LongAdder8 in project ignite by apache.
the class SortedEvictionPolicyPerformanceTest method testThroughput.
/**
* Tests throughput.
*/
public void testThroughput() throws Exception {
final LongAdder8 cnt = new LongAdder8();
final AtomicBoolean finished = new AtomicBoolean();
final int pPut = P_PUT;
final int pGet = P_PUT + P_GET;
final IgniteCache<Integer, Integer> cache = ignite.cache(DEFAULT_CACHE_NAME);
multithreadedAsync(new Callable<Object>() {
@Override
public Object call() throws Exception {
for (; ; ) {
U.sleep(1000);
info("Ops/sec: " + cnt.sumThenReset());
}
}
}, 1);
multithreaded(new Callable<Object>() {
@Override
public Object call() throws Exception {
while (!finished.get()) {
int p = RND.nextInt(100);
int key = RND.nextInt(KEYS);
if (p >= 0 && p < pPut)
cache.put(key, 0);
else if (p >= pPut && p < pGet)
cache.get(key);
else
cache.remove(key);
cnt.increment();
}
return null;
}
}, THREADS);
}
use of org.jsr166.LongAdder8 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 LongAdder8 execCnt = new LongAdder8();
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 org.jsr166.LongAdder8 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 LongAdder8 execCnt = new LongAdder8();
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 org.jsr166.LongAdder8 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 LongAdder8 msgCntr = new LongAdder8();
final Integer topic = 1;
final Map<IgniteUuid, CountDownLatch> map = new ConcurrentHashMap8<>();
rcv.addMessageListener(topic, new GridMessageListener() {
@Override
public void onMessage(UUID nodeId, Object msg) {
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) {
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