简体   繁体   English

LOG4j2异步记录器阻止功能

[英]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. 在log4j2中,当使用asyncappender时,您可以将记录器的参数“ blocking”设置为false,这样,溢出缓冲区大小的所有日志都将被丢弃,并且不会减慢主线程的速度。 (see here under asyncAppender https://logging.apache.org/log4j/2.x/manual/appenders.html ) (请参见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 我正在将我们的应用程序升级到此处的精美asyncLogger结构: 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? 所以可以肯定的是,我问这是因为我没有在文档中看到任何东西,如果有更多的日志输入而没有输出的日志(例如,我们将它们存储在数据库中并且插入需要花费一段时间),所以超出了ringbuffersize使用异步记录器时,多余的日志会怎样? 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.) (以目标负载的2或3倍进行测试是一个好主意。)

FYI, the fastest appender that comes with log4j 2 is RandomAccessFileAppender (and its Rolling variant ). 仅供参考,log4j 2随附的最快的追加器是RandomAccessFileAppender (及其Rolling变体 )。

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. 下一个版本(2.5.1) 将具有一项功能 ,允许用户在环形缓冲区已满80%或更多时丢弃事件(例如DEBUG和TRACE事件)。

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. 如果在AsyncAppender上设置了阻止并且队列已满,则显示该事件将传递给在errorRef属性上配置的Appender(如果已配置)。

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. 这样,一切都是异步的,我可以肯定处理方式与AsyncAppender不同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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