Replies: 2 comments 4 replies
-
In Log4j 2 there are two types of asynchronous components:
Therefore with async loggers you'll have a single async thread, with async appenders you'll have multiple async threads. Remark: This seems like an XY problem. What is the ultimate goal you want to achieve? If a single thread is not able to handle the logging from the rest of the application, maybe you are logging too much? Note that most logging performance benchmarks assume an unrealistic situation, where all an application does is producing log events. |
Beta Was this translation helpful? Give feedback.
-
Thank you for your reply. I hope that under the same traffic pressure, after upgrading to log4j2, I can still output the same amount of log content. As you said, in log4j1 with async append, each appender is a BlockingQueue, and it has its own consumer to handle the LogEvent. This ensures that in cases where there are multiple Appends within an application, we can have multiple threads handling each file write individually. However, after upgrading to lo4j2, because all Asynclogggers share a LoggerContext, it means that they share a Ringbuffer. Similarly, there is only one consumer thread to handle log events and file writes. Per unit of time. It outputs a much smaller number of logs than log4j1 uses. For example(This can only be done by one consuming thread): By the way, in log4j2 I'm using RollingFileAppender +AsyncLogger. If we can bind a different LoggerContext or Ringbuffer for the different Appender, we can achieve the same effect as the async appender. Or there are other ways to help me achieve my goals. |
Beta Was this translation helpful? Give feedback.
-
My project was upgraded from log4j1 to log4j2.
Prerequisite: log4j1 and log4j2 use asynchronous logging, and log4j2 uses
AsyncLogger
.In log4j1, each Logger and Appender can be isolated; each Appender has a different thread writing a different file, but in log4j2, no matter how many AsyncLoggers there are, they all share a LoggerContext. As a result, only one thread gets data from the Ringbuffer and writes the log file, the amount of logs written per unit time is affected, and the throughput does not increase, no matter how the parameters are adjusted.
Is there any way around this scenario?
Beta Was this translation helpful? Give feedback.
All reactions