Sunday, May 03, 2015

Which Concurrent Hash Map?


There are several open source java collection libraries which provide concurrent hash map functionality. But which one is faster and suitable for a low latency application?

In this text, following concurrent hash map classes are investigated in terms of their performance:

Wherever it is required, these parameters are used:
  • Initial Capacity: 16
  • Concurrency level: 16
  • Load factor: 0.75

Setup

Two kind of tests are done to benchmark Map#put and Map#get() methods of these classes. Following setup is applied:
  • As key for maps random generated strings with length of 8 are used.
  • For warm up 100K operation is done before benchmarks are done for each tests.
  • Each main benchmark is done with various number of tasks (10,100,1K,10K,100K,1M,10M)
  • Each benchmark is repeated 5 times and its average is used as result.
  • 10 producer (thread) is used to do put/get operations to simulate concurrency.
  • To reduce garbage collection (GC) activities, before each benchmark, GC is forced , System.gc() and a large heap size is set.
  • Oracle JDK 1.8.0.25 is used
  • Test are done on a Redhat , Intel G6 @ 2.93Ghz with 12 cores server.

Results

Following tables and graphs illustrates elapsed time (macroSeconds) of put/get benchmarks.

Put : Classes/Time (macroSecond) 10 100 1000 10000 100000 1000000 10000000
Javolution_FastMap 188 157 292 1684 16857 297025 4228273
Oracle_ConcurrentHashMap 91 119 170 970 12388 207857 2684529
GS_ConcurrentHashMapUnsafe 85 111 259 1017 13290 252151 3053912
GS_ConcurrentHashMap 78 112 205 1060 14051 258071 3104562
Gauva_ConcurrentHashMap 74 93 158 911 12485 205433 2574604

 


Get: Classes/Time (macroSecond) 10 100 1000 10000 100000 1000000 10000000
Javolution_FastMap 98 105 215 1630 15732 215260 2296100
Oracle_ConcurrentHashMap 78 78 115 619 7411 144583 1866310
GS_ConcurrentHashMapUnsafe 86 81 149 960 10342 172114 2204728
GS_ConcurrentHashMap 69 77 146 1119 10322 168585 2027240
Gauva_ConcurrentHashMap 70 71 114 621 7861 129094 1581683



Conclusion

As tables and figures shows that ConcurrentHashMap implementation of Guava and Oracle performs best for put and get operations. This analysis also exposes myths about performance of FastMap by Javolution.

For source code of benchmark, please click here.

No comments: