Search in sources :

Example 6 with NIOSequentialFileFactory

use of org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory in project activemq-artemis by apache.

the class SequentialFileTptBenchmark method main.

public static void main(String[] args) throws Exception {
    final boolean dataSync = false;
    final boolean writeSync = true;
    final Type type = Type.Mapped;
    final int tests = 10;
    final int warmup = 20_000;
    final int measurements = 100_000;
    final int msgSize = 100;
    final byte[] msgContent = new byte[msgSize];
    Arrays.fill(msgContent, (byte) 1);
    final File tmpDirectory = new File("./");
    // using the default configuration when the broker starts!
    final SequentialFileFactory factory;
    switch(type) {
        case Mapped:
            final int fileSize = Math.max(msgSize * measurements, msgSize * warmup);
            factory = new MappedSequentialFileFactory(tmpDirectory, fileSize, true, ArtemisConstants.DEFAULT_JOURNAL_BUFFER_SIZE_AIO, ArtemisConstants.DEFAULT_JOURNAL_BUFFER_TIMEOUT_AIO, null).setDatasync(dataSync);
            break;
        case Nio:
            factory = new NIOSequentialFileFactory(tmpDirectory, true, ArtemisConstants.DEFAULT_JOURNAL_BUFFER_SIZE_NIO, ArtemisConstants.DEFAULT_JOURNAL_BUFFER_TIMEOUT_NIO, 1, false, null, null).setDatasync(dataSync);
            break;
        case Aio:
            factory = new AIOSequentialFileFactory(tmpDirectory, ArtemisConstants.DEFAULT_JOURNAL_BUFFER_SIZE_AIO, ArtemisConstants.DEFAULT_JOURNAL_BUFFER_TIMEOUT_AIO, 500, false, null, null).setDatasync(dataSync);
            // disable it when using directly the same buffer: ((AIOSequentialFileFactory)factory).disableBufferReuse();
            if (!LibaioContext.isLoaded()) {
                throw new IllegalStateException("lib AIO not loaded!");
            }
            break;
        default:
            throw new AssertionError("unsupported case");
    }
    factory.start();
    try {
        final EncodingSupport encodingSupport = new EncodingSupport() {

            @Override
            public int getEncodeSize() {
                return msgSize;
            }

            @Override
            public void encode(ActiveMQBuffer buffer) {
                final int writerIndex = buffer.writerIndex();
                buffer.setBytes(writerIndex, msgContent);
                buffer.writerIndex(writerIndex + msgSize);
            }

            @Override
            public void decode(ActiveMQBuffer buffer) {
            }
        };
        final int alignedMessageSize = factory.calculateBlockSize(msgSize);
        final long totalFileSize = Math.max(alignedMessageSize * measurements, alignedMessageSize * warmup);
        if (totalFileSize > Integer.MAX_VALUE)
            throw new IllegalArgumentException("reduce measurements/warmup");
        final int fileSize = (int) totalFileSize;
        final SequentialFile sequentialFile = factory.createSequentialFile("seq.dat");
        sequentialFile.getJavaFile().delete();
        sequentialFile.getJavaFile().deleteOnExit();
        sequentialFile.open();
        final long startZeros = System.nanoTime();
        sequentialFile.fill(fileSize);
        final long elapsedZeros = System.nanoTime() - startZeros;
        System.out.println("Zeroed " + fileSize + " bytes in " + TimeUnit.NANOSECONDS.toMicros(elapsedZeros) + " us");
        try {
            {
                final long elapsed = writeMeasurements(factory, sequentialFile, encodingSupport, warmup, writeSync);
                System.out.println("warmup:" + (measurements * 1000_000_000L) / elapsed + " ops/sec");
            }
            for (int t = 0; t < tests; t++) {
                final long elapsed = writeMeasurements(factory, sequentialFile, encodingSupport, measurements, writeSync);
                System.out.println((measurements * 1000_000_000L) / elapsed + " ops/sec");
            }
        } finally {
            sequentialFile.close();
        }
    } finally {
        factory.stop();
    }
}
Also used : MappedSequentialFileFactory(org.apache.activemq.artemis.core.io.mapped.MappedSequentialFileFactory) AIOSequentialFileFactory(org.apache.activemq.artemis.core.io.aio.AIOSequentialFileFactory) NIOSequentialFileFactory(org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory) MappedSequentialFileFactory(org.apache.activemq.artemis.core.io.mapped.MappedSequentialFileFactory) AIOSequentialFileFactory(org.apache.activemq.artemis.core.io.aio.AIOSequentialFileFactory) ActiveMQExceptionType(org.apache.activemq.artemis.api.core.ActiveMQExceptionType) File(java.io.File) NIOSequentialFileFactory(org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory) EncodingSupport(org.apache.activemq.artemis.core.journal.EncodingSupport) ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer)

