Skip to content

Memory Usage Increase in Log4j2 2.24.3 with Async Logging Due to RingBufferLogEvent #3569

Open
@shaonan666

Description

@shaonan666

Description

I am using Log4j2 in my project and recently upgraded from version 2.23.1 to 2.24.3. The application employs an asynchronous logging strategy with Disruptor version 3.4.3. Below is the relevant configuration:

  • log4j2.contextSelector=org.apache.logging.log4j.core.async.AsyncLoggerContextSelector
  • log4j2.asyncQueueFullPolicy=org.apache.logging.log4j.core.async.DiscardingAsyncQueueFullPolicy
  • log4j2.discardThreshold=ERROR
  • log4j2.asyncLoggerWaitStrategy=Yield
  • log4j2.asyncLoggerRingBufferSize=1048576

The logging frequency in my application is relatively low, averaging about 10 log entries per second. When using version 2.23.1, memory usage remained stable based on monitoring data . However, after upgrading to 2.24.3, I observed a gradual increase in memory usage over time, which eventually stabilizes at a fixed threshold.
Figure 1

This behavior differs significantly from what I experienced with 2.23.1. Through heap dump analysis at different time intervals, I confirmed that the memory growth is primarily associated with RingBufferLogEvent objects within Log4j2’s RingBuffer implementation, with the RingBuffer’s memory footprint consistently increasing over time.

Image

Image

Image

I noticed that the 2.24.3 release includes several changes related to memory management. Could any of these changes, particularly those affecting the RingBuffer or RingBufferLogEvent, explain the behavior I am observing?

If additional details are needed, please let me know, and I’d be happy to provide them.

Environment

  • Log4j2 Version: 2.24.3 (upgraded from 2.23.1)
  • Disruptor Version: 3.4.3
  • JVM: Zing24.08.101.0+1 (build 21.0.4.0.101+1-LTS)
  • Logging Frequency: ~10 logs/second

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    To triage

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions