use of org.apache.activemq.artemis.core.io.aio.AIOSequentialFileFactory 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;
}
}
use of org.apache.activemq.artemis.core.io.aio.AIOSequentialFileFactory 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);
}
}
use of org.apache.activemq.artemis.core.io.aio.AIOSequentialFileFactory 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();
}
}
use of org.apache.activemq.artemis.core.io.aio.AIOSequentialFileFactory 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();
}
use of org.apache.activemq.artemis.core.io.aio.AIOSequentialFileFactory in project activemq-artemis by apache.
the class AIOJournalImplTest method getFileFactory.
@Override
protected SequentialFileFactory getFileFactory() throws Exception {
File file = new File(getTestDir());
ActiveMQTestBase.deleteDirectory(file);
file.mkdir();
return new AIOSequentialFileFactory(getTestDirfile(), 10);
}
Aggregations