Lock-free fast path for buffer Pin/Unpin under concurrent readers#61
Open
krleonid wants to merge 3 commits into
Open
Lock-free fast path for buffer Pin/Unpin under concurrent readers#61krleonid wants to merge 3 commits into
krleonid wants to merge 3 commits into
Conversation
When a block is already loaded and has active readers (readers > 0), atomically increment/decrement readers via compare-and-swap without acquiring the per-block mutex. This eliminates mutex contention for the common case of hot blocks with multiple concurrent readers. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
cdcd392 to
5617e3b
Compare
…ntention Replace the exclusive mutex on the block registry with a platform-specific read-write lock. TryGetBlock and BlockIsRegistered acquire a read lock, allowing concurrent scans to look up block handles without serializing. RegisterBlock uses a fast read-lock check before falling back to a write lock for insertion. UnregisterBlock takes a write lock. Uses pthread_rwlock_t on POSIX and SRWLOCK on Windows. Platform headers are isolated in the .cpp file to avoid polluting the header namespace. RAII guards (ReadLockGuard/WriteLockGuard) ensure exception-safe unlock. Benchmark (20 DBs, 20 connections, 194-column table, 1000 rows/query): Before: 56.8 qps, 698.8ms avg latency After: 60.7 qps, 654.6ms avg latency (+6.9%) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
5617e3b to
a17746f
Compare
Log when Purge takes >1000ms or >10 iterations, reporting queue size, dead nodes before/after, and elapsed time. Helps diagnose buffer pool performance degradation in production. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
5015e1f to
4ef7a1c
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
readers > 0), atomically increment/decrement readers via compare-and-swap without acquiring the per-block mutex. Eliminates mutex contention for the common case of hot blocks with multiple concurrent readers.blocks_lock) withstd::shared_mutex.TryGetBlockandBlockIsRegisterednow acquire a shared (read) lock, allowing concurrent scans to look up block handles in parallel.RegisterBlockuses a fast shared-lock check before falling back to exclusive lock for insertion.Benchmark results
Lock-free Pin/Unpin (single table, SELECT * WHERE itemId IN <1000 ids>, 95K rows, 9284 segments)
shared_mutex on blocks_lock (multi-DB, 194-column table, SAMPLE 1000 rows)
Test plan
🤖 Generated with Claude Code