[server] Lookups queue for seconds behind slow putKv requests in the shared request worker pool
Search before asking
- [x] I searched in the issues and found nothing similar.
Motivation
On Fluss 1.0.0, lookups and prefix lookups spend almost all their latency waiting in a request queue, not executing, even though most request workers are idle.
Each client connection is assigned to one worker, and each worker processes its queue one request at a time. A putKv holds the bucket's KV write lock while it reads the old value of every record from RocksDB (read-before-write). When the KV is much larger than the block cache these reads go to disk, so the worker serving a write-heavy connection is busy almost all the time, and every request queued behind it waits, including lookups from other clients.
Note: we see this under sustained heavy write load (a large backfill), not in steady state.
Observed (per tablet server, 5-minute windows, while Flink delta joins and CDC upserts run together, 24 worker threads):
| Request | Queue time p95 / p99 | Process time p95 / p99 |
|---|---|---|
prefixLookup |
2.1 s / 5.9 s | 7 / 12 ms |
lookup |
12.9 s / 20.8 s | 38 / 61 ms |
- The backlog sits on one or two workers: on one server, a single worker had 37–210 requests queued in every sample while 16–23 of the 24 queues were empty.
- Thread dumps show that worker in
putKv, reading old values from RocksDB, in 11 of 13 samples, while 14–23 of the 24 workers were idle. - The KV write lock spreads the blocking: a follower's replication fetch on another worker was blocked on the same bucket's lock (4 of 13 samples), stalling that worker's queue too.
- Raising
netty.server.num-worker-threadsfrom 8 to 24 didn't help: it adds workers, but a write-heavy connection is still tied to one of them. - Tablet CPU (0.1–0.5 of 4 cores) and disk (5–7k of 10k IOPS) are far from saturated.
- Lookup latency is set by the slowest write traffic sharing the worker. Lookup-heavy workloads (delta joins, lookup joins) stall while large writes run.
Related but different: #4057, #4767/#4768 and #4749 reduce KV lock contention, i.e. lookup processing time, which is already low here. This issue is about lookups waiting behind writes in the queue.
Solution
- Don't queue lookups behind the connection's writes: dispatch
lookupandprefixLookupto a separate read pool, or to any free worker. Lookups have no ordering requirement. Writes (putKv,produceLog) stay on their connection's worker, which idempotent writes with several in-flight batches per bucket rely on. - Shorten how long
putKvholds the KV write lock by batching the old-value reads into one MultiGet (#4063/#4065). This is complementary: it shortens the blocking, but without (1) any long-running write can still block reads queued behind it.
Replication traffic shares these queues with client traffic; isolating the internal listener (#4856/#4857) would keep follower fetches out of them. Per-worker busy time and per-request-type queue metrics would also make this easier to diagnose.
No response
Anything else?
No response
Willingness to contribute
- [x] I'm willing to submit a PR!
@wuchong @platinumhamburg before implementing anything, can you let me know your thoughts on this?
Hi @polyzos , Thanks for sharing the observations. I agree that connection-bound request queues can cause head-of-line blocking, and separating reads from writes is worth evaluating. A few thoughts:
-
The blocking model is fairly complex. Besides the long synchronous execution of
putKvandprefixLookup, lock contention is another major source of worker blocking. Separate pools can reduce queue interference, but they do not remove lock waits; blocked reads could still occupy the read pool. Longer term, I think we should look at fair request scheduling together with bucket affinity, while preserving the required write ordering. -
Could you share whether RocksDB shared memory is enabled, along with the block-cache and index/filter settings? Given the reported lookup latency, I would check cache pressure as well. If shared memory is enabled, I would strongly recommend enabling partitioned indexes/filters and ensuring the shared block cache is adequately sized. Keeping index/filter blocks outside the shared block cache is another option, provided their memory is budgeted separately. This is a diagnostic hypothesis; the current observations do not establish cache configuration as the cause.
-
I have also been working on related optimizations that may complement this:
- #4065: Batch old-value reads in the write path to reduce repeated RocksDB/JNI calls while holding the KV write lock.
- #4768: Execute larger MultiGet batches outside the KV lock using snapshot read views.
- #4929: Enable prefix Bloom filtering for compatible KV tables, allowing prefix lookups to skip irrelevant SSTs.
These PRs are still open. The related prefix-lookup lock reduction in #4749 has already merged..
-
For read/write pool separation, could we run a controlled production trial to quantify the benefit? Comparing queue time, processing time, lookup tail latency, and write throughput under comparable load would help, ideally keeping the total worker budget unchanged and distinguishing same-bucket contention from unrelated-bucket traffic. Also,
lookupwithinsertIfNotExistshas write semantics and should be classified as a write request.
Thanks @platinumhamburg, this is helpful. 👍
RocksDB config (1.0.0), per tablet server: shared block cache enabled, 3 GB; shared write buffer 1 GB; cache-index-and-filter-blocks: true with high priority and the block size is 4 KB.
The shared block cache is at 100% (3.21 / 3.22 GB, 0 pinned), with roughly 230 GB of KV per server. RocksDB get p99 is 6–20 ms on the large tables, vs ~1–2 ms on recently written ones. So a cache miss likely costs several reads (index/filter, then data).
That would explain why each putKv holds the worker and the lock for so long, so it makes the queueing worse without being its cause.
I'm running various experiments to better to fully understand different cases and scenarios - we may as well just scale the number of buckets and number of TS. - I just want to track this because long-term it might end up being a pretty useful improvement.
Fair scheduling with bucket affinity sounds like a great long-term direction 👍
6. Thanks @platinumhamburg, this is helpful. 👍 RocksDB config (1.0.0), per tablet server: shared block cache enabled, 3 GB; shared write buffer 1 GB;
cache-index-and-filter-blocks: truewith high priority and the block size is 4 KB. The shared block cache is at 100% (3.21 / 3.22 GB, 0 pinned), with roughly 230 GB of KV per server. RocksDB get p99 is 6–20 ms on the large tables, vs ~1–2 ms on recently written ones. So a cache miss likely costs several reads (index/filter, then data). That would explain why eachputKvholds the worker and the lock for so long, so it makes the queueing worse without being its cause. I'm running various experiments to better to fully understand different cases and scenarios - we may as well just scale the number of buckets and number of TS. - I just want to track this because long-term it might end up being a pretty useful improvement. Fair scheduling with bucket affinity sounds like a great long-term direction 👍
Hi @polyzos, thanks for sharing the details. With roughly 230 GB of KV data per TS and a 3 GB shared block cache, I strongly suspect index/filter cache churn contributes significantly to the latency. Metadata misses introduce additional block reads, I/O, and decompression, extending worker occupancy and lock hold times.
I strongly recommend trying partitioned indexes/filters from #4612:
kv.rocksdb.block.partitioned-index-filters: true
This takes effect when opening a RocksDB instance. Existing SSTs gradually adopt partitioned metadata as compaction rewrites them, which should improve cache efficiency if metadata churn is the bottleneck.
#4612 may not be included in your 1.0 build, so please check your version. If convenient, you could test main, or cherry-pick the recent primary-key table optimizations onto 1.0 and build a test image.
I also strongly recommend testing #4857 with separate internal and external listeners. It isolates replication and control traffic from client queues and backpressure. In our heavy mixed write and Delta Join workload, it substantially reduced ISR instability and brought putKv processing p99 down from seconds to milliseconds. It would be useful to see whether your workload benefits similarly.
Another case from the same cluster (1.0.0, 3 tablet servers, netty.server.num-worker-threads: 24): a partial-update bootstrap into a new primary-key table with 16 buckets.
This time the block cache is not the cause: RocksDB gets on the target table take under 1 ms, writes at most ~90 ms, and there are no write stalls. Even so, putKv requests wait behind each other on the same bucket:
| Tablet | putKv p50 total | p99 queue | p99 process | p99 total |
|---|---|---|---|---|
| ts-0 | 207 ms | 16.4 s | 8.7 s | 25.8 s |
| ts-1 | 264 ms | 30.8 s | 13.1 s | 41.4 s |
| ts-2 | 314 ms | 32.4 s | 9.3 s | 36.6 s |
Tablet CPU stays at 0.3–0.6 cores. Two Flink writers feed each bucket, each with up to 5 requests in flight. KvTablet.putAsLeader holds the bucket's kvLock write lock for the whole batch, so the requests behind it block their worker threads while they wait. Other tables on the same tablets slowed down too: a delta join's lookups and ingestion jobs timed out during the bootstrap.
So a slow putKv doesn't only delay lookups; same-bucket writes park worker threads as well. A fix that stops a worker from blocking on a busy bucket (for example a per-bucket queue with one batch in flight and the rest parked without a thread) would cover both cases. Shortening the lock itself is proposed in #5232, and a lock-wait metric in #5233.
Hi @polyzos, thanks for sharing this additional case, especially the impact of the bootstrap on other tables. I have been thinking about improvements along several related axes: synchronous processing performance, backpressure, and bucket affinity and request scheduling. Your observations provide a useful case for this broader work.
First, we need better visibility into synchronous processing. Currently, requestProcessTimeMs covers both synchronous execution and asynchronous stages such as waiting for replication acknowledgements. Measuring these separately will help identify what occupies the request workers. I am addressing this in #4845 by adding synchronous processing duration and cumulative worker occupancy by request type. Together with the lock-wait and lock-hold metrics proposed in #5233, this should help us understand the synchronous cost of each request type and the contribution of lock contention.
-
Synchronous processing performance. The cache, partitioned index/filter, prefix Bloom, and MultiGet optimizations discussed earlier all aim to reduce synchronous processing cost, worker occupancy, and lock hold times. We have made progress here, and I am continuing to think about further improvements. For this partial-update bootstrap, measuring the batch-level costs of reads, merging, state updates, and WAL construction would help explain where the processing time goes.
-
Backpressure. Connections are currently hashed to fixed request queues. When one queue becomes congested, connections sharing that queue experience queueing delays and backpressure together, while other workers may remain idle. One direction I have been considering is rebalancing affected connections onto idle queues to improve worker utilization and contain the impact of congestion. This would require a clear handoff mechanism that preserves request ordering during migration.
-
Bucket affinity and request scheduling. I think this may be the central architectural issue. The client aggregates multiple buckets of the same table into one RPC to a TS, while the server assigns workers by connection. One RPC therefore processes several buckets sequentially, while requests for the same bucket can arrive on different workers and converge on its lock. This allows contention on one bucket to spread across workers and affect other requests in their queues. Log appends have a relatively simple execution path; KV read-before-write and merge operations make these limitations more pronounced.
A direction I have been exploring is bucket-affine execution: each bucket’s reads and writes are processed serially within the same execution context, pending requests wait in a queue, and workers remain available to serve other buckets. This could substantially reduce request-side lock contention. Multiple buckets could share a bounded worker pool, with fair scheduling between them.
This calls for a broader design of how request batching interacts with bucket scheduling: whether to change client batching or retain multi-bucket RPCs and dispatch their work separately on the server. We would also need to address write ordering, idempotence, asynchronous response aggregation, and coordination with background operations.
I am considering bringing these ideas together in a future FIP for community discussion. A POC and thorough performance testing would be essential, comparing write throughput, worker occupancy, queueing time, and unrelated tables’ tail latency under the same thread and resource budgets. Your bootstrap scenario would be a valuable workload for that evaluation.
Hi @polyzos, following up on the performance issues you reported, I see two separate scheduling problems in the TabletServer RPC path:
- Connection scheduling and fair backpressure. Fixed connection assignments can leave one worker with a backlog while others sit idle. When backpressure is applied at the worker level, lightly loaded connections assigned to that worker can also have their reads paused.
- RPC scheduling when bucket accesses conflict. When RPCs access overlapping buckets, the choice of which requests run concurrently and which go first affects worker wait time, throughput, and tail latency.
I opened a draft PR to address the first problem. It lets idle workers take over ready connections within the same listener resource group and gives connections fair access to the group’s shared request quota. In controlled benchmarks on a local test cluster, I saw clear gains under skewed connection load, sustained Fluss and Kafka backpressure, and workloads mixing long prefix lookups with writes to the same bucket. Draft PR #5384
I’d like to test this with you on a workload representative of what you see in practice. The partial-update bootstrap you described, with lookups and writes on other tables running alongside it, seems like a good starting point. Would you be interested in comparing main and the draft PR together to see whether the gains carry over?