You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by "Gary Gregory (JIRA)" <ji...@apache.org> on 2015/06/10 01:14:01 UTC

[jira] [Commented] (LOG4J2-1048) FileConfigurationMonitor - High CPU usage

    [ https://issues.apache.org/jira/browse/LOG4J2-1048?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14579725#comment-14579725 ] 

Gary Gregory commented on LOG4J2-1048:
--------------------------------------

Note that there is a JIRA to redo this feature use the Java 7 file watch service.

There is also another JIRA to redo all timings using the nanosecond API instead of the millisecond API.

Nevertheless this is a good catch.

Thank you.

Also note that proposing changes is always better as patch file in unified diff format.

G

> FileConfigurationMonitor - High CPU usage
> -----------------------------------------
>
>                 Key: LOG4J2-1048
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-1048
>             Project: Log4j 2
>          Issue Type: Bug
>          Components: Configurators, Core
>    Affects Versions: 2.3
>            Reporter: Nikhil
>
> I am observing some high system CPU usage as a result of high number of calls to System.currentTimeMillis() in FileConfigurationMonitor.checkConfiguration() method.
> The checkConfiguration() method is called as part of Logger's every log/logIfEnabled and isEnabled method, therefore getting called thousands of times in my application when under moderate load. Each one of these calls therefore results in calling System.currentTimeMillis().
> The following code change, where the currentTimeMillis() is called only when required seemed to reduce the cpu load
> -final long current = System.currentTimeMillis();-
> -if(((counter.incrementAndGet() & MASK) == 0) && (current >= nextCheck))-
> Fixed as
> {code}
>  final long current;
>         if (((counter.incrementAndGet() & MASK) == 0) && ((current = System.currentTimeMillis()) >= nextCheck)) {
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org