log4j RollingFileAppender performance












2














I need to log heavily for further analisys so when file is rolled the whole flow stuck for a while doing something like this:



"org.springframework.kafka.KafkaListenerEndpointContainer#1-1-C-1" - Thread t@56
java.lang.Thread.State: BLOCKED
at org.apache.logging.log4j.core.appender.rolling.RollingFileManager.checkRollover(RollingFileManager.java:174)
- waiting to lock <2afdff68> (a org.apache.logging.log4j.core.appender.rolling.RollingFileManager) owned by "SrpResultsProcessor-8" t@90
at org.apache.logging.log4j.core.appender.RollingFileAppender.append(RollingFileAppender.java:280)
at org.apache.logging.log4j.core.config.AppenderControl.tryCallAppender(AppenderControl.java:156)
at org.apache.logging.log4j.core.config.AppenderControl.callAppender0(AppenderControl.java:129)
at org.apache.logging.log4j.core.config.AppenderControl.callAppenderPreventRecursion(AppenderControl.java:120)
at org.apache.logging.log4j.core.config.AppenderControl.callAppender(AppenderControl.java:84)
at org.apache.logging.log4j.core.config.LoggerConfig.callAppenders(LoggerConfig.java:447)
at org.apache.logging.log4j.core.config.LoggerConfig.processLogEvent(LoggerConfig.java:432)
at org.apache.logging.log4j.core.config.LoggerConfig.log(LoggerConfig.java:416)
at org.apache.logging.log4j.core.config.LoggerConfig.log(LoggerConfig.java:402)
at org.apache.logging.log4j.core.config.AwaitCompletionReliabilityStrategy.log(AwaitCompletionReliabilityStrategy.java:63)
at org.apache.logging.log4j.core.Logger.logMessage(Logger.java:146)
at org.apache.logging.log4j.spi.AbstractLogger.logMessageSafely(AbstractLogger.java:2091)
at org.apache.logging.log4j.spi.AbstractLogger.logMessage(AbstractLogger.java:2005)
at org.apache.logging.log4j.spi.AbstractLogger.logIfEnabled(AbstractLogger.java:1876)
at org.apache.logging.slf4j.Log4jLogger.debug(Log4jLogger.java:124)
...


Here is my yaml config:



Configuration:
name: default

Appenders:

RollingFile:
- name: stdout
fileName: ../logs/${component.name}.log
filePattern: "../logs/archive/${component.name}_%d{yyyy-MM-dd}_%i.log.zip"
PatternLayout:
pattern: "%d{ISO8601} %-5level [%t] %logger{36} - %msg%n"
Policies:
SizeBasedTriggeringPolicy:
size: 300 MB
DefaultRollOverStrategy:
max: 20
Delete:
basePath: ../logs
maxDepth: 2
IfFileName:
glob: "*/${component.name}_*.log.zip"
IfAccumulatedFileCount:
exceeds: 50

- name: stderr
fileName: ../logs/${component.name}.err
filePattern: "../logs/archive/${component.name}_%d{yyyy-MM-dd}_%i.err.zip"
PatternLayout:
pattern: "%d{ISO8601} %-5level [%t] %logger{36} - %msg%n"
Policies:
SizeBasedTriggeringPolicy:
size: 300 MB
DefaultRollOverStrategy:
max: 5
Delete:
basePath: ../logs
maxDepth: 2
IfFileName:
glob: "*/${component.name}_*.err.zip"
IfAccumulatedFileCount:
exceeds: 10
...


Any ideas to improve performance of the 'rolling'?










share|improve this question
























  • Use a SocketAppender. Let Lilith handle the file rolling - in its own time.
    – Boris the Spider
    Jun 7 at 18:23












  • What is your current log4j config?
    – Adam
    Jun 7 at 19:34
















2














I need to log heavily for further analisys so when file is rolled the whole flow stuck for a while doing something like this:



