branch-4.1: [improvement](be) Add stampede protection for AnnIndexIVFListCache #62442#62567
Merged
yiguolei merged 1 commit intobranch-4.1from Apr 16, 2026
Merged
Conversation
…62442) ## Summary - Add double-check locking pattern to `CachedRandomAccessReader::borrow()` to prevent concurrent threads from redundantly reading the same IVF list data from disk (cache stampede) - Eliminate ghost memory caused by LRU cache entry replacement under high concurrency, reducing usage ratio fluctuations - Zero overhead on the fast path (cache hit); reuses the existing `_io_mutex` without introducing new synchronization primitives ## Proposed Changes When multiple threads concurrently miss the `AnnIndexIVFListCache` for the same key, they all independently read the same data from disk and insert it into the cache. The LRU cache silently replaces duplicate entries (counted as "stampede"), causing: 1. **Redundant disk I/O**: N concurrent misses produce N identical reads instead of 1 2. **Ghost memory**: replaced entries whose handles are still pinned consume memory not tracked by cache `_usage`, leading to usage ratio fluctuations (observed 87%→50% under high concurrency) 3. **Lower cache hit ratio**: unnecessary evictions caused by inflated insertion volume The fix leverages the existing `_io_mutex` (required because CLucene `IndexInput` is stateful) by moving its acquisition before the disk read and adding a cache re-check after acquiring the lock. If a preceding thread already loaded the same key, subsequent threads skip the disk I/O entirely. ### What problem does this PR solve? Problem Summary: Under high concurrency (e.g., vectordb_bench with 10-90 concurrent threads), the AnnIndexIVFListCache exhibits excessive stampede events, redundant disk I/O, and usage ratio fluctuations due to the TOCTOU gap between cache lookup and insert. ### Release note Reduced redundant disk I/O and memory waste for IVF on-disk vector index cache under concurrent queries by adding stampede protection (double-check locking pattern) to CachedRandomAccessReader::borrow(). ### Check List (For Author) - Test: Manual test with vectordb_bench concurrency benchmark - Behavior changed: No - Does this need documentation: No
Contributor
|
Thank you for your contribution to Apache Doris. Please clearly describe your PR:
|
Contributor
|
run buildall |
Contributor
BE UT Coverage ReportIncrement line coverage Increment coverage report
|
Contributor
BE Regression && UT Coverage ReportIncrement line coverage Increment coverage report
|
yiguolei
approved these changes
Apr 16, 2026
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.
Cherry-picked from #62442