[
https://issues.apache.org/jira/browse/LOG4J2-1417?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Remko Popma resolved LOG4J2-1417.
---------------------------------
Resolution: Fixed
Added a web-app safe representation for storing StringBuilders in ThreadLocals.
Performance testing showed the original representation is faster with multiple
threads, so the web-safe representation is only used if
Constants.ENABLE_THREADLOCALS is false.
*Original representation with 4 threads*
{code}
// java -Dlog4j2.enable.threadlocals=true -jar log4j-perf\target\benchmarks.jar
".*Unbox.*" -f 1 -wi 10 -i 15 -t 4
Benchmark Mode Samples Score Error Units
o.a.l.l.p.j.UnboxBenchmark.boxBoolean sample 797504 62.489 ± 1.197 ns/op
o.a.l.l.p.j.UnboxBenchmark.boxDouble sample 1073882 475.165 ± 6.840 ns/op
o.a.l.l.p.j.UnboxBenchmark.boxFloat sample 998490 279.987 ± 3.992 ns/op
o.a.l.l.p.j.UnboxBenchmark.boxInt sample 1149793 78.770 ± 2.661 ns/op
o.a.l.l.p.j.UnboxBenchmark.boxLong sample 629717 75.244 ± 0.865 ns/op
o.a.l.l.p.j.UnboxBenchmark.boxShort sample 685683 69.648 ± 1.057 ns/op
{code}
*Web-safe representation with 4 threads*
{code}
// java -Dlog4j2.enable.threadlocals=false -jar
log4j-perf\target\benchmarks.jar ".*Unbox.*" -f 1 -wi 10 -i 15 -t 4
Benchmark Mode Samples Score Error
Units
o.a.l.l.p.j.UnboxBenchmark.boxBoolean sample 680750 69.998 ± 4.319
ns/op
o.a.l.l.p.j.UnboxBenchmark.boxDouble sample 1096977 495.519 ± 11.621
ns/op
o.a.l.l.p.j.UnboxBenchmark.boxFloat sample 952154 301.714 ± 12.061
ns/op
o.a.l.l.p.j.UnboxBenchmark.boxInt sample 912080 102.098 ± 4.950
ns/op
o.a.l.l.p.j.UnboxBenchmark.boxLong sample 1016424 95.503 ± 10.432
ns/op
o.a.l.l.p.j.UnboxBenchmark.boxShort sample 611588 77.056 ± 2.721
ns/op
{code}
Fixed in master.
> Unbox should respect Constants.ENABLE_THREADLOCALS
> --------------------------------------------------
>
> Key: LOG4J2-1417
> URL: https://issues.apache.org/jira/browse/LOG4J2-1417
> Project: Log4j 2
> Issue Type: Bug
> Components: API
> Affects Versions: 2.6, 2.6.1
> Reporter: Remko Popma
> Assignee: Remko Popma
> Fix For: 2.6.2
>
>
> The org.apache.logging.log4j.util.Unbox class stores a non-JDK class
> (Unbox$State) in a static ThreadLocal field.
> This may cause memory leaks in containers which share thread pools between
> applications.
> One way to accomplish this is to have two ThreadLocal fields: one that stores
> an array of StringBuilders, and one that stores an AtomicLong to track the
> current slot.
> (If there is a performance impact we can switch between alternative
> implementations depending on the value of Constants.ENABLE_THREADLOCALS.)
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]