"org.springframework.kafka.KafkaListenerEndpointContainer#1-1-C-1" - Thread t@56
java.lang.Thread.State: BLOCKED
at org.apache.logging.log4j.core.appender.rolling.RollingFileManager.checkRollover(RollingFileManager.java:174)
- waiting to lock <2afdff68> (a org.apache.logging.log4j.core.appender.rolling.RollingFileManager) owned by "SrpResultsProcessor-8" t@90
at org.apache.logging.log4j.core.appender.RollingFileAppender.append(RollingFileAppender.java:280)
at org.apache.logging.log4j.core.config.AppenderControl.tryCallAppender(AppenderControl.java:156)
at org.apache.logging.log4j.core.config.AppenderControl.callAppender0(AppenderControl.java:129)
at org.apache.logging.log4j.core.config.AppenderControl.callAppenderPreventRecursion(AppenderControl.java:120)
at org.apache.logging.log4j.core.config.AppenderControl.callAppender(AppenderControl.java:84)
at org.apache.logging.log4j.core.config.LoggerConfig.callAppenders(LoggerConfig.java:447)
at org.apache.logging.log4j.core.config.LoggerConfig.processLogEvent(LoggerConfig.java:432)
at org.apache.logging.log4j.core.config.LoggerConfig.log(LoggerConfig.java:416)
at org.apache.logging.log4j.core.config.LoggerConfig.log(LoggerConfig.java:402)
at org.apache.logging.log4j.core.config.AwaitCompletionReliabilityStrategy.log(AwaitCompletionReliabilityStrategy.java:63)
at org.apache.logging.log4j.core.Logger.logMessage(Logger.java:146)
at org.apache.logging.log4j.spi.AbstractLogger.logMessageSafely(AbstractLogger.java:2091)
at org.apache.logging.log4j.spi.AbstractLogger.logMessage(AbstractLogger.java:2005)
at org.apache.logging.log4j.spi.AbstractLogger.logIfEnabled(AbstractLogger.java:1876)
at org.apache.logging.slf4j.Log4jLogger.debug(Log4jLogger.java:124)
...


Here is my yaml config:



Configuration:
name: default

Appenders:

RollingFile:
- name: stdout
fileName: ../logs/${component.name}.log
filePattern: "../logs/archive/${component.name}_%d{yyyy-MM-dd}_%i.log.zip"
PatternLayout:
pattern: "%d{ISO8601} %-5level [%t] %logger{36} - %msg%n"
Policies:
SizeBasedTriggeringPolicy:
size: 300 MB
DefaultRollOverStrategy:
max: 20
Delete:
basePath: ../logs
maxDepth: 2
IfFileName:
glob: "*/${component.name}_*.log.zip"
IfAccumulatedFileCount:
exceeds: 50

- name: stderr
fileName: ../logs/${component.name}.err
filePattern: "../logs/archive/${component.name}_%d{yyyy-MM-dd}_%i.err.zip"
PatternLayout:
pattern: "%d{ISO8601} %-5level [%t] %logger{36} - %msg%n"
Policies:
SizeBasedTriggeringPolicy:
size: 300 MB
DefaultRollOverStrategy:
max: 5
Delete:
basePath: ../logs
maxDepth: 2
IfFileName:
glob: "*/${component.name}_*.err.zip"
IfAccumulatedFileCount:
exceeds: 10
...


Any ideas to improve performance of the 'rolling'?










share|improve this question
























  • Use a SocketAppender. Let Lilith handle the file rolling - in its own time.
    – Boris the Spider
    Jun 7 at 18:23












  • What is your current log4j config?
    – Adam
    Jun 7 at 19:34














2












2








2







I need to log heavily for further analisys so when file is rolled the whole flow stuck for a while doing something like this:



