Same write rate, different winner
Both Java caches handled about 2,500 updates a second. Changing which records got updated reversed which cache gave the quicker response near the slow end.
The clue was in the list of records. Our early test had 32,768 records available to read. But the list of requests repeated about every 0.8 seconds. Depending on the starting sequence, only about 1,940 different records got updated. I’d been describing the test as “5% writes.” I’d left out where those writes went.
So we ran it two ways. In the first, updates could touch 2,048 records. In the second, they could touch all 32,768. Reads could reach every record in both. We kept everything else we could the same, including 4,096 bytes per record, 50,000 scheduled requests a second, 512 MiB of memory for Java to manage (its heap), and no extra data deliberately held there.
Either way, about 2,500 updates arrived each second. In the small set, an individual record was replaced about once every 0.82 seconds on average. Spread the updates across the whole cache and the same record lasted about 13 seconds between replacements. We’d changed how long the data lived without asking the machine to do any more writes.
Same number of writes. Different result.
We compared Caffeine, which keeps the records on Java’s heap, with Chronicle Map, which keeps their bytes outside it. We measured response p99.9 from when each request was due until its work finished. That gives the wait experienced near the slowest request in a thousand. Lower is better. These are the ranges across the 30-second runs on our second machine, in microseconds throughout.
| Records open to updates | Caffeine (µs) | Chronicle Map (µs) |
|---|---|---|
| 2,048 | 6.42–6.53 | 7.61–9.26 |
| 32,768 | 3,090–3,650 | 7.48–7.90 |
Caffeine was a little quicker when the same records kept getting updated. Spread those updates out and its slow responses took over three milliseconds. Chronicle stayed under eight microseconds at that percentile. We saw the same switch on the first machine and when we ran for 90 seconds on the second.
How can a seven-microsecond operation leave someone waiting?
One later run made the difference between the two clocks hard to miss. At 10% writes to the small set of records, Caffeine’s p99.9 was about 7 microseconds measured from the start of the operation, and 415 microseconds measured from when the request was due. The Java log recorded a 22-millisecond pause. At 50,000 arrivals a second, about 1,100 requests can come due in that time. The largest queue we recorded was 1,105.
That gives me a sense of what a pause costs at this load. It leaves a harder question. Why did the pause last 22 milliseconds? The logs don’t settle that. In the original 30-second comparison, Java’s G1 garbage collector spent about 4 milliseconds in collections that included older objects with concentrated writes, and 36–40 with writes spread out. Records living longer could help explain that. The log describes the whole program. It can’t tell me whether record 42 survived a particular collection.
What held up when we changed the test?
We doubled the arrival rate to 100,000 a second and cut the share of writes to 2.5%. That kept us at about 2,500 updates a second. Both request sequences still showed the switch. But when we kept arrivals at 50,000 and raised writes to 10% or 20%, the two sequences disagreed about the winner for the small set. I’d ask which records get updated before choosing a cache. I’d also ask how often.
We asked a different question in 48 paired runs. How quickly could one worker finish operations back to back, including making the fresh data for each write? With small, 256-byte records, Chronicle led all 24 comparisons at p99 and p99.9. With 4,096-byte records, Caffeine led all 24. That ranking held across the heap pressures we tried. This test tells me about the work a busy worker can finish. The scheduled test also tells me about requests still waiting for their turn.
The measurement I left out
I wanted to split a write in two. How much time went into making the new value, and how much into putting it in the cache? We added a reading of the clock between those steps. Before using the breakdown, we checked whether the extra reading changed the overall comparison. We’d agreed to tolerate a shift of 5% in the ratio between the caches. Timing every write moved it by more than 11% in one run. Even timing one write in eight moved it by more than 14% in another. We stopped there. I still don’t have a reliable split.
If I ran the hackathon experiment again, I’d bring a few representative records and a list of which ones actually change. I’d also find out where someone starts waiting for an answer. Then I’d try one more read method Chronicle offers, getUsing(), which lets a caller supply an object to reuse. If the caller finishes with the bytes immediately, that may save a copy. If it needs to keep the first answer while reading the next one, that first set of bytes has to live somewhere. I started with a question about how many copies a machine needed. Now I’d ask who needs each copy, and for how long.