|
| 1 | +In-memory benchmarks |
| 2 | +====================== |
| 3 | + |
| 4 | +This benchmark compares different Map implementations. We try to keep this test fair, no trick or extra tuning. |
| 5 | +Also dataset is small with no GC overhead. |
| 6 | + |
| 7 | +Benchmark source is in `Github repo <https://github.com/jankotek/mapdb-benchmarks>`_. |
| 8 | +Please send Pull Request if you have improvements. |
| 9 | +All tests ran on Linux with 64bit JDK8. |
| 10 | + |
| 11 | +Maps |
| 12 | +-------------- |
| 13 | + |
| 14 | +There are six maps in this test. All tests work on Map with 10 million entries to minimize GC overhead, |
| 15 | +Key is 8-byte long, value is 16-byte UUID. |
| 16 | +Small objects were chosen to better illustrate overhead of internal Map structures (nodes, hash table..) |
| 17 | + |
| 18 | +HTreeMap is concurrent HashMap implementation from MapDB. It is optimized for bigger keys and large number of entries. |
| 19 | +It has some extra features such as entry expiration with TTL or maximal size. |
| 20 | + |
| 21 | +BTreeMap is concurrent TreeMap implementation from MapDB. It is optimized for minimal space usage and for small keys. |
| 22 | +It has features to redoce memory and space usage. |
| 23 | + |
| 24 | +MapDB serializes all data into in-memory binary store backed by ``byte[]``. This storage is not limited by GC |
| 25 | + and ``DirectByteBuffer`` version was tested on half-terabyte of memory. |
| 26 | + |
| 27 | +There is also ``_heap`` mode where MapDB stores all data on-heap using pointers and object instances. |
| 28 | +There is no serialization involved. |
| 29 | +This mode is usually faster for smaller sets, but is limited by Garbage Collection. |
| 30 | + |
| 31 | +Memory usage |
| 32 | +~~~~~~~~~~~~~~ |
| 33 | + |
| 34 | +This chart shows how much entries ``Map<Long,UUID>`` can fit into 5GB of heap memory. |
| 35 | +JVM starts with 5GB maximal heap size (``-Xmx5G``), entries are added until JVM terminates with ``OutOfMemoryException``. |
| 36 | + |
| 37 | +.. centered:: **Number of entries inserted into Map with 5GB heap, before JVM runs out of memory (higher is better)** |
| 38 | +.. image:: target/charts/maps_memory_usage.png |
| 39 | + |
| 40 | +ConcurrentHashMap and ConcurrentSkipListMap are bundled with Java. Their both consume about the same amount of memory. |
| 41 | + |
| 42 | +BTreeMap should have in theory very good space usage. However underlying store is too fragmented after frequent updates, |
| 43 | +this bug should be solved soon. ``BTreeMap_pump`` shows best case for BTreeMap, with no fragmentation. |
| 44 | + |
| 45 | +``BTreeMap_heap`` is on-heap version of BTreeMap. It uses specialized node representation |
| 46 | +(``Long[]`` and ``UUID[]`` are internally stored in ``long[]``) and that makes it space efficient. |
| 47 | + |
| 48 | +HTreeMap is not yet optimized for space usage, no surprise here. |
| 49 | + |
| 50 | +SortedTableMap is very space efficient after compaction. |
| 51 | + |
| 52 | + |
| 53 | +Random updates |
| 54 | +~~~~~~~~~~~~~~~~~ |
| 55 | + |
| 56 | +.. centered:: **Time to update 100M random keys on Map with 100M entries (smaller is better)** |
| 57 | +.. image:: target/charts/maps_update.png |
| 58 | + |
| 59 | +``ConcurrentHashMap`` in this case rocks . |
| 60 | + |
| 61 | +``HTreeMap`` and ``BTreeMap`` are relatively slow. Optimizations are planned for M4. |
| 62 | + |
| 63 | +Random get |
| 64 | +~~~~~~~~~~~~~~~~~ |
| 65 | + |
| 66 | +.. centered:: **Time to get 100M random keys on Map with 100M entries (smaller is better)** |
| 67 | +.. image:: target/charts/maps_get.png |
| 68 | + |
| 69 | +``ConcurrentHashMap`` rocks again. |
| 70 | + |
| 71 | +``BTreeMap_heap`` takes advantage of specialization (it uses ``long[]`` instead of ``Long[]`` in BTree Nodes). |
| 72 | + |
| 73 | +``HTreeMap`` and ``BTreeMap`` are relatively slow. Optimizations are planned for M4. |
| 74 | + |
| 75 | + |
| 76 | + |
0 commit comments