Search in sources :

Example 1 with MappedSequentialFileFactory

use of org.apache.activemq.artemis.core.io.mapped.MappedSequentialFileFactory in project activemq-artemis by apache.

the class JournalStorageManager method init.

@Override
protected void init(Configuration config, IOCriticalErrorListener criticalErrorListener) {
    if (!EnumSet.allOf(JournalType.class).contains(config.getJournalType())) {
        throw ActiveMQMessageBundle.BUNDLE.invalidJournal();
    }
    bindingsFF = new NIOSequentialFileFactory(config.getBindingsLocation(), criticalErrorListener, config.getJournalMaxIO_NIO());
    bindingsFF.setDatasync(config.isJournalDatasync());
    Journal localBindings = new JournalImpl(ioExecutorFactory, 1024 * 1024, 2, config.getJournalCompactMinFiles(), config.getJournalPoolFiles(), config.getJournalCompactPercentage(), config.getJournalFileOpenTimeout(), bindingsFF, "activemq-bindings", "bindings", 1, 0, criticalErrorListener);
    bindingsJournal = localBindings;
    originalBindingsJournal = localBindings;
    switch(config.getJournalType()) {
        case NIO:
            if (criticalErrorListener != null) {
                ActiveMQServerLogger.LOGGER.journalUseNIO();
            }
            journalFF = new NIOSequentialFileFactory(config.getJournalLocation(), true, config.getJournalBufferSize_NIO(), config.getJournalBufferTimeout_NIO(), config.getJournalMaxIO_NIO(), config.isLogJournalWriteRate(), criticalErrorListener, getCriticalAnalyzer());
            break;
        case ASYNCIO:
            if (criticalErrorListener != null) {
                ActiveMQServerLogger.LOGGER.journalUseAIO();
            }
            journalFF = new AIOSequentialFileFactory(config.getJournalLocation(), config.getJournalBufferSize_AIO(), config.getJournalBufferTimeout_AIO(), config.getJournalMaxIO_AIO(), config.isLogJournalWriteRate(), criticalErrorListener, getCriticalAnalyzer());
            break;
        case MAPPED:
            if (criticalErrorListener != null) {
                ActiveMQServerLogger.LOGGER.journalUseMAPPED();
            }
            journalFF = new MappedSequentialFileFactory(config.getJournalLocation(), config.getJournalFileSize(), true, config.getJournalBufferSize_NIO(), config.getJournalBufferTimeout_NIO(), criticalErrorListener);
            break;
        default:
            throw ActiveMQMessageBundle.BUNDLE.invalidJournalType2(config.getJournalType());
    }
    journalFF.setDatasync(config.isJournalDatasync());
    int fileSize = config.getJournalFileSize();
    // we need to correct the file size if its not a multiple of the alignement
    int modulus = fileSize % journalFF.getAlignment();
    if (modulus != 0) {
        int difference = modulus;
        int low = config.getJournalFileSize() - difference;
        int high = low + journalFF.getAlignment();
        fileSize = difference < journalFF.getAlignment() / 2 ? low : high;
        ActiveMQServerLogger.LOGGER.invalidJournalFileSize(config.getJournalFileSize(), fileSize, journalFF.getAlignment());
    }
    Journal localMessage = createMessageJournal(config, criticalErrorListener, fileSize);
    messageJournal = localMessage;
    originalMessageJournal = localMessage;
    largeMessagesDirectory = config.getLargeMessagesDirectory();
    largeMessagesFactory = new NIOSequentialFileFactory(config.getLargeMessagesLocation(), false, criticalErrorListener, 1);
    if (config.getPageMaxConcurrentIO() != 1) {
        pageMaxConcurrentIO = new Semaphore(config.getPageMaxConcurrentIO());
    } else {
        pageMaxConcurrentIO = null;
    }
}
Also used : MappedSequentialFileFactory(org.apache.activemq.artemis.core.io.mapped.MappedSequentialFileFactory) AIOSequentialFileFactory(org.apache.activemq.artemis.core.io.aio.AIOSequentialFileFactory) ReplicatedJournal(org.apache.activemq.artemis.core.replication.ReplicatedJournal) Journal(org.apache.activemq.artemis.core.journal.Journal) Semaphore(java.util.concurrent.Semaphore) NIOSequentialFileFactory(org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory) JournalImpl(org.apache.activemq.artemis.core.journal.impl.JournalImpl)

