Day 21: Write a Microbenchmark Using Java Microbenchmark Harness (JMH) to Compare Off-Heap vs Heap Storage
Day 21: Benchmarking the Boundary between Heap and Off-Heap
In Day 20, you refactored AstraKV to store its payload segments in DirectByteBuffer instances, effectively moving your primary data storage out of the JVM's garbage-collected heap. By doing this, you successfully reduced the "stop-the-world" pause times caused by the GC scanning millions of objects. Today, we confront the reality of that decision: moving data off-heap is not a free lunch. We are trading GC pressure for explicit memory management and potential cache-miss overhead.
To make informed engineering decisions, you cannot rely on intuition or simple System.currentTimeMillis() measurements. You need the Java Microbenchmark Harness (JMH).
Keep going with the full lesson
The rest of this lesson — plus its implementation guide, runnable scripts and source code — is included with the course or an All Access plan. Create a free account to start the free lessons in every course.
Already a member? Sign in