"org.springframework.kafka.KafkaListenerEndpointContainer#1-1-C-1" - Thread t@56
java.lang.Thread.State: BLOCKED
at org.apache.logging.log4j.core.appender.rolling.RollingFileManager.checkRollover(RollingFileManager.java:174)
- waiting to lock <2afdff68> (a org.apache.logging.log4j.core.appender.rolling.RollingFileManager) owned by "SrpResultsProcessor-8" t@90
at org.apache.logging.log4j.core.appender.RollingFileAppender.append(RollingFileAppender.java:280)
at org.apache.logging.log4j.core.config.AppenderControl.tryCallAppender(AppenderControl.java:156)
at org.apache.logging.log4j.core.config.AppenderControl.callAppender0(AppenderControl.java:129)
at org.apache.logging.log4j.core.config.AppenderControl.callAppenderPreventRecursion(AppenderControl.java:120)
at org.apache.logging.log4j.core.config.AppenderControl.callAppender(AppenderControl.java:84)
at org.apache.logging.log4j.core.config.LoggerConfig.callAppenders(LoggerConfig.java:447)
at org.apache.logging.log4j.core.config.LoggerConfig.processLogEvent(LoggerConfig.java:432)
at org.apache.logging.log4j.core.config.LoggerConfig.log(LoggerConfig.java:416)
at org.apache.logging.log4j.core.config.LoggerConfig.log(LoggerConfig.java:402)
at org.apache.logging.log4j.core.config.AwaitCompletionReliabilityStrategy.log(AwaitCompletionReliabilityStrategy.java:63)
at org.apache.logging.log4j.core.Logger.logMessage(Logger.java:146)
at org.apache.logging.log4j.spi.AbstractLogger.logMessageSafely(AbstractLogger.java:2091)
at org.apache.logging.log4j.spi.AbstractLogger.logMessage(AbstractLogger.java:2005)
at org.apache.logging.log4j.spi.AbstractLogger.logIfEnabled(AbstractLogger.java:1876)
at org.apache.logging.slf4j.Log4jLogger.debug(Log4jLogger.java:124)
...


Here is my yaml config:



Configuration:
name: default

Appenders:

RollingFile:
- name: stdout
fileName: ../logs/${component.name}.log
filePattern: "../logs/archive/${component.name}_%d{yyyy-MM-dd}_%i.log.zip"
PatternLayout:
pattern: "%d{ISO8601} %-5level [%t] %logger{36} - %msg%n"
Policies:
SizeBasedTriggeringPolicy:
size: 300 MB
DefaultRollOverStrategy:
max: 20
Delete:
basePath: ../logs
maxDepth: 2
IfFileName:
glob: "*/${component.name}_*.log.zip"
IfAccumulatedFileCount:
exceeds: 50

- name: stderr
fileName: ../logs/${component.name}.err
filePattern: "../logs/archive/${component.name}_%d{yyyy-MM-dd}_%i.err.zip"
PatternLayout:
pattern: "%d{ISO8601} %-5level [%t] %logger{36} - %msg%n"
Policies:
SizeBasedTriggeringPolicy:
size: 300 MB
DefaultRollOverStrategy:
max: 5
Delete:
basePath: ../logs
maxDepth: 2
IfFileName:
glob: "*/${component.name}_*.err.zip"
IfAccumulatedFileCount:
exceeds: 10
...


Any ideas to improve performance of the 'rolling'?










share|improve this question















I need to log heavily for further analisys so when file is rolled the whole flow stuck for a while doing something like this:



"org.springframework.kafka.KafkaListenerEndpointContainer#1-1-C-1" - Thread t@56
java.lang.Thread.State: BLOCKED
at org.apache.logging.log4j.core.appender.rolling.RollingFileManager.checkRollover(RollingFileManager.java:174)
- waiting to lock <2afdff68> (a org.apache.logging.log4j.core.appender.rolling.RollingFileManager) owned by "SrpResultsProcessor-8" t@90
at org.apache.logging.log4j.core.appender.RollingFileAppender.append(RollingFileAppender.java:280)
at org.apache.logging.log4j.core.config.AppenderControl.tryCallAppender(AppenderControl.java:156)
at org.apache.logging.log4j.core.config.AppenderControl.callAppender0(AppenderControl.java:129)
at org.apache.logging.log4j.core.config.AppenderControl.callAppenderPreventRecursion(AppenderControl.java:120)
at org.apache.logging.log4j.core.config.AppenderControl.callAppender(AppenderControl.java:84)
at org.apache.logging.log4j.core.config.LoggerConfig.callAppenders(LoggerConfig.java:447)
at org.apache.logging.log4j.core.config.LoggerConfig.processLogEvent(LoggerConfig.java:432)
at org.apache.logging.log4j.core.config.LoggerConfig.log(LoggerConfig.java:416)
at org.apache.logging.log4j.core.config.LoggerConfig.log(LoggerConfig.java:402)
at org.apache.logging.log4j.core.config.AwaitCompletionReliabilityStrategy.log(AwaitCompletionReliabilityStrategy.java:63)
at org.apache.logging.log4j.core.Logger.logMessage(Logger.java:146)
at org.apache.logging.log4j.spi.AbstractLogger.logMessageSafely(AbstractLogger.java:2091)
at org.apache.logging.log4j.spi.AbstractLogger.logMessage(AbstractLogger.java:2005)
at org.apache.logging.log4j.spi.AbstractLogger.logIfEnabled(AbstractLogger.java:1876)
at org.apache.logging.slf4j.Log4jLogger.debug(Log4jLogger.java:124)
...


