kafka and page cache: warm/cold reads + pollution

kafka and page cache: warm/cold reads + pollution

Contents

Abstract

Kafka serves recent data from the operating system’s page cache rather than from its own cache. We measured how much consumers gain from that, and whether a consumer reading old data hurts others by evicting their data. A single-node Kafka 4.4 broker with about 3.2 GiB of page cache and a separate load-generator VM ran on one Proxmox host, using two disk profiles: unthrottled NVMe, and the same disk throttled to a cloud-volume baseline of 125 MB/s and 3,000 IOPS.

Reading the same 2 GiB from disk instead of from cache took 1.3 times as long on NVMe, and 5.1 times as long on the throttled disk. In the second experiment, a producer wrote a steady 98 MiB/s while two consumers read it: one kept up in real time, and one deliberately stayed 19 seconds behind. A third consumer then read 12 GiB of old data, a “backfill”. On NVMe, the backfill pushed the delayed consumer’s data out of cache. Evicted pages were re-read five to six times as often, and the share of its data still in cache fell from 82% to about 60%. Even so, its worst-case (p99) latency rose only from about 16 ms to 37–69 ms. On the throttled disk, the same backfill pushed that consumer’s p99 to 9.2 s (sequential) and 9.5 s (random), and also slowed the real-time consumer and the producer. In two of six runs, nothing had recovered 5 minutes after the backfill stopped.

The broker’s own timing metrics suggest why. The backfill used up the disk’s read limit, and Kafka’s few shared network threads got stuck waiting on disk (in sendfile) for data that was not in cache. While stuck, they could not serve anyone else, the producer included. The conclusion: on fast local disks, cache pollution happens but costs little. On throttled cloud volumes, what protects healthy consumers is spare read capacity on the disk and keeping backfills away from them.

1. Introduction

Kafka does not keep its own read cache. It writes records to log segment files and relies on the operating system’s page cache to serve recent data from memory. A consumer that keeps up with the producer reads pages that were written moments ago and are still in RAM. A consumer that falls behind reads data the kernel has already evicted, so the broker has to go to disk.

This is well known in principle, and both effects have been reported before. KAFKA-3062 describes lagging consumers polluting the page cache for latency-sensitive ones. KAFKA-7504 shows a catch-up read blocking a network thread in sendfile and slowing producers. This article measures both on one setup, comparing a fast local disk with a throttled cloud-class disk, with every variable that is not under test held fixed.

Hypotheses

ID Hypothesis Primary evidence
H1 A consumer reading data still in page cache is faster than one reading evicted data from disk. Time to read the same 2 GiB, warm vs cold.
H2 The size of the H1 gap depends on disk speed. H1 repeated on an unthrottled NVMe disk and on a disk throttled to a cloud-volume baseline.
H3 A backfill consumer reading old data evicts pages that a slightly-lagging healthy consumer is about to read, raising that consumer’s latency. Refaults up, cache residency of the tail down, tail end-to-end latency up.
H4 (not run) Plaintext gets zero-copy (sendfile), TLS does not. TLS costs CPU but leaves H1 to H3 unchanged. Left for future work.

Who is the realistic victim

A consumer at lag 0 reads each page a few milliseconds after it is written. That page is the most recently used one in memory, so it is almost never evicted in that window. The consumer at risk is one that is healthy but a little behind, by seconds or minutes. The data between “written” and “read” has to survive in cache for that whole window. The pollution experiment therefore uses a deliberately delayed consumer as the expected victim, with a lag-0 consumer as the control.

2. Experimental setup

Everything ran on one Proxmox host, with the broker and the client in separate VMs so that they have separate page caches. Traffic between them never leaves the host, so the network is never the bottleneck. That matters here: the homelab’s physical network is 1 Gbit/s, about 119 MiB/s, while reads in this lab reach 650 MiB/s from cache and 490 MiB/s from NVMe. With the VMs on separate hosts, the network would have capped every read.

Hardware and virtual machines

