HttpClient - use ConcurrentHashMap instead of HashMap?

2011-01-09 Thread sebb
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-unsubscr...@commons.apache.org
For additional commands, e-mail: dev-h...@commons.apache.org



Re: HttpClient - use ConcurrentHashMap instead of HashMap?

2011-01-09 Thread Ralph Goers
Why did you post this to the commons dev list instead of http-components dev?

Ralph

On Jan 9, 2011, at 7:32 AM, sebb wrote:

 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-unsubscr...@commons.apache.org
 For additional commands, e-mail: dev-h...@commons.apache.org
 


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



Re: HttpClient - use ConcurrentHashMap instead of HashMap?

2011-01-09 Thread sebb
On 9 January 2011 16:20, Ralph Goers ralph.go...@dslextreme.com wrote:
 Why did you post this to the commons dev list instead of http-components dev?

Oops, sorry!

However, the timings might still be interesting for Commons components...

 Ralph

 On Jan 9, 2011, at 7:32 AM, sebb wrote:

 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-unsubscr...@commons.apache.org
 For additional commands, e-mail: dev-h...@commons.apache.org



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



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