Repository navigation
Description
Summary
A heavy command on one connection makes every other connection wait for it to finish, even though KiviDB runs 6 worker threads. KEYS over 2M keys takes 148 ms, and a probe client's PING on a separate connection waits 140 ms. Deleting a 3M-field hash takes 116 ms; the probe waits 115 ms. KiviDB is faster than Redis on both commands, but it stalls other clients the same way. This was repeatable in every run, so it isn't the probe sharing a worker thread by chance (with 6 threads, that would happen about 1 time in 6).
The most common complaint we found across GitHub Redis-slowness issues is exactly this: one heavy command freezes everyone. That's the pain a multi-threaded Redis-compatible server is best placed to remove.
Numbers (2 fresh runs each)
| Redis 8.10.3: command / other client's worst PING | KiviDB 1.2.2: command / other client's worst PING | |
|---|---|---|
KEYS user:99* over 2M keys (11,111 matches) |
235–236 ms / 226–227 ms | 148 ms / 140 ms |
DEL of a 3M-field hash |
232–236 ms / 231–235 ms | 116 ms / 115 ms |
Repro
Load 2M keys user:N, then run KEYS user:99* while another connection PINGs every 1 ms. Record that connection's worst latency.
Real-world cases (each is one heavy command freezing everyone)
- perf: chat:completion re-emits the entire accumulated tool-call output on every round, so agentic sessions grow to tens of MB per Redis publish open-webui/open-webui#29833: a 45 MB
PUBLISHblocked Redis for 393–420 ms; 65 timeouts an hour across 1,057 clients. - [warm-reboot] apps crash due to redis is busy running 'tablue_dump.lua' during warm-start sonic-net/sonic-buildimage#3008 and #13561: a Lua dump (
KEYS+HGETALL) blocked Redis for 5 s, and BGP got BUSY during a warm reboot. - Redis Object Cache throws exception during BG save operation rhubarbgroup/redis-cache#537:
ZRANGEBYSCORE/ZREMRANGEBYSCOREon a huge sorted set took 12–22 s. - updateDelaySet may cause very high redis cpu usage OptimalBits/bull#1893:
EVALSHAover a multi-million delayed sorted set took 10,435 ms. - Bad performance when many keys in redis darkweak/souin#646: an
MGETof 2.9M keys took about 4 s and blocked allGETs. - Generic cache invalidation helper uses blocking Redis KEYS on a hot path stellarmarket-labs/stellar-market#1185, del() is causing production outages because it is O(N) cayasso/cacheman-redis#18 (
KEYSabout 1 s per call), and many more usingKEYSon a hot path.
Questions
- What does
KEYS(and a bigDEL) hold that aPINGon another connection needs: a global lock, every shard's lock, or a barrier?PINGtouches no data. - Could keyspace-wide reads walk the shards one at a time, releasing each, and could freeing a large value move to a background thread (Redis's
lazyfree)?
Environment
- KiviDB 1.2.2 (
kividb/kividb:v1.2.2, prebuilt image, default settings plus--port 6379 --protected-mode no) vs Redis 8.10.3 (redis:8,--save "" --appendonly no, default single-threaded I/O). - One server at a time on the same host: AWS CodeBuild, 8 vCPU, 15 GB, linux x86_64, Docker. The client is Python 3.12 with redis-py 5.2.1 in a container on the same host. Each server is started fresh for each run.
- The snippets above are the relevant parts of the harness.
Activity
fix(server): long KEYS, SCAN and DEL no longer hold up other connecti…
fix(server): keep the runtime's idle threads, and lazyfree-lazy-user-…
test(long_commands): run without lua-parallel-scripts, and check the …
Merge pull request #757 from kividbio/fix/heavy-command-stall
perf(store): grow a shard's table in steps, not in one stall (#752)
bench: 1.3.0 regression suite, part 1 (runner + SCAN, growth, give-ba…