10 Replies Latest reply on Apr 14, 2012 9:42 AM by Lars Gråmark

    Log4j logger performance in JBoss AS 7

    Lars Gråmark Newbie

      I recently migrated an application from Tomcat 6 to JBoss 7. The migration went fine except but when we ran comparative performance tests between Tomcat and JBoss we found that

      the response times were a lot worse than in Tomcat. When I looked into the problem I found that the overhead was caused by the using log4j over the JBoss logging subsystem.

      The fact that the logging subsystem could have a slight overhead is understandable but I find the proportion a bit worrying.


      I simplified the test in order to recreate it for this forum and it now contains 10 calls to the log4j logger.

      When running this with 10 simultaneneous users and each with 100 requests I get approx 23 ms per call.

      Now if I compare this with a setup that does NOT use the logging subsystem but uses log4j directly I get approx 2 ms.

      Quite a differency.

      I havent run this through a profiler yet but I wanted to make a sanity check with you before proceeding with this.

      Did I miss anything in the configuration?


      This is what I did to get the figures for the logging subsystem.


      1. I installed a fresh copy of JBoss 7.1.1-final.
      2. I downloaded the latest version of the hellowolrd application from quickstarts.
      3. I added the following dependency to the pom.xml.
      4. Altered the HelloService to this:
        public class HelloService {
           Logger logger = Logger.getLogger(HelloService.class);

           String createHelloMessage(String name) {
               for (int i=0;i<10;i++) {
                   logger.warn("Hello world");
               return "Hello " + name + "!";
      5. Added the handler and the logger below to standalone.xml:
        <periodic-rotating-file-handler name="DEMO" autoflush="false">
                <pattern-formatter pattern="%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n"/>
            <file relative-to="jboss.server.log.dir" path="demo.log"/>
            <suffix value=".yyyy-MM-dd"/>
            <append value="true"/>
        <logger category="org.jboss.as.quickstarts" use-parent-handlers="false">
            <level name="INFO"/>
                <handler name="DEMO"/>
      6. Added the file jboss-deployment-structure.xml to WEB-INF
                    <module name="org.apache.log4j" />
      7. I then used the Apache benchmarking tool to get the numbers.
        ab -n100 -c10



      This is what I did to get the numbers for log4j without going through the logging subsystem:


      1. Replaced the file jboss-deployment-structure.xml in WEB-INF with the following contents:
                    <module name="org.apache.log4j" />
      2. Added the line below to bin/standalone.conf.
        JAVA_OPTS="$JAVA_OPTS -Dlog4j.configuration=file://<path to JBOSS_HOME>/standalone/configuration/log4j.xml"
      3. Added the file log4j.xml in standalone/configuration.
        <?xml version="1.0" encoding="UTF-8"?>
        <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
        <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"     debug="false">
           <appender name="DEMO" class="org.apache.log4j.DailyRollingFileAppender">
              <param name="File" value="${jboss.server.log.dir}/demo_direct.log" />
              <param name="Append" value="true" />
              <param name="DatePattern" value="'.'yyyy-MM-dd" />
              <layout class="org.apache.log4j.PatternLayout">
                 <param name="ConversionPattern" value="%d{ABSOLUTE} [%t] %-5p|%5X{id}|%-50.50c| %m%n" />
           <appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
              <param name="Target" value="System.out" />
              <param name="Threshold" value="DEBUG" />
              <layout class="org.apache.log4j.PatternLayout">
                 <param name="ConversionPattern" value="%d{ABSOLUTE} %-5p [%c{1}] %m%n" />
           <logger name="org.jboss.as.quickstarts" additivity="false">
              <level value="INFO" />
              <appender-ref ref="DEMO" />
              <priority value="INFO" />
              <appender-ref ref="DEMO" />
      4. Again I used the Apache benchmarking tool to get the numbers.
        ab -n100 -c10




      Lars Gråmark