Example 7 with NIOSequentialFileFactory

use of org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory in project activemq-artemis by apache.

the class FileIOUtilTest method testCopy.

@Test
public void testCopy() throws Exception {
    System.out.println("Data at " + temporaryFolder.getRoot());
    SequentialFileFactory factory = new NIOSequentialFileFactory(temporaryFolder.getRoot(), 100);
    SequentialFile file = factory.createSequentialFile("file1.bin");
    file.open();
    ByteBuffer buffer = ByteBuffer.allocate(204800);
    buffer.put(new byte[204800]);
    buffer.rewind();
    file.writeDirect(buffer, true);
    buffer = ByteBuffer.allocate(409605);
    buffer.put(new byte[409605]);
    buffer.rewind();
    SequentialFile file2 = factory.createSequentialFile("file2.bin");
    file2.open();
    file2.writeDirect(buffer, true);
    // This is allocating a reusable buffer to perform the copy, just like it's used within LargeMessageInSync
    buffer = ByteBuffer.allocate(4 * 1024);
    SequentialFile newFile = factory.createSequentialFile("file1.cop");
    FileIOUtil.copyData(file, newFile, buffer);
    SequentialFile newFile2 = factory.createSequentialFile("file2.cop");
    FileIOUtil.copyData(file2, newFile2, buffer);
    Assert.assertEquals(file.size(), newFile.size());
    Assert.assertEquals(file2.size(), newFile2.size());
    newFile.close();
    newFile2.close();
    file.close();
    file2.close();
    System.out.println("Test result::");
}
Also used : SequentialFile(org.apache.activemq.artemis.core.io.SequentialFile) ByteBuffer(java.nio.ByteBuffer) SequentialFileFactory(org.apache.activemq.artemis.core.io.SequentialFileFactory) NIOSequentialFileFactory(org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory) NIOSequentialFileFactory(org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory) Test(org.junit.Test)

Example 8 with NIOSequentialFileFactory

use of org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory in project activemq-artemis by apache.

the class PagingStoreImplTest method testRestartPage.

@Test
public void testRestartPage() throws Throwable {
    clearDataRecreateServerDirs();
    SequentialFileFactory factory = new NIOSequentialFileFactory(new File(getPageDir()), 1);
    PagingStoreFactory storeFactory = new FakeStoreFactory(factory);
    final int MAX_SIZE = 1024 * 10;
    AddressSettings settings = new AddressSettings().setPageSizeBytes(MAX_SIZE).setAddressFullMessagePolicy(AddressFullMessagePolicy.PAGE);
    final PagingStore storeImpl = new PagingStoreImpl(PagingStoreImplTest.destinationTestName, null, 100, createMockManager(), createStorageManagerMock(), factory, storeFactory, new SimpleString("test"), settings, getExecutorFactory().getExecutor(), true);
    storeImpl.start();
    Assert.assertEquals(0, storeImpl.getNumberOfPages());
    // Marked the store to be paged
    storeImpl.startPaging();
    storeImpl.depage();
    Assert.assertNull(storeImpl.getCurrentPage());
    storeImpl.startPaging();
    Assert.assertNotNull(storeImpl.getCurrentPage());
    storeImpl.stop();
}
Also used : AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) PagingStoreImpl(org.apache.activemq.artemis.core.paging.impl.PagingStoreImpl) PagingStoreFactory(org.apache.activemq.artemis.core.paging.PagingStoreFactory) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) SequentialFile(org.apache.activemq.artemis.core.io.SequentialFile) File(java.io.File) PagingStore(org.apache.activemq.artemis.core.paging.PagingStore) FakeSequentialFileFactory(org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.FakeSequentialFileFactory) NIOSequentialFileFactory(org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory) SequentialFileFactory(org.apache.activemq.artemis.core.io.SequentialFileFactory) NIOSequentialFileFactory(org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory) Test(org.junit.Test)

Example 9 with NIOSequentialFileFactory

use of org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory in project activemq-artemis by apache.

the class PagingStoreImplTest method testPageWithNIO.