Host px1 Broker VM Client VM
CPU Intel i5-8500, 6 cores / 6 threads, up to 4.1 GHz 4 vCPU, pinned to host cores 0-3 2 vCPU, pinned to host cores 4-5
Memory 16 GB 5 GiB, ballooning off; 1 GiB JVM heap; about 3.2 GiB left for page cache 3 GiB, ballooning off
Storage 512 GB NVMe, LVM-thin 200 GiB data disk, XFS, noatime, cache=none 24 GiB root disk only
Software Proxmox VE 9.1 Ubuntu 24.04, kernel 6.8, MGLRU on; Kafka 4.4.0 Ubuntu 24.04; kbench (Go, franz-go 1.22)

cache=none makes QEMU open the virtual disk with O_DIRECT, so the host’s own page cache never caches the broker’s disk I/O. A drop_caches inside the broker VM therefore gives a truly cold read.

The broker VM is small on purpose. With about 3.2 GiB of page cache, the data outgrows the cache within seconds at the produce rates used here, instead of after hundreds of gigabytes.

Kafka configuration

  • A single node in KRaft mode, acting as both broker and controller.
  • One partition, replication factor 1, compression.type=none, fixed 1 KiB records.
  • Infinite retention. log.flush.* and the segment size stay at their defaults, so the operating system decides when to flush dirty pages, as in a normal deployment.
  • Plaintext listener, so fetches use zero-copy sendfile.

Load generator

kbench is a small Go tool written for this lab, built on the franz-go client. Off-the-shelf perf tools report no end-to-end latency and cannot run a deliberately delayed consumer.

  • produce: a fixed rate in messages per second. The first 8 bytes of each record hold its send time in nanoseconds. Producer settings are acks=all, linger 5 ms, 1 MiB batches, no compression.
  • consume: reports per-second end-to-end latency (p50, p99, p99.9) and lag. With --delay D, it only processes records at least D seconds old and reports the excess latency beyond D. That makes it a healthy consumer that is a fixed distance behind.
  • backfill: reads an old topic either sequentially or by seeking to random offsets and reading 16 MiB chunks.

The producer and all consumers run on the same client VM. End-to-end latency is then measured against one clock, with no clock-skew error.

Disk profiles

The broker’s data disk is the variable under test. Proxmox applies QEMU I/O throttles to it live.

Profile Emulates Throttle Measured with fio: sequential read / random 4k read
nvme the raw local NVMe none 2,132 MiB/s / 133,000 IOPS
cloud an AWS gp3 baseline volume (GCP pd-balanced is similar: 3,000 IOPS and 140 MiB/s baseline) reads capped at 125 MB/s and 3,000 IOPS 125 MiB/s / 3,010 IOPS

The throttle applies to reads only. Writes stay unthrottled, which is kinder to the broker than a real cloud volume, where reads and writes share one budget.

Measurement

Each run starts collectors on the broker: iostat, vmstat, a /proc sampler for CPU, memory, refault and disk counters, and fincore every 5 s over the live topic’s segment files to measure how much of the topic is in page cache. kbench writes per-second CSVs on the client. Every run also writes a meta.json with the full configuration.

Prometheus on a Raspberry Pi scrapes node_exporter and Kafka’s JMX metrics every 2 s, for live viewing and the broker request-time breakdown. The CSV files are the source of truth, and the analysis script regenerates every table and figure from them.

3. Variables

Two things vary: the disk profile and the backfill mode. Everything else is held fixed, so any difference between runs comes from those two.

Kind Variable Values
Independent Disk profile nvme (unthrottled), cloud (reads capped at 125 MB/s and 3,000 IOPS)
Independent Backfill mode (Exp 3) sequential, random 16 MiB chunks
Independent Cache state (Exp 2) warm (data in page cache), cold (after drop_caches)
Controlled Record size 1 KiB
Controlled Topic layout 1 partition, replication factor 1, no compression
Controlled Produce rate (Exp 3) 100,000 records/s, about 98 MiB/s (50% of the measured keep-up ceiling)
Controlled Delayed consumer’s lag (Exp 3) 19 s, about 1.9 GiB of data, sized at 60% of the broker’s page cache
Controlled Broker resources 4 vCPU, 5 GiB RAM, 1 GiB heap, readahead 128 KiB, MGLRU on
Controlled Client resources 2 vCPU, 3 GiB RAM, separate page cache
Measured End-to-end latency per-second p99 of (receive time − send time − delay), per consumer
Measured Consumer lag records behind the end of the log
Measured Read throughput MiB/s for full timed reads (Exp 1, Exp 2)
Measured Page-cache residency share of the delayed consumer’s 1.9 GiB window in page cache, from fincore
Measured Refaults workingset_refault_file per second: pages evicted and then needed again
Measured Broker disk I/O read and write MiB/s, IOPS, utilisation on the data disk
Measured Broker request times Produce and Fetch time split into queue, local and send time (JMX)