Example 2 with MappedSequentialFileFactory

use of org.apache.activemq.artemis.core.io.mapped.MappedSequentialFileFactory in project activemq-artemis by apache.

the class SyncCalculation method newFactory.

private static SequentialFileFactory newFactory(File datafolder, boolean datasync, JournalType journalType, int fileSize, int maxAIO) {
    SequentialFileFactory factory;
    if (journalType == JournalType.ASYNCIO && !LibaioContext.isLoaded()) {
        journalType = JournalType.NIO;
    }
    switch(journalType) {
        case NIO:
            factory = new NIOSequentialFileFactory(datafolder, 1).setDatasync(datasync);
            ((NIOSequentialFileFactory) factory).disableBufferReuse();
            factory.start();
            return factory;
        case ASYNCIO:
            factory = new AIOSequentialFileFactory(datafolder, maxAIO).setDatasync(datasync);
            factory.start();
            ((AIOSequentialFileFactory) factory).disableBufferReuse();
            return factory;
        case MAPPED:
            factory = new MappedSequentialFileFactory(datafolder, fileSize, false, 0, 0, null).setDatasync(datasync).disableBufferReuse();
            factory.start();
            return factory;
        default:
            throw ActiveMQMessageBundle.BUNDLE.invalidJournalType2(journalType);
    }
}
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) SequentialFileFactory(org.apache.activemq.artemis.core.io.SequentialFileFactory) NIOSequentialFileFactory(org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory)

Example 3 with MappedSequentialFileFactory

use of org.apache.activemq.artemis.core.io.mapped.MappedSequentialFileFactory 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 4 with MappedSequentialFileFactory

use of org.apache.activemq.artemis.core.io.mapped.MappedSequentialFileFactory in project activemq-artemis by apache.

the class MappedUnbuferedJournalImplTest method getFileFactory.

@Override
protected SequentialFileFactory getFileFactory() throws Exception {
    File file = new File(getTestDir());
    deleteDirectory(file);
    file.mkdir();
    return new MappedSequentialFileFactory(getTestDirfile(), 10 * 1024, false, 0, 0, null);
}
Also used : MappedSequentialFileFactory(org.apache.activemq.artemis.core.io.mapped.MappedSequentialFileFactory) File(java.io.File)

Example 5 with MappedSequentialFileFactory

use of org.apache.activemq.artemis.core.io.mapped.MappedSequentialFileFactory in project activemq-artemis by apache.

the class MappedJournalCompactTest method getFileFactory.

@Override
protected SequentialFileFactory getFileFactory() throws Exception {
    File file = new File(getTestDir());
    ActiveMQTestBase.deleteDirectory(file);
    file.mkdir();
    return new MappedSequentialFileFactory(getTestDirfile(), 60 * 1024, false, 0, 0, null);
}
Also used : MappedSequentialFileFactory(org.apache.activemq.artemis.core.io.mapped.MappedSequentialFileFactory) File(java.io.File)

Aggregations

MappedSequentialFileFactory (org.apache.activemq.artemis.core.io.mapped.MappedSequentialFileFactory)9 File (java.io.File)7 AIOSequentialFileFactory (org.apache.activemq.artemis.core.io.aio.AIOSequentialFileFactory)4 NIOSequentialFileFactory (org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory)4 ActiveMQBuffer (org.apache.activemq.artemis.api.core.ActiveMQBuffer)3 EncodingSupport (org.apache.activemq.artemis.core.journal.EncodingSupport)3 JournalImpl (org.apache.activemq.artemis.core.journal.impl.JournalImpl)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 SequentialFileFactory (org.apache.activemq.artemis.core.io.SequentialFileFactory)2 Journal (org.apache.activemq.artemis.core.journal.Journal)2 RecordInfo (org.apache.activemq.artemis.core.journal.RecordInfo)2 Test (org.junit.Test)2 MpscArrayQueue (io.netty.util.internal.shaded.org.jctools.queues.MpscArrayQueue)1 ByteBuffer (java.nio.ByteBuffer)1 ArrayList (java.util.ArrayList)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Executor (java.util.concurrent.Executor)1 ExecutorService (java.util.concurrent.ExecutorService)1 Semaphore (java.util.concurrent.Semaphore)1 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)1