Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Log4j2 monitorInterval performance

In log4j2, monitorInterval attribute is available for Configuration element. I tried to read about the performance impact of this attribute but couldn't find any source anywhere. So, I have multiple questions regarding monitorInterval attribute.

  1. I would like to know, what performance impact it has by specifying a small value as 5 (5 seconds) and a large value let's say as 3000 (5 minutes) in Configuration element?

  2. What exactly happens? Does that mean, it will automatically detect every time a specified interval of time has elapsed?

  3. Is there any way to force log4j2 to reload configuration right away via configuration files (XML, JSON, YAML, PROPERTIES), not programmatic reconfiguration?

like image 532
SSC Avatar asked Mar 09 '23 02:03

SSC


1 Answers

It used to be the case that there was a small performance impact. Concretely, Log4j2 would occasionally check the lastModified time of the configuration file when processing a log event. It was clever enough not to do that on every event but only when enough time had passed since the last time it checked: only once every monitorInterval seconds.

Since Log4j 2.5 it is different: there's a watcher background thread that occasionally wakes up and checks the lastModified time of the configuration file. So now there's no impact on logging performance. (The reason for this change was actually not performance but accuracy: previously files would not roll over if until a something was logged, which could be much later than the rollover time.) See https://issues.apache.org/jira/browse/LOG4J2-1202 for details.

To force a configuration reload, apart from touching the configuration file and programmatic reconfiguration, you can use the JMX interface. Also take a look at the Configurator class in log4j-core. It has several methods that result in reconfiguration.

like image 156
Remko Popma Avatar answered Mar 20 '23 19:03

Remko Popma