Refaults are the most direct evidence of cache pollution. A refault counts a page that the kernel evicted and then had to read back from disk because something needed it again.

4. Method

There are four experiments, each repeated at least three times per disk profile. Results are reported as the median with min and max. Every run starts from a fresh topic and an empty broker page cache.

Exp 0: Baselines

  • iperf3 from client to broker and back, over the VM bridge.
  • fio on a file inside the broker’s data filesystem: 1 MiB sequential reads at queue depth 16, and 4 KiB random reads at queue depth 32, both with O_DIRECT for 30 s.

Exp 1: Ceilings (nvme only)

  • 1a, warm-read ceiling: write 2 GiB, which fits in page cache, then read it from the start three times. The best rate is the upper bound for reading from cache.
  • 1b, keep-up ceiling: a lag-0 consumer plus a producer at a fixed rate, stepping from 25,000 to 250,000 records/s, 60 s per step. The ceiling R_max is the highest rate where the producer hits its target and the consumer’s lag stays bounded.

Both ceilings are set by the client, not the disk, so they were measured once, on the unthrottled disk.

Exp 2: Warm vs cold (H1, H2)

  1. Write 2 GiB into a fresh topic and check that it is about 100% in page cache.
  2. Read it end to end twice. These are the warm reads.
  3. On the broker: sync, then echo 3 > /proc/sys/vm/drop_caches. Check that residency is about 0%.
  4. Read it again. This is the cold read.
  5. Read it once more, warm, to confirm that the cold read refilled the cache.

The ratio is the cold read time divided by the mean warm read time.

Exp 3: Pollution (H3)

Setup:

  • An old topic of 12 GiB, about 3.5 times the page cache, written once and then dropped from cache so it starts cold.
  • A live topic with the producer at 100,000 records/s, about 98 MiB/s.
  • Two consumers on the live topic:
    • tail0, at lag 0, the control;
    • tailD, delayed by 19 s. At 98 MiB/s that is a 1.9 GiB window, sized at 60% of the page cache. This is the expected victim.

Phases:

Phase Length What runs
W 49 s warm-up, until tailD’s delay is reached
A 5 min producer, tail0, tailD
B 5 min the same, plus a backfill consumer reading the old topic, sequentially or randomly
C 5 min backfill stopped; recovery

Phase A is the baseline and phase B is the test, so the analysis compares B with A. A metric counts as “moved” only if its B median differs from its A median by more than A’s normal noise. The difference has to beat the largest of three bars: 3 times A’s median absolute deviation (a robust measure of spread), 25% of A’s value, or a small fixed minimum. Each run then gets one of four verdicts:

  • Pollution confirmed: all three signs of eviction moved. Refaults went up, less of tailD’s window stayed in cache, and tailD’s p99 latency rose.
  • Contention only: tailD got slower, but its data stayed in cache and refaults did not rise. The backfill slowed it by competing for the disk, not by evicting its data.
  • No effect: nothing moved beyond phase A’s noise.
  • Mixed: any other combination. The metrics that moved are listed.

Validity checks

  • Pre-flight:
    • no other run in progress;
    • broker disk under 80% full;
    • client load low;
    • only the two lab VMs running on the host.
  • Client CPU: a run is invalid if the client stays above about 80% CPU, because then the load generator is the bottleneck. The busiest run peaked at 78% for a moment, with a 95th percentile of 49%.
  • Residency checks: Exp 2 aborts if the warm data is not at least 95% cached, or the dropped data is more than 2% cached. One early run failed this check, because the previous run’s deleted topic was still cached. Every run now ends its topic reset with a drop_caches.
  • Excluded run: an early warm-read ceiling run gave 549 MiB/s while a node_exporter collector used about 30% of a client core. It was discarded, and the collector was turned off for every run reported here.

