Description
When multiple clients concurrently read the same key (e.g., thousands of GET requests on a hot key), performance degrades significantly.
Expected Behavior
Read commands should be able to execute concurrently on the same key without blocking each other. Only write commands need exclusive access.
Context
Root cause: The expireKeyIfNeeded function acquires a lock via the RdLock(), which always uses an LOCK_X(exclusive lock). This lock is acquired for all commands, including pure read-only commands like GET, HGET, LRANGE, ZRANGE, and TTL. Consequently, all operations on the same key are fully serialized, even though read operations do not modify any data.
The exclusive lock in expireKeyIfNeeded exists because it may synchronously delete expired keys. But for read commands, returning nil for expired keys is sufficient — deletion can be deferred.
IndexManager::scanExpiredKeysJob already provides background expired key cleanup as a safety net.
This bottleneck is most pronounced under high-concurrency hot key workloads.
Description
When multiple clients concurrently read the same key (e.g., thousands of GET requests on a hot key), performance degrades significantly.
Expected Behavior
Read commands should be able to execute concurrently on the same key without blocking each other. Only write commands need exclusive access.
Context
Root cause: The expireKeyIfNeeded function acquires a lock via the RdLock(), which always uses an LOCK_X(exclusive lock). This lock is acquired for all commands, including pure read-only commands like GET, HGET, LRANGE, ZRANGE, and TTL. Consequently, all operations on the same key are fully serialized, even though read operations do not modify any data.
The exclusive lock in expireKeyIfNeeded exists because it may synchronously delete expired keys. But for read commands, returning nil for expired keys is sufficient — deletion can be deferred.
IndexManager::scanExpiredKeysJob already provides background expired key cleanup as a safety net.
This bottleneck is most pronounced under high-concurrency hot key workloads.