use of org.apache.activemq.artemis.core.io.aio.AIOSequentialFile in project activemq-artemis by apache.
the class MultiThreadAsynchronousFileTest method executeTest.
private void executeTest(final boolean sync) throws Throwable {
MultiThreadAsynchronousFileTest.debug(sync ? "Sync test:" : "Async test");
AIOSequentialFileFactory factory = new AIOSequentialFileFactory(getTestDirfile(), 21000);
factory.start();
factory.disableBufferReuse();
AIOSequentialFile file = (AIOSequentialFile) factory.createSequentialFile(fileName);
file.open();
try {
MultiThreadAsynchronousFileTest.debug("Preallocating file");
file.fill(MultiThreadAsynchronousFileTest.NUMBER_OF_THREADS * MultiThreadAsynchronousFileTest.SIZE * MultiThreadAsynchronousFileTest.NUMBER_OF_LINES);
MultiThreadAsynchronousFileTest.debug("Done Preallocating file");
CountDownLatch latchStart = new CountDownLatch(MultiThreadAsynchronousFileTest.NUMBER_OF_THREADS + 1);
ArrayList<ThreadProducer> list = new ArrayList<>(MultiThreadAsynchronousFileTest.NUMBER_OF_THREADS);
for (int i = 0; i < MultiThreadAsynchronousFileTest.NUMBER_OF_THREADS; i++) {
ThreadProducer producer = new ThreadProducer("Thread " + i, latchStart, file, sync);
list.add(producer);
producer.start();
}
latchStart.countDown();
ActiveMQTestBase.waitForLatch(latchStart);
long startTime = System.currentTimeMillis();
for (ThreadProducer producer : list) {
producer.join();
if (producer.failed != null) {
throw producer.failed;
}
}
long endTime = System.currentTimeMillis();
MultiThreadAsynchronousFileTest.debug((sync ? "Sync result:" : "Async result:") + " Records/Second = " + MultiThreadAsynchronousFileTest.NUMBER_OF_THREADS * MultiThreadAsynchronousFileTest.NUMBER_OF_LINES * 1000 / (endTime - startTime) + " total time = " + (endTime - startTime) + " total number of records = " + MultiThreadAsynchronousFileTest.NUMBER_OF_THREADS * MultiThreadAsynchronousFileTest.NUMBER_OF_LINES);
} finally {
file.close();
factory.stop();
}
}
Aggregations