5. Results

Every run reported below passed its validity checks. A cold read took 1.3 times as long as a warm one on NVMe and 5.1 times as long on the cloud-class disk. A backfill raised the delayed consumer’s median p99 from about 16 ms to 37–69 ms on NVMe, and to 9.2–9.5 s on the cloud disk.

5.1 Baselines (Exp 0)

Profile Runs Network, client to broker fio sequential read fio random 4k read
nvme 3 20.0 Gbit/s 2,132 MiB/s 133,207 IOPS
cloud 3 20.4 Gbit/s 125.4 MiB/s 3,010 IOPS

The VM-to-VM network runs at about 20 Gbit/s, about 2.4 GiB/s, far above any read rate in this lab. The cloud throttle holds its limits to within 0.5%.

5.2 Ceilings (Exp 1)

  • Warm-read ceiling: a single consumer reads from page cache at 652 MiB/s (median of 3 reads, range 646–654). The client is the limit here. One core goes to parsing records (unpacking about 650,000 records per second from Kafka’s binary format and checking their checksums), while the broker stays mostly idle.
  • Keep-up ceiling: a lag-0 consumer keeps up with a producer at up to 200,000 records/s (about 195 MiB/s), with p99 under 20 ms. At 250,000 records/s, lag grows without bound.

The pollution experiment therefore produces at half of R_max: 100,000 records/s. Half leaves headroom: at that rate the client keeps up easily, so any slowdown in phase B comes from the backfill, not from the client running near its own limit.

5.3 Warm vs cold (Exp 2)

Reading the same 2 GiB took 3.2 s from page cache on both disks. From disk, it took 4.1 s on NVMe and 16.4 s on the cloud disk.

Profile Runs Warm read Cold read Cold / warm Disk read rate during cold read fio sequential Cold read vs fio
nvme 4 3.18 s [3.13–3.26] 4.14 s [3.97–4.18] 1.29 [1.27–1.31] 494 MiB/s 2,132 MiB/s 23%
cloud 3 3.20 s [3.15–3.29] 16.45 s [16.44–16.45] 5.14 [4.99–5.22] 125 MiB/s 125 MiB/s 100%

On the cloud disk, the cold read runs at exactly the throttle limit. On NVMe, the cold read reaches only 23% of what fio gets from the same disk. An NVMe drive reaches full speed only with many reads in flight at once: fio kept 16 reads of 1 MiB each going in parallel. A single Kafka consumer has one fetch outstanding at a time, and the kernel’s 128 KiB readahead keeps only a read or two in flight, so the drive spends most of its time waiting for the next request. So even a fast disk gives a cold consumer about 490 MiB/s, against 650 MiB/s from cache. This is a single-consumer number. A production broker serving many partitions and consumers has many fetches in flight at once, so its cold reads can use far more of an NVMe drive’s speed.

5.4 Pollution (Exp 3)

In every run, the backfill raised the delayed consumer’s latency, and refaults rose as well. What differs between the two disks is the size of the effect and what happens to everyone else.

Per-run p99 of the delayed consumer, phase A vs phase B: 2–7.5× higher on NVMe, 230–760× on the cloud disk

Each line joins one run’s phase A and phase B. The number at the right is B divided by A.

Medians per condition, phase A vs phase B (3 runs each). p99 is the median of the per-second p99 values in each phase:

Profile / backfill tailD p99, A → B tail0 p99, A → B Refaults/s, A → B tailD window in cache, A → B Backfill read rate Verdicts
nvme / sequential 16 → 37 ms 19 → 24 ms 14,200 → 83,500 82% → 57% 232 MiB/s 1 confirmed, 2 mixed
nvme / random 17 → 69 ms 21 → 34 ms 11,500 → 70,400 83% → 65% 207 MiB/s 2 confirmed, 1 mixed
cloud / sequential 18 ms → 9.2 s 21 ms → 1.9 s 12,800 → 16,000 82% → 71% 62 MiB/s 3 mixed
cloud / random 18 ms → 9.5 s 21 ms → 6.5 s 13,000 → 25,800 82% → 76% 47 MiB/s 3 mixed

