use of org.jsr166.ConcurrentLinkedDeque8 in project ignite by apache.
the class MemoryEventStorageSpi method cleanupQueue.
/**
* Method cleans up all events that either outnumber queue size
* or exceeds time-to-live value. It does none if someone else
* cleans up queue (lock is locked) or if there are queue readers
* (readersNum > 0).
*/
private void cleanupQueue() {
long now = U.currentTimeMillis();
long queueOversize = evts.sizex() - expireCnt;
for (int i = 0; i < queueOversize && evts.sizex() > expireCnt; i++) {
Event expired = evts.poll();
if (log.isDebugEnabled())
log.debug("Event expired by count: " + expired);
}
while (true) {
ConcurrentLinkedDeque8.Node<Event> node = evts.peekx();
if (// Queue is empty.
node == null)
break;
Event evt = node.item();
if (// Competing with another thread.
evt == null)
continue;
if (now - evt.timestamp() < expireAgeMs)
break;
if (evts.unlinkx(node) && log.isDebugEnabled())
log.debug("Event expired by age: " + node.item());
}
}
use of org.jsr166.ConcurrentLinkedDeque8 in project ignite by apache.
the class GridConcurrentLinkedDequeMultiThreadedTest method testQueueMultiThreaded.
/**
* @throws Exception If failed.
*/
@SuppressWarnings({ "BusyWait" })
public void testQueueMultiThreaded() throws Exception {
final AtomicBoolean done = new AtomicBoolean();
final ConcurrentLinkedDeque8<Byte> queue = new ConcurrentLinkedDeque8<>();
// Poll thread.
IgniteInternalFuture<?> pollFut = multithreadedAsync(new Callable<Object>() {
@Nullable
@Override
public Object call() throws Exception {
info("Thread started.");
while (!done.get()) try {
queue.poll();
} catch (Throwable t) {
error("Error in poll thread.", t);
done.set(true);
}
info("Thread finished.");
return null;
}
}, 5, "queue-poll");
// Producer thread.
IgniteInternalFuture<?> prodFut = multithreadedAsync(new Callable<Object>() {
@Nullable
@Override
public Object call() throws Exception {
info("Thread started.");
while (!done.get()) {
Node<Byte> n = queue.addx((byte) 1);
if (RND.nextBoolean())
queue.unlinkx(n);
}
info("Thread finished.");
return null;
}
}, 5, "queue-prod");
Thread.sleep(2 * 60 * 1000);
done.set(true);
pollFut.get();
prodFut.get();
}
use of org.jsr166.ConcurrentLinkedDeque8 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;
}
use of org.jsr166.ConcurrentLinkedDeque8 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.ConcurrentLinkedDeque8 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);
}
Aggregations