logging-log4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Remko Popma (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (LOG4J2-812) Performance optimization: avoid use of synchronized SimpleDateFormat in Dat​ePatternCo​nverter
Date Sun, 05 Jul 2015 07:32:04 GMT

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

Remko Popma commented on LOG4J2-812:
------------------------------------

I added JMH benchmark /log4j-perf/src/main/java/org/apache/logging/log4j/perf/jmh/SimpleDateFormatBenchmark.
Results:

*1 Thread: almost no difference*

{code}
java -jar log4j-perf/target/benchmarks.jar ".*SimpleDateFormat.*" -f 1 -wi 5 -i 10 -t 1 -si
true

Benchmark                                                     Mode  Samples    Score    Error
 Units
o.a.l.l.p.j.SimpleDateFormatBenchmark.baseline              sample   108801   18.976 ±  1.142
 ns/op
o.a.l.l.p.j.SimpleDateFormatBenchmark.synchronizedFormat    sample   123187  374.147 ±  7.128
 ns/op
o.a.l.l.p.j.SimpleDateFormatBenchmark.threadLocalFormat     sample   127111  351.628 ± 15.233
 ns/op
{code}

*4 Threads: contended lock is ~20x slower than threadlocal*

{code}
java -jar log4j-perf/target/benchmarks.jar ".*SimpleDateFormat.*" -f 1 -wi 5 -i 10 -t 4 -si
true

Benchmark                                                     Mode  Samples      Score   
 Error  Units
o.a.l.l.p.j.SimpleDateFormatBenchmark.baseline              sample   448270     27.179 ±
  1.565  ns/op
o.a.l.l.p.j.SimpleDateFormatBenchmark.synchronizedFormat    sample   544613  13362.691 ±
376.438  ns/op
o.a.l.l.p.j.SimpleDateFormatBenchmark.threadLocalFormat     sample   443271    779.043 ±
 37.221  ns/op
{code}


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

> -----------------------------------------------------------------------------------------------
>
>                 Key: LOG4J2-812
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-812
>             Project: Log4j 2
>          Issue Type: Bug
>          Components: Pattern Converters, Performance Benchmarks
>    Affects Versions: 2.0.2
>            Reporter: Mohit Anchlia
>            Assignee: Remko Popma
>             Fix For: 2.3
>
>
> 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:
> {quote}
> 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
> {quote}
> ----
> One alternative that  was suggested on the mailing list is to use commons lang FastDateFormat
to format log timestamps.



--
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


Mime
View raw message