The “mixed” verdicts on NVMe have refaults up and residency down, but tailD’s p99 rose by less than the noise threshold in those runs. On the cloud disk, refaults only rose by 1.3 to 2 times. A disk capped at 3,000 IOPS cannot serve many more refaults, so the refault rate is itself throttled, and it stays under the noise threshold.

Recovery (phase C): on NVMe, every run returned to its phase-A latency within about a minute of the backfill stopping. On the cloud disk, the disk stayed pinned at its 125 MiB/s limit for all of phase C in all six runs, and the runs split into two groups:

  • Four runs recovered partly. tail0 settled at about 0.8–5 s p99. tailD stayed 3–58 s behind its target.
  • Two runs collapsed (one sequential, one random). tail0, the lag-0 control, fell up to 70 s behind, with p99 near 100 s at the end of phase C. The producer dropped from 100,000 to about 30,000–35,000 records/s for long stretches. In these two runs, tailD’s window residency fell to about 40%.

Why there was no full recovery: a consumer that has fallen behind needs data that is no longer cached. It must read from disk just to keep pace with the 98 MiB/s being produced, which leaves about 27 MiB/s of the disk’s 125 for catching up. With one consumer on disk, that was enough only for a partial recovery. With both on disk, demand exceeded what the disk could serve, and they fell further behind. The overload sustained itself after the backfill stopped, a pattern known as a metastable failure. Section 6.3 has the mechanism.

p99 of the lag-0 consumer over 15 minutes: flat near 20 ms on NVMe, about 2 s on a recovered cloud run, up to 144 s on a collapsed one

The two cloud runs had identical settings. In the collapsed one, the lag-0 consumer never got back to the latency it had before the backfill.

6. Discussion

The page cache matters far more on a slow disk than on a fast one. On a cloud-class disk, a backfill does more than pollute the cache: it can stall consumers that were never behind, and the producer too.

6.1 The warm-cold gap is set by whichever is slower: the consumer or the disk

A warm read is limited by the consumer, at about 650 MiB/s here. A cold read is limited by the disk path. On NVMe, a single consumer’s fetch loop pulls about 490 MiB/s from disk, close to the warm ceiling, so cold costs only 30%. On a 125 MiB/s volume, a cold read runs at the volume’s limit and takes five times as long.

The practical reading: on cloud block storage, a consumer that has fallen out of cache catches up at roughly the volume’s read throughput, not at the speed it showed while it was keeping up.

6.2 On NVMe, pollution is real but cheap

The backfill read 207–242 MiB/s of old data. That cut the delayed consumer’s window residency from about 82% to 57–65% and raised refaults five to six times. Those are exactly the signs of pollution H3 predicts. But the disk served the extra misses in milliseconds:

  • tailD’s median p99 rose from about 16 ms to 37 ms (sequential) and 69 ms (random); single runs ranged from 27 to 120 ms;
  • tail0 barely moved (+5 to +13 ms);
  • everything recovered within a minute of the backfill stopping.

6.3 On a throttled disk, a shared read budget and blocked network threads cause a cascade

Three things combine.

  1. The read budget is already half used before the backfill starts. In phase A, the broker read 44–52 MiB/s from disk in every run (section 6.4). That is 40% of the cloud disk’s budget.
  2. The backfill takes the rest. The disk sat at its 125 MiB/s cap for all of phase B in all six cloud runs. tailD’s misses now queue behind backfill reads.
  3. Cold fetches block threads that other clients share. Kafka sends fetch data with sendfile from a small pool of network threads (3 by default). When the data is not in cache, sendfile waits on the disk, and so does the thread. Broker metrics show this at p99.9:
    • Fetch response send time reached about 1.2 s.
    • Produce responses waited up to 1.7 s in the response queue for a network thread to pick them up, though the broker wrote the data in 10–30 ms.

So the producer and the lag-0 consumer stall behind cold reads for other clients. Once tail0 falls far enough behind, its own data gets evicted and it starts reading from disk too. The disk then has about 27 MiB/s of headroom (125 minus the 98 MiB/s being produced) to serve two consumers catching up. That is not enough, so the system can settle into either state: recovered, or collapsed. Which one a run ends in depends on whether tail0 is pushed out of cache during phase B. In two of six runs it was.