Here is my yaml config:



Configuration:
name: default

Appenders:

RollingFile:
- name: stdout
fileName: ../logs/${component.name}.log
filePattern: "../logs/archive/${component.name}_%d{yyyy-MM-dd}_%i.log.zip"
PatternLayout:
pattern: "%d{ISO8601} %-5level [%t] %logger{36} - %msg%n"
Policies:
SizeBasedTriggeringPolicy:
size: 300 MB
DefaultRollOverStrategy:
max: 20
Delete:
basePath: ../logs
maxDepth: 2
IfFileName:
glob: "*/${component.name}_*.log.zip"
IfAccumulatedFileCount:
exceeds: 50

- name: stderr
fileName: ../logs/${component.name}.err
filePattern: "../logs/archive/${component.name}_%d{yyyy-MM-dd}_%i.err.zip"
PatternLayout:
pattern: "%d{ISO8601} %-5level [%t] %logger{36} - %msg%n"
Policies:
SizeBasedTriggeringPolicy:
size: 300 MB
DefaultRollOverStrategy:
max: 5
Delete:
basePath: ../logs
maxDepth: 2
IfFileName:
glob: "*/${component.name}_*.err.zip"
IfAccumulatedFileCount:
exceeds: 10
...


Any ideas to improve performance of the 'rolling'?







java performance log4j






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jun 8 at 11:37

























asked Jun 7 at 18:20









Mykhaylo Adamovych

8,345176190




8,345176190












  • Use a SocketAppender. Let Lilith handle the file rolling - in its own time.
    – Boris the Spider
    Jun 7 at 18:23












  • What is your current log4j config?
    – Adam
    Jun 7 at 19:34


















  • Use a SocketAppender. Let Lilith handle the file rolling - in its own time.
    – Boris the Spider
    Jun 7 at 18:23












  • What is your current log4j config?
    – Adam
    Jun 7 at 19:34
















Use a SocketAppender. Let Lilith handle the file rolling - in its own time.
– Boris the Spider
Jun 7 at 18:23






Use a SocketAppender. Let Lilith handle the file rolling - in its own time.
– Boris the Spider
Jun 7 at 18:23














What is your current log4j config?
– Adam
Jun 7 at 19:34




What is your current log4j config?
– Adam
Jun 7 at 19:34












2 Answers
2






active

oldest

votes


















0














-DLog4jContextSelector=org.apache.logging.log4j.core.async.AsyncLoggerContextSelector


source






share|improve this answer

















  • 1




    Please use the edit link on your question to add additional information. The Post Answer button should be used only for complete answers to the question. - From Review
    – EJoshuaS
    Jun 8 at 19:20



















0














This is a problem with high concurrency, and it works as designed. The file system (I/O) doesn't have the enough performance as required.



The synchronized makes BLOCKED some Java monitor when trying to acquire the resource.



/**
* Determines if a rollover should occur.
* @param event The LogEvent.
*/
public synchronized void checkRollover(final LogEvent event) {
if (triggeringPolicy.isTriggeringEvent(event)) {
rollover();
}
}


The solution as mentioned above is to move to Async logging.



https://logging.apache.org/log4j/2.x/manual/async.html






