[Logo] Terracotta Discussion Forums (LEGACY READ-ONLY ARCHIVE)
  [Search] Search   [Recent Topics] Recent Topics   [Members]  Member Listing   [Groups] Back to home page 
[Register] Register / 
[Login] Login 
[Expert]
HashMap vs. ConcurrentHashMap  XML
Forum Index -> General
Author Message
micha.b

journeyman

Joined: 06/14/2007 14:21:15
Messages: 47
Offline

Hi,

I've found the following article:

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

I've tried this stuff in my own approach but didn't succeeded. Can it be, that if I use batched inserts like the HashMap.putAll method, the HashMap performs much better than the ConcurrentHashMap?

Best Regards
Michael
tgautier

seraphim

Joined: 06/05/2006 12:19:26
Messages: 1781
Offline

Michael,

It's possible. I found the same thing and talked with our Engineering Director about it. ConcurrentHashMap should work better across different nodes for individual writes because it won't have contention, but it might not be fast at bulk puts...we put it on the list to investigate further.

Notice also that the post is testing reads and writes, not just writes.
[WWW]
siyer

journeyman

Joined: 06/12/2007 07:42:16
Messages: 22
Offline

Michael - yes batching obviously is a useful strategy - so one/few transactions that put in batch into a Hashmap (resulting in 1/few lock acquisitions and commits to the terracotta server i.e. "Terracotta transactions") might indeed outperform a concurrentHashMap (which might involve multiple transactions in such a case).

Ofcourse, not all applications may support that characteristic of being able to interact with the map in batch. ConcurrentHashMap does outperform HashMap in the case where you have a large number of threads transacting in a fine-grained manner with the map where each thread needs to lock on a Map since a concurrentHashMap is essentially several HashMaps put together (16 by default, configurable on instantiation) - so essentially a put would contend for 1 out of 16 locks instead of a put to a Hashmap where there is only 1 lock to contend for across the cluster.

Once we support RentrantReadWriteLock, read performance against a ConcurrentHashMap will also improve. I believe this support was added a few weeks ago - so it should be in the 2.4 stable-build. I am not sure if though all the necessary changes in terms of improved read performance for ConcurrentHashMap are checked in yet...will let u know.

Thanks.
micha.b

journeyman

Joined: 06/14/2007 14:21:15
Messages: 47
Offline

Ok ... thanks. I'll stay tuned so far.

Best Regards
Michael
siyer

journeyman

Joined: 06/12/2007 07:42:16
Messages: 22
Offline

yeah support for ReentrantReadWriteLock is in 2.4 but you'll have to wait some more until stable of 2.5 is out, which will probably feature improved read performance for the concurrentHashMap
rgds
Sreeni Iyer
rsatish

neo

Joined: 10/28/2012 11:03:27
Messages: 1
Offline

See http://javaopensourcecode.blogspot.com/2012/06/concurrenthashmap.html
Article describes in detail about the internals of HashMap and CocurrentHashMap.
 
Forum Index -> General
Go to:   
Powered by JForum 2.1.7 © JForum Team