Proposed feedback loop: backfill saturates the disk, network threads block in sendfile, other clients stall, tail0 falls out of cache and becomes a second cold reader

The network-thread explanation fits the request-time breakdown, and matches KAFKA-7504, where LINE engineers traced produce-latency spikes during a catch-up read to sendfile blocking a network thread. It is not proven in this lab, though. Kafka has a metric for exactly this: the share of time its network threads sit idle. Threads stuck in sendfile should push it well below 100%. It read a constant 100% for the whole run, which is implausible under this load, so it was probably not measured correctly and could neither confirm nor rule out stuck threads.

6.4 The 60% window did not fit

The delayed consumer’s 1.9 GiB window was sized at 60% of the 3.2 GiB page cache. In phase A of every run, before any backfill, only about 82% of that window was cached, with 11,000–14,000 refaults/s. That works out to about 1.6 GiB of recent data kept, roughly half of the page cache. So tailD was already reading part of its data from disk.

Why only half the cache held recent data was not investigated. Likely suspects: the kernel’s page-replacement policy (MGLRU) evicting freshly written pages earlier than expected, readahead filling cache with pages nobody asked for, and other files competing for the same memory. Whatever the cause, it changes how to read the results. Phase A was not a clean “no problem” baseline: tailD already missed about 18% of its reads before any backfill. On NVMe those misses cost nothing noticeable. On the cloud disk they used 40% of the read budget, so the backfill started with little room left.

6.5 What this means for running Kafka

  • On cloud volumes, buy read headroom over the produce rate. A consumer that falls out of cache can catch up only as fast as the headroom allows. On real cloud volumes, writes count against the same budget, which this lab did not model.
  • Treat backfills as a risk to the whole broker, not just to the lagging consumer. Options include client quotas on the backfill, running it at off-peak times, fetching from a follower replica, or serving old data from tiered storage.
  • Watch refaults and broker disk reads. A rise in workingset_refault_file together with disk reads near the volume limit is the early warning. A lag-0 consumer slowing down during a backfill points to network-thread blocking. More network threads may help, but that was not tested here.

7. Assumptions and threats to validity

The largest caveats are that the cloud disk is an emulation, and that three runs are too few to estimate how often a cloud run collapses.

Assumption or limitation Effect on the results
The “cloud” disk is a local NVMe with a QEMU read throttle, not a real network-attached volume. Real cloud volumes add a network round trip to every read and have burst credits. Cold-read latency on real volumes is probably worse than shown here.
Writes were not throttled. Real gp3 and pd-balanced volumes share one budget between reads and writes, and Persistent Disk writes also count against the VM’s network egress. The cloud results are likely optimistic.
One host, one broker, one partition, replication factor 1. No replication traffic, no follower fetches, no partition skew. Production clusters spread load across many partitions and brokers.
The client is the warm-read bottleneck: about 650 MiB/s, one core decoding. Warm-cold ratios are relative to this client. A faster consumer would widen the NVMe gap.
Phase A was not a clean baseline: about 82% of tailD’s window was cached, and the broker read about 50 MiB/s from disk. Effects are measured against an already slightly stressed state. That understates the pollution effect on NVMe and makes the cloud runs more fragile.
Only MGLRU was tested, with 128 KiB readahead. The classic two-list LRU or a larger readahead might change residency and cold-read speed.
Three runs per condition. Enough for medians on NVMe, where runs agree closely. On the cloud disk, outcomes split between recovered and collapsed, and three runs cannot estimate how often each happens.
Broker request times come from Kafka’s JMX histograms, which decay over about 5 minutes. Short stalls show up only at p99.9, and not precisely. The network-thread idle metric read a constant 100% and was unusable.
The verdict thresholds (3 × MAD, 25%, a floor) are a choice. On the cloud disk, the bursty phase-A refault rate makes the refault test conservative. The individual numbers are reported alongside every verdict.

8. Conclusions

H1, cache hits are faster: supported. Reading 2 GiB from page cache took 3.2 s. From disk it took 4.1 s on NVMe and 16.4 s on the cloud disk. All seven runs showed the gap, with tight ranges.

