Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

lmax RingBuffer with log4j takes up a lot of memory

I'm running a Tomcat web application in debug mode and, looking through the biggest objects with YourKit profiler, I see that by far the largest is a single instance of com.lmax.disruptor.RingBuffer. I assume this has something with log4j, which uses RingBuffer internally to report asynchronously. Is there any way I can reduce the memory footprint of this object? Why is it so large?

like image 509
Johnny Avatar asked Feb 10 '20 11:02

Johnny


1 Answers

From 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.

To reduce the memory usage, reduce the RingBuffer size (number of slots) by setting the system property:

log4j2.asyncLoggerRingBufferSize=value

The minimum size is 128. To allocate 5Mb set the value to 32768. See Log4j Async Loggers for more information.

like image 63
Boris Avatar answered Oct 23 '22 13:10

Boris