[
https://issues.apache.org/jira/browse/LOG4J2-812?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14614541#comment-14614541
]
Remko Popma commented on LOG4J2-812:
------------------------------------
The performance numbers Ralph posted on the ML look very nice. Let me reproduce
them here for future reference (I find benchmark results easier to read
formatted in Jira then on my phone mail app):
{quote}
I created an implementation that uses FastDateFormat and an AtomicReference. I
modified the benchmarks and the results are below. atomicFormat is the new
version. cachedFormat uses logic similar to what Remko proposed. fastFormat
simply uses the FastDateFormat on every timestamp. synchronizedFormat uses
logic similar to what is in the DatePatternConverter now. threadLocalFormat
retrieves a threadLocal SimpleDateFormat and formats every timestamp with it.
{quote}
*1 Thread*
{code}
Benchmark Mode Samples
Score Error Units
o.a.l.l.p.j.SimpleDateFormatBenchmark.atomicFormat sample 67961
93.774 ± 3.928 ns/op
o.a.l.l.p.j.SimpleDateFormatBenchmark.baseline sample 89151
39.136 ± 2.352 ns/op
o.a.l.l.p.j.SimpleDateFormatBenchmark.cachedFormat sample 66065
74.033 ± 3.613 ns/op
o.a.l.l.p.j.SimpleDateFormatBenchmark.fastFormat sample 79434
316.701 ± 6.443 ns/op
o.a.l.l.p.j.SimpleDateFormatBenchmark.synchronizedFormat sample 81409
304.055 ± 5.835 ns/op
o.a.l.l.p.j.SimpleDateFormatBenchmark.threadLocalFormat sample 84137
298.179 ± 6.005 ns/op
{code}
*4 Threads*
{code}
Benchmark Mode Samples
Score Error Units
o.a.l.l.p.j.SimpleDateFormatBenchmark.atomicFormat sample 270722
82.465 ± 1.767 ns/op
o.a.l.l.p.j.SimpleDateFormatBenchmark.baseline sample 290686
46.817 ± 1.348 ns/op
o.a.l.l.p.j.SimpleDateFormatBenchmark.cachedFormat sample 229500
86.370 ± 2.102 ns/op
o.a.l.l.p.j.SimpleDateFormatBenchmark.fastFormat sample 228713
435.373 ± 20.030 ns/op
o.a.l.l.p.j.SimpleDateFormatBenchmark.synchronizedFormat sample 293448
2113.380 ± 138.919 ns/op
o.a.l.l.p.j.SimpleDateFormatBenchmark.threadLocalFormat sample 283040
507.937 ± 15.903 ns/op
{code}
*8 Threads*
{code}
Benchmark Mode Samples
Score Error Units
o.a.l.l.p.j.SimpleDateFormatBenchmark.atomicFormat sample 389028
120.208 ± 39.351 ns/op
o.a.l.l.p.j.SimpleDateFormatBenchmark.baseline sample 523979
62.972 ± 2.952 ns/op
o.a.l.l.p.j.SimpleDateFormatBenchmark.cachedFormat sample 606880
125.257 ± 7.320 ns/op
o.a.l.l.p.j.SimpleDateFormatBenchmark.fastFormat sample 470751
768.610 ± 24.760 ns/op
o.a.l.l.p.j.SimpleDateFormatBenchmark.synchronizedFormat sample 614805
4598.192 ± 107.378 ns/op
o.a.l.l.p.j.SimpleDateFormatBenchmark.threadLocalFormat sample 434334
884.489 ± 130.365 ns/op
{code}
> Performance optimization: avoid use of synchronized SimpleDateFormat in
> DatePatternConverter
> -----------------------------------------------------------------------------------------------
>
> 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
>
> Attachments: LOG4J2-812-patch.txt, LOG4J2-812.patch2.diff
>
>
> Threads seem to be blocking on class
> org.apache.loggin.log4j.core.pattern.DatePatternConverter. 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 [email protected] 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: [email protected]
For additional commands, e-mail: [email protected]