H2, the gap depends on disk speed: supported. The cold/warm ratio was 1.29 on NVMe and 5.14 on the cloud disk. The ratio is set by whichever is slower, the consumer or the disk: about 650 MiB/s from cache, against 490 MiB/s from NVMe and 125 MiB/s from the cloud volume.

H3, a backfill pollutes the cache and hurts a slightly-lagging consumer: supported on NVMe; on the cloud disk the effect goes beyond the hypothesis.

  • NVMe: every run showed the predicted pattern. Refaults rose five to six times, the delayed consumer’s window residency fell by 18–25 points, and its p99 rose two to four times. The absolute cost stayed in tens of milliseconds, and the lag-0 control was barely touched. Three of six runs met all three formal criteria. The other three missed only the latency threshold.

  • Cloud disk: the delayed consumer’s median p99 rose from about 18 ms to 9.2 s (sequential) and 9.5 s (random); single runs ranged from 5.3 to 13.6 s. The damage did not stay with the delayed consumer as H3 assumed:

    • the lag-0 control’s median p99 rose to 1.9 s (sequential) and 6.5 s (random), and to 60–65 s in the two collapsed runs;
    • in two runs the system collapsed, with the producer cut to a third of its rate and no recovery within 5 minutes.

    The mechanism is a saturated read budget plus sendfile blocking shared network threads, more than eviction alone.

H4, TLS vs plaintext: not tested.

The practical conclusion: on fast local disks, Kafka’s reliance on the page cache is forgiving. On throttled cloud volumes, a single backfill can take down healthy consumers and slow the producer. Read headroom and backfill isolation matter more than cache size there.

9. Future work

  1. Real cloud disks. Repeat the same experiments on GCP, with real pd-balanced and pd-ssd volumes. The configuration and experiment layers are already platform-agnostic. On GCP the network becomes a variable: a 4-vCPU E2 broker has an 8 Gbit/s egress cap, and Persistent Disk writes count against it.
  2. A clean baseline. Shrink tailD’s delay until its window is about 100% cached in phase A, then rerun Exp 3 on both disks.
  3. Find the cloud tipping point. Step the produce rate down on the cloud disk until no run collapses. Run enough repetitions to estimate how often each produce rate collapses.
  4. Test the network-thread explanation. Rerun the cloud collapse case with more network threads (num.network.threads) and with a quota on the backfill client, and capture thread dumps during phase B.
  5. Throttle writes as well as reads, to match how cloud volumes actually budget I/O.
  6. MGLRU off, and readahead of 2 MiB. Check whether the classic LRU keeps more of the tail cached, and whether larger readahead speeds up cold reads on NVMe.
  7. TLS (H4). Repeat the ceiling and warm-vs-cold experiments over TLS, where sendfile is not available.

Appendix A: Reproducibility

The whole lab is automated. Ansible builds the VMs and configures the guests. kbench generates the load. Shell scripts run each experiment on the client inside tmux, and one Python script regenerates every table and figure from the raw CSVs. The code is at git.emincarbas.com/kafka-pagecache-lab. The tag pagecache-2026-11 is the exact state that produced these results. Clone it with git clone https://git.emincarbas.com/kafka-pagecache-lab.

ansible/       provisioning (Proxmox platform layer) and guest roles
kbench/        Go load generator (produce, consume, backfill, fill)
experiments/   lib.sh, residency.sh, exp0.sh to exp4.sh
analysis/      analyze.py
results/       raw CSVs and meta.json per run; summary/ is generated
make kbench                          # build the load generator
make provision configure             # VMs, Kafka, exporters, data disk
make throttle PROFILE=nvme           # or cloud, sata, hdd
make run EXP='exp0.sh; ./exp2.sh; ./exp3.sh'
make fetch-results analyze           # pull results, regenerate tables and plots

Every run directory holds a meta.json with the platform, disk profile, kernel, LRU mode, readahead, VM sizes, produce rate, consumer delay, backfill mode and phase timestamps. Raw run directories, with their meta.json and per-second CSVs, stay local and are not in the repository; only the generated summaries in results/summary/ are committed.

← All posts