Filip Hanik - Dev Lists wrote:
> Mark Thomas wrote:
>> I was a little surprised that ThreadLocal seems to be slower. I still
>> wonder if I got the test wrong for that but I can't see anything.
>>
> If it was me doing the date, and making it all threadlocal, with no
> global variables at all
> And this will run faster, even though initially creating the thread
> local map incurs overhead, it doesn't do unnecessary object creation or
> assignment. And there is no need, since we are local at all times.

Thanks for the review. I think I was having a "Can't see the woods for
the trees" moment.

I've made the changes you suggested and lo and behold the ThreadLocal is
quicker.

> testAccessLogGetDate: 16 threads and 10000000 iterations using Syncs
> took 7461ms
> testAccessLogGetDate: 16 threads and 10000000 iterations using
> ThreadLocals took 6433ms

Out of interest, how many cores are you running? With 4 cores I get a
bigger difference:
org.apache.catalina.valves.Benchmarks$TimeDateElementBenchmarkTest_Sync:
16 threads and 10000000 iterations using Syncs took 14359ms
org.apache.catalina.valves.Benchmarks$TimeDateElementBenchmarkTest_Local:
16 threads and 10000000 iterations using ThreadLocals took 1532ms

Per request this is still next to nothing. I did think about not
bothering to port the change at all. However, given the possibility for
contention with the various syncs on 'this' in the AccessLogValve, I
will port it as it will be quicker to port it than it would be to write
a better, more representative benchmark for the AccessLogValve.

Mark



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to