NOTE: This feature is only available in the extended version of MentaLog
MentaLog can use a memory mapped file for better performance. When you use this feature, a MappedByteBuffer is allocated and used to write the logs to disk so instead of making a system call on each call to fileChannel.write you write the bytes to memory and let the OS write it to disk whenever it finds it convenient.
You can use one of the static methods below to create a log that uses a memory mapped file:
Log.createMemoryMappedLogger(String dir, String filename, boolean isSynchronized, boolean isAsynchronous); Log.createMemoryMappedLogger(String dir, String filename, boolean isSynchronized, List<Encoder> encoders, boolean isAsynchronous); Log.createMemoryMappedLogger(String dir, String filename, boolean isSynchronized, int memoryMappedBufferSize, boolean isAsynchronous); Log.createMemoryMappedLogger(String dir, String filename, boolean isSynchronized, List<Encoder> encoders, int memoryMappedBufferSize, boolean isAsynchronous);
You can specify the mapped byte buffer size. if you don't specify anything it will default to 50 megabytes. It is important to choose a size large enough to accommodate all your logs so that the mapped byte buffer does not have to be rolled. Rolling is expensive because a new mapped byte buffer has to be created and the old one is discarded or cached to avoid creating garbage. For this cache option, see the cacheOnBufferRoll option below which defaults to true.
-DlogMemoryMappedBufferSize or Log.setMemoryMappedBufferSize(int size) - You can specify the default memory mapped buffer size that will be used if you don't specify any size in the methods above. If not specified it defaults to 50Mb.
-DlogMemoryMappedBufferThreshold or Log.setMemoryMappedBufferThreashold(double d) - You can specify the threshold percentage that triggers the rolling of the memory mapped buffer into a new one. It defaults to 0.8, in other words, when the buffer is 80% full a new one will be allocated.
-DlogAlertOnBufferRoll or Log.setAlertOnBufferRoll(boolean flag) - Alert if log file gets too big and requires a byte buffer roll which can be expensive. The default is false.
-DlogCacheOnBufferRoll or Log.setCacheOnBufferRoll(boolean flag) - Cache the old byte buffer so it does not get garbage collected in the event that it needs to be rolled. It is a soft cache, so if the JVM starts to run out of memory the old buffers will be garbage collected. It defaults to true.
-DlogForceOnBufferRoll or Log.setForceOnBufferRoll(boolean flag) - Call force on the mapped byte buffer in the event it needs to be rolled. Defaults to false.
-DlogForceOnClose or Log.setForceOnClose(boolean flag) - Call force on the mapped byte buffer when the log is closed. Defaults to false.