Uploaded image for project: 'Log4j 2'
  1. Log4j 2
  2. LOG4J2-812

Performance optimization: avoid use of synchronized SimpleDateFormat in Dat​ePatternCo​nverter

    XMLWordPrintableJSON

Details

    Description

      Threads seem to be blocking on class org.apache​.loggin.lo​g4j.core.p​attern.Dat​ePatternCo​nverter. It's short lived but is visible in profiler. It also is adding on to CPU. Here is the mail conversation on the mailing list:

      Ralph Goers ralph.goers@dslextreme.com via logging.apache.org

      The converter uses a SimpleDateFormat which is not thread safe and so is synchronized. I am sure there might be minor optimizations that could be done to this

      What I would do is modify DatePatternConverter to
      a) use Java 8’s java.time.format.DateTimeFormatter if running on Java 8
      b) use Joda Time’s DateTimeFormat if it is present.
      c) create a pool of SimpleDateFormat objects and use those.

      Please create a Jira issue for this.

      Ralph


      One alternative that was suggested on the mailing list is to use commons lang FastDateFormat to format log timestamps.

      Attachments

        1. LOG4J2-812-patch.txt
          17 kB
          Remko Popma
        2. LOG4J2-812.patch2.diff
          126 kB
          Ralph Goers
        3. LOG4J2-812.patch3.diff
          127 kB
          Ralph Goers

        Issue Links

          Activity

            People

              rgoers Ralph Goers
              mohitanchlia Mohit Anchlia
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: