commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sebb <seb...@gmail.com>
Subject HttpClient - use ConcurrentHashMap instead of HashMap?
Date Sun, 09 Jan 2011 15:32:25 GMT
AbstractCookieSpec uses an unsynchronised  HashMap, so is not thread-safe.

AIUI, ConcurrentHashMap has much better performance than a
synchronised HashMap - but of course we are not using synch here.

A quick test using the code at [1] (1 thread, 1 VM) appears to show
that the performance of CHM and HM is fairly similar:

Map type:           HashMap
Runtime:            3000
Number of threads:  1
Write probability:  0.6
Remove probability: 0.02
Ops per second:     1260837.0

Map type:           ConcurrentHashMap
Runtime:            3000
Number of threads:  1
Write probability:  0.6
Remove probability: 0.02
Ops per second:     1313171.0

So I wonder if we should consider replacing HashMap with
ConcurrentHashMap in Cookies and elsewhere in HttpClient?

[1] http://unserializableone.blogspot.com/2007/04/performance-comparision-between.html

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Mime
View raw message