Is ChronicleMap an improved Concurrent HashMap?

1.3k Views Asked by At

I am new to off-heap storage in JVM, and ChronicleMap looks good for off heap things. But my main concern is related to performance mostly.

I did run simple test with config

ChronicleMapBuilder<IntValue, BondVOImpl> builder =
                ChronicleMapBuilder.of(IntValue.class, BondVOImpl.class)
                .minSegments(512)
                .averageValue(new BondVOImpl())
                .maxBloatFactor(4.0)
                .valueMarshaller(new BytesMarshallableReaderWriter<>(BondVOImpl.class))
                .entries(ITERATIONS);

and found following results

----- Concurrent HASHMAP ------------------------
Time for putting 7258
Time for getting 678

----- CHRONICLE MAP ------------------------
Time for putting 4704
Time for getting 2246

Read performance is quite low as compare to Concurrent HashMap.

I have tried with 1024/2048 segments, with default Bloat factor, with default Marshaller too. But still same results.

I'm only looking to take advantage of Off Heap feature to reduce GC Pauses and no intentions to use persistent thing or replication or using map beyond the JVM.

So the question is should I use ChronicleMap or stick with ConcurrentHashMap? Or there are any other configs which I can use to enhance performance in case of ChronicleMap?

Thanks in advance.

** Benchmarking using https://github.com/OpenHFT/Chronicle-Map/blob/master/src/test/java/net/openhft/chronicle/map/perf/MapJLBHTest.java :**

enter image description here

1

There are 1 best solutions below

9
Dmitry Pisklov On

First of all, I don't buy your test results. You don't provide any code for your benchmark and I suspect the benchmark is fairly inaccurate (yes, benchmarking is fairly complicated subject, and without warmup and all the relevant stuff it's meaningless). Our benchmark gives me this:

-------------------------------- SUMMARY (Read) -----------------------------------------------------------
Percentile   run1         run2         run3      % Variation
50:             0.16         0.16         0.21        17.15
90:             0.23         0.20         0.35        33.48
99:             0.46         0.43         0.78        35.19
99.7:           0.74         1.22         1.59        16.83
99.9:           1.52         1.85         2.84        26.06
worst:         36.46      5187.58       161.09        95.41
-------------------------------------------------------------------------------------------------------------------
-------------------------------- SUMMARY (Write) -----------------------------------------------------------
Percentile   run1         run2         run3      % Variation
50:             2.67         2.69         3.05         8.21
90:             3.02         2.95         3.97        18.75
99:             4.51         6.20         9.06        23.50
99.7:           5.86         9.28        15.55        31.07
99.9:         930.56        22.10       964.86        96.60
worst:       1357.31    226033.66    233373.70         2.12
-------------------------------------------------------------------------------------------------------------------

Numbers are in microseconds, benchmark code is here https://github.com/OpenHFT/Chronicle-Map/blob/master/src/test/java/net/openhft/chronicle/map/perf/MapJLBHTest.java

And we had proofs that Chronicle Map is better than ConcurrentHashMap in most cases - but it depends on how well the marshalling is implemented.

That said, replacing ConcurrentHashMap is not a main use case for Chronicle Map.

  • Offheap maps are capable of storing vast amounts of data, uncomparable with heap data structures, without huge performance penalties.
  • In persisted mode it can be used between multiple processes
  • It can be replicated between hosts
  • etc