-
Notifications
You must be signed in to change notification settings - Fork 582
Take into account key size for MemorySizedCache #6720
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,7 +19,7 @@ use quickwit_config::CacheConfig; | |
| use quickwit_proto::search::{ | ||
| CountHits, LeafResourceStats, LeafSearchResponse, SearchRequest, SplitIdAndFooterOffsets, | ||
| }; | ||
| use quickwit_storage::{MemorySizedCache, OwnedBytes}; | ||
| use quickwit_storage::{MemUsage, MemorySizedCache, OwnedBytes}; | ||
| use tantivy::index::SegmentId; | ||
|
|
||
| /// A cache to memoize `leaf_search_single_split` results. | ||
|
|
@@ -118,6 +118,14 @@ impl CacheKey { | |
| } | ||
| } | ||
|
|
||
| impl MemUsage for CacheKey { | ||
| fn heap_mem_usage(&self) -> usize { | ||
| // `SearchRequest` cannot easily implement `MemUsage`, but `encoded_len()` is a good proxy | ||
| // for its memory footprint. | ||
| self.split_id.heap_mem_usage() + self.request.encoded_len() | ||
|
Comment on lines
+123
to
+125
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
For searches spanning many indexes or containing many snippet fields, Useful? React with 👍 / 👎. |
||
| } | ||
| } | ||
|
|
||
| /// A (half-open) range bounded inclusively below and exclusively above [start..end). | ||
| #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] | ||
| struct HalfOpenRange { | ||
|
|
@@ -249,7 +257,45 @@ mod tests { | |
| SplitIdAndFooterOffsets, | ||
| }; | ||
|
|
||
| use super::LeafSearchCache; | ||
| use super::{CacheKey, LeafSearchCache, MemUsage}; | ||
|
|
||
| #[test] | ||
| fn test_cache_key_mem_usage_accounts_the_request() { | ||
| let split_info = SplitIdAndFooterOffsets { | ||
| split_id: "01H4V2E9K7XQZ8N3M5P6R7S8T9".to_string(), | ||
| split_footer_start: 0, | ||
| split_footer_end: 100, | ||
| timestamp_start: None, | ||
| timestamp_end: None, | ||
| num_docs: 0, | ||
| }; | ||
| let short_request = SearchRequest { | ||
| index_id_patterns: vec!["test-idx".to_string()], | ||
| query_ast: "short".to_string(), | ||
| max_hits: 10, | ||
| ..Default::default() | ||
| }; | ||
| let padding = "x".repeat(10_000); | ||
| let long_request = SearchRequest { | ||
| query_ast: format!("short{padding}"), | ||
| ..short_request.clone() | ||
| }; | ||
|
|
||
| let short_key = CacheKey::from_split_meta_and_request(split_info.clone(), short_request); | ||
| let long_key = CacheKey::from_split_meta_and_request(split_info, long_request); | ||
|
|
||
| // The split id and the request are both owned outside the struct itself. | ||
| assert!(short_key.mem_usage() > size_of::<CacheKey>()); | ||
| // A longer query AST is charged for, roughly byte for byte. `encoded_len` is a proxy, so | ||
| // only the order of magnitude is pinned here: the extra length must show up, and must not | ||
| // be wildly over-counted. | ||
| let delta = long_key.mem_usage() - short_key.mem_usage(); | ||
| assert!( | ||
| delta >= padding.len() && delta <= padding.len() + 16, | ||
| "a {} byte longer query AST grew the key by {delta} bytes", | ||
| padding.len() | ||
| ); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_leaf_search_cache_no_timestamp() { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does not bound total memory for
partial_request_cache_capacity:SearcherContext::newpasses the full configuration independently to bothLeafSearchCacheandListFieldsCache(quickwit-search/src/service.rslines 473–475), and each constructs its ownMemorySizedCache. On a node receiving both search and list-fields traffic, cached entries can therefore consume roughly twice the configured capacity even before cache metadata overhead, so this new guarantee is misleading unless the caches share a budget or the documentation explicitly describes the per-cache limit.Useful? React with 👍 / 👎.