lmax RingBuffer 与 log4j 占用大量内存

lmax RingBuffer with log4j takes up a lot of memory

我是 运行 一个处于调试模式的 Tomcat Web 应用程序,使用 YourKit 分析器查看最大的对象,我发现到目前为止最大的是 com.lmax.disruptor.RingBuffer.我假设这与 log4j 有关系,它在内部使用 RingBuffer 来异步报告。有什么办法可以减少这个对象的内存占用吗?为什么这么大?

来自Async Log4j2, memory leak?

The implementation of Apache Log4j2 in async mode uses a RingBuffer to buffering all the logs content. By default uses 262144 slots (256 * 1024). This causes an initial memory reserve of approximately 40 megabytes and in a environment with a limited memory causes the memory head to be always full and therefore the starting slowdown.

为了减少内存使用,通过设置系统属性:

减少RingBuffer大小(槽数)
log4j2.asyncLoggerRingBufferSize=value

最小大小为 128。要分配 5Mb,请将值设置为 32768。有关详细信息,请参阅 Log4j Async Loggers