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?
Asked
Active
Viewed 3,723 times
5
-
How large is it? What's the Tomcat version? – Boris Feb 10 '20 at 11:50
-
42M, running on Tomcat 9 with Java 8. – Johnny Feb 10 '20 at 11:56
-
Is 42M really a problem? – Thilo Feb 10 '20 at 12:39
-
2Not a problem, but I was curious about it. – Johnny Feb 10 '20 at 12:43
1 Answers
4
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.

Boris
- 22,667
- 16
- 50
- 71