use of org.jctools.queues.SpscArrayQueue in project apex-core by apache.
the class AbstractReservoirTest method testSpscBlockingQueuePerformance.
@Test
@Ignore
public void testSpscBlockingQueuePerformance() {
final SpscArrayQueue<Object> spscArrayQueue = new SpscArrayQueue<>(CAPACITY);
final ReentrantLock lock = new ReentrantLock();
final Condition notFull = lock.newCondition();
final long start = System.currentTimeMillis();
final Thread t = new Thread(new Runnable() {
@Override
public void run() {
try {
int sleepMillis;
for (int i = 0; i < COUNT; i++) {
sleepMillis = 0;
while (spscArrayQueue.poll() == null) {
sleep(sleepMillis);
sleepMillis = Math.min(10, sleepMillis + 1);
}
lock.lock();
notFull.signal();
lock.unlock();
}
} catch (InterruptedException e) {
logger.error("Interrupted", e);
throw new RuntimeException(e);
}
}
});
t.start();
final Object o = new Byte[128];
try {
for (int i = 0; i < COUNT; i++) {
if (!spscArrayQueue.offer(o)) {
lock.lockInterruptibly();
while (!spscArrayQueue.offer(o)) {
notFull.await();
}
lock.unlock();
}
}
t.join();
} catch (InterruptedException e) {
logger.error("Interrupted", e);
throw new RuntimeException(e);
}
logger.debug("Time {}", System.currentTimeMillis() - start);
}
Aggregations