What happens to a Redis-compatible cache when its data does not fit in memory, and the kernel compresses
the overflow (zram, zswap) or pages it to SSD (disk swap)? Valkey 9.2 with 40 GB and 64 GB of data on a 32 GB server,
lz4 and zstd at several levels, six workloads, measured with
kvbench.
Archived report (v1). Measured 2026-11-23 to 25 on a Vultr
bare-metal Intel Xeon E-2286G (6 cores, 32 GB RAM, SATA SSD) with the first benchmark protocol (one 2-minute window per point, all points
in a fixed order after one load, single-threaded Valkey). Kept for reference; see the current report for the rerun on newer hardware
with the revised protocol.
AI-generated results. This benchmark was designed, run and analyzed with an AI assistant (Claude).
Results were spot-checked by a person, but not every number and explanation has been verified in detail, and they may contain mistakes.
All code and raw data are published on GitHub; please
open an issue if you find a problem.
Key findings
Compressing values in the client beats every kernel option. With values compressed by the client (lz4 or zstd) before SET, 40 GB of data takes
9.5-11.8 GB in Valkey and 64 GB takes 14.5-18.2 GB, so everything fits in RAM: throughput and latency are the same as (slightly better than) the
uncompressed in-RAM run, at 1-5 µs more client CPU per operation. Details below.
Without changing the client, zram with lz4 is the best option tested. With 40 GB of data on 31 GB of RAM (about 30% of Valkey's memory compressed),
it costs 27% of throughput when every key is equally likely, 5-8% with skewed access and about nothing with a tight hot set.
At 64 GB (2x RAM) Valkey still delivers 57-96% of its in-RAM throughput.
zstd loses to lz4 at every level tried (3, 1, -1). It compresses Valkey's pages 7.5-8.4x instead of 4.6x and keeps
4-5 GB more of Valkey uncompressed, but that cuts page faults by only about 10% while each fault costs about twice as much CPU.
zswap matches zram, unless its shrinker is on. The shrinker (on by default in recent kernels) writes compressed pages to disk
under memory pressure even when the pool has room; at 2x RAM it cut zswap-zstd throughput by 70%. Details below.
Disk swap stalls Valkey's single thread on every page read: 11k ops/s at 40 GB and 5k at 64 GB with uniform access,
10-17x slower than zram with lz4.
Stores that keep data on SSD: Kvrocks with lz4 gets more throughput than Valkey with zram on uniform and zipfian access, but uses 4-7x more CPU per
operation and has higher tail latency; TidesKV is faster still but stalls for seconds at a time; Lavik is limited by this host's SATA SSDs. Details below.
Variable value sizes use 14% less memory than fixed 1 KiB values and, at the same memory size, cause about 25% fewer page faults.
Explore the results
The zswap shrinker
zswap is a compressed cache in front of a normal swap device. Pages the kernel swaps out are compressed into a RAM pool
instead of being written to disk, and read back from the pool without any disk I/O. Pages leave the pool for the disk only by writeback.
Shrinker off (shrinker_enabled=N): writeback happens only when the pool reaches
max_pool_percent of RAM. Until then everything stays compressed in RAM and zswap behaves like zram.
Shrinker on (Y, the default on this kernel): the pool takes part in memory reclaim like other caches.
Whenever memory is tight, zswap writes its coldest compressed pages to disk, even with the pool far below its limit. That helps when
swapped-out memory is really idle. In a cache the "cold" pages are still read, and memory stays tight as long as the data exceeds RAM, so
those pages become disk reads in Valkey's single thread.
For caches whose data exceeds RAM: use zram, or set zswap.shrinker_enabled=0.
64 GB of data, uniform access: throughput at full load
Same compressor, shrinker on (kernel default) vs off
Client-side compression instead of kernel compression
The application compresses each value before SET and decompresses it after GET (kvbench --client-compress); Valkey stores
the compressed bytes. Disk swap was enabled only as overflow and was never used: the compressed data fits in RAM.
Each value is compressed on its own, which loses ratio compared with the kernel compressing whole 4 KiB pages: 3.2x per value with lz4 (zram: 4.6x
on Valkey's pages) and 4.2x with zstd 3 (zram: 8.1x). It still wins by far, because all data is compressed and stays in RAM, instead of the overflow
being compressed and paged back on access.
Throughput is 2-6% above the uncompressed in-RAM run: Valkey moves ~300 bytes per value instead of 1 KiB. The client pays for it:
+1.0 µs per operation with lz4, +3.4 µs with zstd -1, +4.9 µs with zstd 3.
Trade-offs not measured here: values become opaque to the server (no APPEND, GETRANGE, INCR on them), every client must use the same codec, and
small or already-compressed values gain little.
Where the memory is
Valkey's memory at the end of the uniform full-load run: how much stays resident (uncompressed) and how much is swapped out,
with the compression ratio the kernel achieved on Valkey's real pages (bare values compress 3.8x with lz4 and 7.3x with zstd 3).
Fixed vs variable value sizes
Values uniformly distributed between 0 and 2000 bytes (mean ~1006 B) instead of a fixed 1024 B. The same 30M keys take 14% less memory
(jemalloc stores a 1 KiB value plus header in a 1280-byte slot); with 35M keys the variable data set matches the fixed one's memory.
Throughput in ops/s with page faults per operation.
Kvrocks, Lavik and TidesKV
The same data sets on stores that keep data on SSD and use RAM as a cache, on the same 6 server CPUs as Valkey:
Kvrocks 2.17 (RocksDB) with its shipped configuration (snappy) and with lz4 or zstd, Lavik 0.3.2 (values on SSD, key index in RAM),
and TidesKV 0.1.0 (TidesDB) with lz4 or zstd.
Kvrocks with lz4 compresses its files well enough that almost all of them stay in the page cache even at 64 GB (SSD reads 0-3 MB/s).
It reaches 114k ops/s with uniform access at 64 GB (Valkey with zram lz4: 84k) and 158k with zipfian (126k), but uses 38-52 µs of server CPU per operation
across its threads against 7-12 µs for Valkey, and its tail latency is higher: p99.9 0.6-0.9 ms at 50k ops/s with uniform access, against 0.24 ms.
With hot spots (hotspot, normal) Valkey with zram is faster. lz4 beats both the shipped snappy configuration and zstd everywhere.
Lavik reads every GET from the SSD and stops at 69-79k ops/s on this host's SATA SSDs, with p99 of tens of milliseconds at 50k ops/s.
It is designed for NVMe, so this host does not show it at its best.
TidesKV is the fastest store between stalls: 217k ops/s with uniform access at 40 GB with p99 0.3 ms, and 130-198k at 64 GB, at 26-42 µs of CPU per operation.
But in about half of the runs it stalls for 5-10 seconds: throughput drops to 1-13% of normal for all requests, then the backlog clears in a burst
(see the stall-seconds measure). It ran with sync-mode none because its default (interval) commits at about the disk's sync rate here
(~650 SET/s); none acknowledges a write before it leaves process memory, which is weaker durability than Kvrocks's default. TidesKV is pre-1.0.
Valkey with zram had no stalls in any run; disk swap and Lavik stall when they run out of I/O.
Non-default store settings: Kvrocks starts from its shipped kvrocks.conf with only bind/port/dir and workers 6 changed
(variants change rocksdb.compression); TidesKV defaults with bind/port/dir, workers 6 and sync-mode none
(zstd variant: compression zstd); Lavik defaults with --threads 6, --pin-workers on the server CPUs and a 300 GB data file.
Kvrocks and Lavik 40 GB results are from a rerun: the first run overlapped other work on the benchmark host.
How it was measured
Server: Vultr bare metal, Intel Xeon E-2286G (6 cores / 12 threads), 32 GB RAM (31 GB usable), 2x 960 GB SATA SSD,
Ubuntu 26.04, kernel 7.0, turbo off. This CPU runs with PTI/IBRS/MDS mitigations, so system calls are expensive; absolute numbers
will be higher on newer hardware.
Valkey 9.2.0, single main thread (default io-threads 1), no persistence, no maxmemory,
on CPUs 1-3,7-9. The client, kvbench (Rust), runs on CPUs 4,5,10,11:
4 threads x 16 connections, one request in flight per connection, over loopback TCP.
Data: integer keys; 1 KiB values with 10% random characters (or uniform 0-2000 B). 90% GET / 10% SET.
Workloads: full load with uniform, zipfian 0.99, hotspot (90% of operations on 10% of keys) and normal (standard deviation 5% of the key space)
key access; and a fixed 50k ops/s with uniform and zipfian access, where latency is measured from the scheduled send time.
Steady state: before every point the key distribution runs at full load until two 30-second chunks agree within 2%,
then 60 s warm-up and 120 s measured. Every run uses a fresh random request stream.
Noise: about 1% for throughput and p99, about ±15 µs for p99.9 at 50k ops/s (two runs of the in-RAM baseline).
Each configuration was run once.
Settings that are not defaults
Component
Setting
Valkey 9.2.0
--save "", --appendonly no, --protected-mode no (loopback only); everything else default
Host
vm.overcommit_memory=1, turbo off, performance governor, conntrack skipped for loopback
Disk swap
swap file on the second SSD (64 GB; 96 GB for the 64 GB data set), swappiness 60
zram
one device (64 / 96 GB), no disk swap, swappiness 180, page-cluster 0, watermark_boost_factor 0, watermark_scale_factor 125; zstd level via algorithm_params (default 3)
zswap
zsmalloc, max_pool_percent 50, same swap file as disk swap, swappiness 100, same three sysctls as zram; shrinker_enabled kernel default Y unless marked "shrinker off"