share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f50747813%2flog4j-rollingfileappender-performance%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    -DLog4jContextSelector=org.apache.logging.log4j.core.async.AsyncLoggerContextSelector


    source






    share|improve this answer

















    • 1




      Please use the edit link on your question to add additional information. The Post Answer button should be used only for complete answers to the question. - From Review
      – EJoshuaS
      Jun 8 at 19:20
















    0














    -DLog4jContextSelector=org.apache.logging.log4j.core.async.AsyncLoggerContextSelector


    source






    share|improve this answer

















    • 1




      Please use the edit link on your question to add additional information. The Post Answer button should be used only for complete answers to the question. - From Review
      – EJoshuaS
      Jun 8 at 19:20














    0












    0








    0






    -DLog4jContextSelector=org.apache.logging.log4j.core.async.AsyncLoggerContextSelector


    source






    share|improve this answer












    -DLog4jContextSelector=org.apache.logging.log4j.core.async.AsyncLoggerContextSelector


    source







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Jun 8 at 17:54









    Mykhaylo Adamovych

    8,345176190




    8,345176190








    • 1




      Please use the edit link on your question to add additional information. The Post Answer button should be used only for complete answers to the question. - From Review
      – EJoshuaS
      Jun 8 at 19:20














    • 1




      Please use the edit link on your question to add additional information. The Post Answer button should be used only for complete answers to the question. - From Review
      – EJoshuaS
      Jun 8 at 19:20








    1




    1




    Please use the edit link on your question to add additional information. The Post Answer button should be used only for complete answers to the question. - From Review
    – EJoshuaS
    Jun 8 at 19:20




    Please use the edit link on your question to add additional information. The Post Answer button should be used only for complete answers to the question. - From Review
    – EJoshuaS
    Jun 8 at 19:20













    0














    This is a problem with high concurrency, and it works as designed. The file system (I/O) doesn't have the enough performance as required.



    The synchronized makes BLOCKED some Java monitor when trying to acquire the resource.



    /**
    * Determines if a rollover should occur.
    * @param event The LogEvent.
    */
    public synchronized void checkRollover(final LogEvent event) {
    if (triggeringPolicy.isTriggeringEvent(event)) {
    rollover();
    }
    }


    The solution as mentioned above is to move to Async logging.



    https://logging.apache.org/log4j/2.x/manual/async.html






    share|improve this answer


























      0














      This is a problem with high concurrency, and it works as designed. The file system (I/O) doesn't have the enough performance as required.



      The synchronized makes BLOCKED some Java monitor when trying to acquire the resource.



      /**
      * Determines if a rollover should occur.
      * @param event The LogEvent.
      */
      public synchronized void checkRollover(final LogEvent event) {
      if (triggeringPolicy.isTriggeringEvent(event)) {
      rollover();
      }
      }


      The solution as mentioned above is to move to Async logging.



      https://logging.apache.org/log4j/2.x/manual/async.html






      share|improve this answer
























        0












        0








        0






        This is a problem with high concurrency, and it works as designed. The file system (I/O) doesn't have the enough performance as required.



        The synchronized makes BLOCKED some Java monitor when trying to acquire the resource.



        /**
        * Determines if a rollover should occur.
        * @param event The LogEvent.
        */
        public synchronized void checkRollover(final LogEvent event) {
        if (triggeringPolicy.isTriggeringEvent(event)) {
        rollover();
        }
        }


        The solution as mentioned above is to move to Async logging.



        https://logging.apache.org/log4j/2.x/manual/async.html






        share|improve this answer












        This is a problem with high concurrency, and it works as designed. The file system (I/O) doesn't have the enough performance as required.



        The synchronized makes BLOCKED some Java monitor when trying to acquire the resource.



        /**
        * Determines if a rollover should occur.
        * @param event The LogEvent.
        */
        public synchronized void checkRollover(final LogEvent event) {
        if (triggeringPolicy.isTriggeringEvent(event)) {
        rollover();
        }
        }


        The solution as mentioned above is to move to Async logging.



        https://logging.apache.org/log4j/2.x/manual/async.html







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 22 at 20:31









        devwebcl

        592721




        592721






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f50747813%2flog4j-rollingfileappender-performance%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            What visual should I use to simply compare current year value vs last year in Power BI desktop

            How to ignore python UserWarning in pytest?

            Alexandru Averescu