TailCache · Part 5 of 6

Why the same cache test gave me two answers

At the same memory setting, two runs picked different winners. Counting how many requests took longer than 100 microseconds helped explain the split.

Halfway sounded like a sensible place to look. With no extra data occupying Java’s heap, Caffeine gave us the quicker response near the slow end of the test. When we made the application keep another 208 mebibytes (MiB) in memory, Chronicle Map did. I wanted to know where the result changed. We tried 104 MiB.

Three comparisons gave us two answers. Chronicle was quicker twice. Caffeine was quicker once. Before choosing another memory size, I wanted to understand how the same setup could give us both.

When does a wait start?

We scheduled 50,000 requests a second on one worker. That means a request is due every 20 microseconds. Imagine the worker pauses for one millisecond. By the time it gets back, 50 requests have come due. A lookup might take only a few microseconds once the worker gets to it. The person who asked for the first record has already waited almost a millisecond.

We kept both times. Service time starts when the worker begins the operation. Response time starts when the request was due. Here we cared about response p99.9, the time by which roughly 999 of every 1,000 requests had finished, waiting included.

We kept the Java heap at 512 MiB and the cache at 32,768 records of 4,096 bytes each. About 95 out of every 100 requests read a record. The others replaced one. All 30 fresh Java processes finished their 1.5 million requests. So the disagreement at 104 MiB wasn’t a run that had simply given up halfway.

About 295 requests made the difference

I found the most helpful number by asking a simpler question of the Caffeine runs. How many requests waited longer than 100 microseconds? In 1.5 million requests, the slowest 0.1% is about 1,500. If more than 1,500 cross that line, p99.9 has to land above 100 microseconds.

In one run, about 1,686 crossed it. In another, about 1,391 did. That difference of roughly 295 requests put the two p99.9 readings at 359 and 33 microseconds. The third run landed at 426. Counting explained how the number jumped so far. It still left open what made those requests wait.

We tried two fresh request sequences. Both runs at the midpoint passed our checks for measurement problems. They still picked different winners. I left the crossover somewhere between 0 and 208 MiB for this workload. A more precise number would have been easier to put in the paper. I couldn’t defend one.

Which memory number would I put on a dashboard?

At 208 MiB of extra data, Chronicle used less of the Java heap after garbage collection. Yet when we sampled the whole program, Chronicle’s peak physical memory use was 796–812 MiB. Caffeine’s was 600–605 MiB. If I were tuning Java’s collector, I’d want the heap number. If I were deciding how much memory the machine needed, I’d want the second one too.