[DocDB] Concurrent sys-catalog reads on yb-master collapse into a lock convoy on the RocksDB block cache shard mutexes
Jira Link: DB-23709
Description
Under a burst of concurrent sys-catalog reads, yb-master throughput collapses below its uncontended rate and stays there, with per-read latency of 1-4 s, until the read load goes away. The threads are not doing work; they are asleep on the RocksDB block cache shard mutexes.
Observed (v2025.2.5.2)
Cluster with hundreds of TServers, tens of thousands of PG backends, and a
96-core master leader. A migration issued 13 DDL statements about 5-7 s apart
(13 catalog version bumps in 78 s, each carrying 120-576 invalidation messages).
Every backend re-read catalog rows from the master, every TServer refetched
table schemas, and every new connection ran a full relcache preload. The
master saw 2,000-3,500 RPCs in flight for ~5 minutes, >97% of them
TabletServerService.Read on the sys catalog tablet, from ~160 distinct
TServers at 15-25 each.
rpc_workers_limit was 4096 on the master, so every request got a worker.
threadz at the peak: 4,330 threads, of which ~1,840 were asleep in
rocksdb::ShardedLRUCache::Lookup() / ::Release() under
BlockBasedTable::GetBlockFromCache, ~1,100 more in
LongOperationTracker::LongOperationTracker() (#33252), and 7-30 executing
RocksDB/DocDB code at any sampled instant.
Throughput served: 2-3.5k reads/s, vs ~4.2k/s at baseline with ~20 threads. Per-read latency: p50 1.5-1.9 s, p99 2-8 s, max 9.5 s, flat for the whole storm. Little's law on in-flight / throughput reproduces the plateau.
Host CPU at the peak (node_exporter, 1-minute bucket): all 96 cores >90% busy, 84 cores system time, 11 cores user time, ~256k context switches/s, scheduler run-queue wait ~1,900 runnable-seconds/second. At baseline the master served 4.2k reads/s on ~2 user cores, so compute was not the limit; 16 user cores could have served >30k/s.
Nothing else was happening on the master's storage: no compaction, no flush, and no decompression or file-read frame in ~700 sampled read stacks. The block cache was hot.
Single-DDL invalidation waves on the same cluster show the same signature at smaller scale (~45 cores of system time, 130-170 reads in flight, 136 threads on the LRU mutex) and clear within a minute.
Mechanism
- The sys catalog is one tablet, one RocksDB instance, one block cache (128
shards here:
db_block_cache_num_shard_bitsauto = ceil(log2(96))). cache_index_and_filter_blocks=true, so every seek goes through the block cache for the per-file index reader and the lower-level index block before it reaches a data block. yb-master hard-codesuse_docdb_aware_bloom_filter=false(master_main.cc), so no SST file can be skipped: every read touches every file's index handles. With 3-4 SST files that is ~18-24 Lookup/Release pairs per read, and the index handles are the same for every reader regardless of which rows it wants. A block's shard is fixed by the hash of its key, so adding shards does not spread this load.- Each shard is a
port::Mutex: a plain non-adaptive pthread mutex. A contended acquire sleeps infutex_wait; unlock doesfutex_wake(1)with no handoff, so the woken thread must be scheduled and win a race against running threads, or sleep again. Once anyone is waiting, every acquisition on that shard costs a sleep/wake round trip whose latency includes the run-queue wait, tens of milliseconds when ~1,900 threads are runnable. - With thousands of worker threads each holding a read open, the hot shards are never uncontended, so the master's read throughput is bounded by mutex handoff rate, not by cores or by the nanoseconds the critical section takes, and the futex traffic itself saturates the machine in kernel mode.
The per-shard concentration and the kernel-side cost are inferred from the stacks, the code path, and the host CPU split; they were not measured with per-shard lock statistics or a kernel profile.
- #34359
- #34360
- #34361
- #34361
Issue Type
kind/bug
Warning: Please confirm that this issue does not contain any sensitive information
- I confirm this issue does not contain any sensitive information.
Source: yugabyte/yugabyte-db