简体   繁体   中英

LOG4j2 async logger blocking functionality

background:

in log4j2 when using an asyncappender you have the ability to set the parameter "blocking" to false for the logger so any logs which overflow the buffer size will be discarded and not slow up the main thread. (see here under asyncAppender https://logging.apache.org/log4j/2.x/manual/appenders.html )

I am upgrading our application to the glorious asyncLogger structure found here: https://logging.apache.org/log4j/2.x/manual/async.html

while I see I can set the ring buffer size, I do not see anything stating that I can stop it from blocking the applications main thread,

question:

so just to be certain I am asking here as I dont see anything in the docs, if one has more logs coming in than logs going out(say we are stashing them in a DB and the insert is taking awhile) so the ringbuffersize is exceeded when using asyncloggers what happens to the extra logs? and will the main thread be slowed in any way?

thanks!

With async loggers, if your appender cannot keep up with the logging rate of the application, the ringbuffer will eventually fill up. When the ringbuffer is full, loggers will block trying to add a log event to the ringbuffer, so yes, application threads will be affected.

One of the reasons the default ringbuffer size is so large is that it can handle "bursts" of log events without impacting the application. However, it is important to select an appender that is appropriate for (can handle) the sustained logging rate of your application. (Testing with 2 or 3 times your target load is a good idea.)

FYI, the fastest appender that comes with log4j 2 is RandomAccessFileAppender (and its Rolling variant ).

The next release (2.5.1) will have a feature to allow users to drop events (eg DEBUG and TRACE events) when the ringbuffer is 80% full or more.

If blocking is set on the AsyncAppender and the queue is full it appears the event will be passed to the Appender configured on the errorRef attribute, if one is configured.

However, you asked also asked about what happens when using asynchronous loggers, which is separate. With that everything is asynchronous and I am pretty sure is handled differently than the AsyncAppender.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM