[
https://issues.apache.org/jira/browse/LOG4J2-1142?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14942331#comment-14942331
]
Remko Popma commented on LOG4J2-1142:
-------------------------------------
I added ThreadLocalVsPoolBenchmark in log4j-perf. Results: (Sampling mode, so
lower score is better)
*1 thread*
ObjectPool does better than new instance but not as well as ThreadLocal.
{code}
java -jar log4j-perf/target/benchmarks.jar ".*ThreadLocalVsPool.*" -f 1 -wi 10
-i 20 -tu ns -bm sample
Benchmark Mode Samples Score
Error Units
o.a.l.l.p.j.ThreadLocalVsPoolBenchmark.newInstance sample 279014 1269.062
± 19.034 ns/op
o.a.l.l.p.j.ThreadLocalVsPoolBenchmark.objectPool sample 296059 1194.341
± 20.673 ns/op
o.a.l.l.p.j.ThreadLocalVsPoolBenchmark.threadLocal sample 324899 1098.280
± 19.351 ns/op
{code}
*4 threads*
With multiple threads ThreadPool is still best but ObjectPool is now worse than
new instance.
{code}
java -jar log4j-perf/target/benchmarks.jar ".*ThreadLocalVsPool.*" -f 1 -wi 10
-i 20 -tu ns -bm sample -t 4
Benchmark Mode Samples Score
Error Units
o.a.l.l.p.j.ThreadLocalVsPoolBenchmark.newInstance sample 1195394 2352.861
± 58.072 ns/op
o.a.l.l.p.j.ThreadLocalVsPoolBenchmark.objectPool sample 1121414 2538.705
± 76.728 ns/op
o.a.l.l.p.j.ThreadLocalVsPoolBenchmark.threadLocal sample 1361047 2104.974
± 40.835 ns/op
{code}
> ThreadLocals in Layout implementations should be non-static to prevent memory
> leaks in web containers
> -----------------------------------------------------------------------------------------------------
>
> Key: LOG4J2-1142
> URL: https://issues.apache.org/jira/browse/LOG4J2-1142
> Project: Log4j 2
> Issue Type: Improvement
> Components: Layouts
> Affects Versions: 2.4
> Reporter: Dmitri Blinov
> Assignee: Remko Popma
> Fix For: 2.4.1
>
> Attachments: LOG4J2-1142.patch
>
>
> As discussed in LOG4J2-1125, storing ThreadLocal<StringBuilder> in a static
> field may not interact well with the thread pools and class loaders of some
> web containers and may result in memory leaks, especially in older web
> containers.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]