apache / apache/logging-log4j2

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

Open
#3,569 11 comments 1 reaction 0 assignees View on GitHub
waiting-for-maintainer
Dominant language
Java
Stars
3.6k
Forks
1.7k
Avg merge
21h 30m
Merged PRs (30d)
27

Description

## 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](https://github.com/user-attachments/assets/a316f1a6-ce6a-419c-a754-6bf2aec9f721)

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](https://github.com/user-attachments/assets/54e112ef-35f8-4f94-8ecc-cd4d2c05a0f4)

![Image](https://github.com/user-attachments/assets/102e503e-94de-496f-a24e-067526797dbd)

![Image](https://github.com/user-attachments/assets/4ed5c638-e571-4737-9802-0b17d5cdf0eb)

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

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.