@Test
public void testPageWithNIO() throws Exception {
    ActiveMQTestBase.recreateDirectory(getTestDir());
    testConcurrentPaging(new NIOSequentialFileFactory(new File(getTestDir()), 1), 1);
}
Also used : SequentialFile(org.apache.activemq.artemis.core.io.SequentialFile) File(java.io.File) NIOSequentialFileFactory(org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory) Test(org.junit.Test)

Example 10 with NIOSequentialFileFactory

use of org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory in project activemq-artemis by apache.

the class JournalCleanupCompactStressTest method setUp.

@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    threadPool = Executors.newFixedThreadPool(20, tFactory);
    executorFactory = new OrderedExecutorFactory(threadPool);
    testExecutor = executorFactory.getExecutor();
    maxRecords = new Semaphore(MAX_WRITES);
    errors.set(0);
    File dir = new File(getTemporaryDir());
    dir.mkdirs();
    SequentialFileFactory factory;
    int maxAIO;
    if (LibaioContext.isLoaded()) {
        factory = new AIOSequentialFileFactory(dir, 10);
        maxAIO = ActiveMQDefaultConfiguration.getDefaultJournalMaxIoAio();
    } else {
        factory = new NIOSequentialFileFactory(dir, true, 1);
        maxAIO = ActiveMQDefaultConfiguration.getDefaultJournalMaxIoNio();
    }
    journal = new JournalImpl(50 * 1024, 20, 20, 50, ActiveMQDefaultConfiguration.getDefaultJournalCompactPercentage(), factory, "activemq-data", "amq", maxAIO) {

        @Override
        protected void onCompactLockingTheJournal() throws Exception {
        }

        @Override
        protected void onCompactStart() throws Exception {
            testExecutor.execute(new Runnable() {

                @Override
                public void run() {
                    try {
                        // System.out.println("OnCompactStart enter");
                        if (running) {
                            long id = idGen.generateID();
                            journal.appendAddRecord(id, (byte) 0, new byte[] { 1, 2, 3 }, false);
                            journal.forceMoveNextFile();
                            journal.appendDeleteRecord(id, id == 20);
                        }
                    // System.out.println("OnCompactStart leave");
                    } catch (Exception e) {
                        e.printStackTrace();
                        errors.incrementAndGet();
                    }
                }
            });
        }
    };
    journal.start();
    journal.loadInternalOnly();
}
Also used : OrderedExecutorFactory(org.apache.activemq.artemis.utils.actors.OrderedExecutorFactory) AIOSequentialFileFactory(org.apache.activemq.artemis.core.io.aio.AIOSequentialFileFactory) Semaphore(java.util.concurrent.Semaphore) File(java.io.File) SequentialFileFactory(org.apache.activemq.artemis.core.io.SequentialFileFactory) NIOSequentialFileFactory(org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory) AIOSequentialFileFactory(org.apache.activemq.artemis.core.io.aio.AIOSequentialFileFactory) NIOSequentialFileFactory(org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory) JournalImpl(org.apache.activemq.artemis.core.journal.impl.JournalImpl) Before(org.junit.Before)

Aggregations

NIOSequentialFileFactory (org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory)33 JournalImpl (org.apache.activemq.artemis.core.journal.impl.JournalImpl)19 File (java.io.File)18 SequentialFileFactory (org.apache.activemq.artemis.core.io.SequentialFileFactory)15 Test (org.junit.Test)11 RecordInfo (org.apache.activemq.artemis.core.journal.RecordInfo)10 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)7 PreparedTransactionInfo (org.apache.activemq.artemis.core.journal.PreparedTransactionInfo)7 SequentialFile (org.apache.activemq.artemis.core.io.SequentialFile)6 AIOSequentialFileFactory (org.apache.activemq.artemis.core.io.aio.AIOSequentialFileFactory)6 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 LinkedList (java.util.LinkedList)4 MappedSequentialFileFactory (org.apache.activemq.artemis.core.io.mapped.MappedSequentialFileFactory)4 JournalFile (org.apache.activemq.artemis.core.journal.impl.JournalFile)4 ActiveMQBuffer (org.apache.activemq.artemis.api.core.ActiveMQBuffer)3 EncodingSupport (org.apache.activemq.artemis.core.journal.EncodingSupport)3 Journal (org.apache.activemq.artemis.core.journal.Journal)3 FakeSequentialFileFactory (org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.FakeSequentialFileFactory)3 ByteBuffer (java.nio.ByteBuffer)2