Search in sources :

Example 1 with AIOSequentialFile

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();
    }
}
Also used : AIOSequentialFileFactory(org.apache.activemq.artemis.core.io.aio.AIOSequentialFileFactory) AIOSequentialFile(org.apache.activemq.artemis.core.io.aio.AIOSequentialFile) ArrayList(java.util.ArrayList) CountDownLatch(java.util.concurrent.CountDownLatch)

Aggregations

ArrayList (java.util.ArrayList)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 AIOSequentialFile (org.apache.activemq.artemis.core.io.aio.AIOSequentialFile)1 AIOSequentialFileFactory (org.apache.activemq.artemis.core.io.aio.AIOSequentialFileFactory)1