Skip to content

Commit

Permalink
make cache kind configureable
Browse files Browse the repository at this point in the history
  • Loading branch information
trinity-1686a committed Oct 2, 2024
1 parent 2dcc696 commit 59b25e7
Show file tree
Hide file tree
Showing 13 changed files with 183 additions and 163 deletions.
57 changes: 57 additions & 0 deletions quickwit/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions quickwit/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ matches = "0.1.9"
md5 = "0.7"
mime_guess = "2.0.4"
mockall = "0.11"
moka = { version = "0.12.8", features = ["sync"] }
mrecordlog = { git = "https://github.com/quickwit-oss/mrecordlog", rev = "306c0a7" }
new_string_template = "1.5.1"
nom = "7.1.3"
Expand Down
4 changes: 2 additions & 2 deletions quickwit/quickwit-config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ pub use crate::metastore_config::{
MetastoreBackend, MetastoreConfig, MetastoreConfigs, PostgresMetastoreConfig,
};
pub use crate::node_config::{
IndexerConfig, IngestApiConfig, JaegerConfig, NodeConfig, SearcherConfig, SplitCacheLimits,
DEFAULT_QW_CONFIG_PATH,
CacheKind, IndexerConfig, IngestApiConfig, JaegerConfig, NodeConfig, SearcherConfig,
SplitCacheLimits, DEFAULT_QW_CONFIG_PATH,
};
use crate::source_config::serialize::{SourceConfigV0_7, SourceConfigV0_8, VersionedSourceConfig};
pub use crate::storage_config::{
Expand Down
14 changes: 14 additions & 0 deletions quickwit/quickwit-config/src/node_config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,14 +206,25 @@ impl SplitCacheLimits {
}
}

#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize, Default)]
pub enum CacheKind {
// we make this the default to keep old behavior, it's tbd if lfu is a definitive improvement
#[default]
Lru,
Lfu,
}

#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
#[serde(deny_unknown_fields, default)]
pub struct SearcherConfig {
pub aggregation_memory_limit: ByteSize,
pub aggregation_bucket_limit: u32,
pub fast_field_cache_capacity: ByteSize,
pub fast_field_cache_kind: CacheKind,
pub split_footer_cache_capacity: ByteSize,
pub split_footer_cache_kind: CacheKind,
pub partial_request_cache_capacity: ByteSize,
pub partial_request_cache_kind: CacheKind,
pub max_num_concurrent_split_searches: usize,
pub max_num_concurrent_split_streams: usize,
// Strangely, if None, this will also have the effect of not forwarding
Expand All @@ -229,8 +240,11 @@ impl Default for SearcherConfig {
fn default() -> Self {
Self {
fast_field_cache_capacity: ByteSize::gb(1),
fast_field_cache_kind: CacheKind::default(),
split_footer_cache_capacity: ByteSize::mb(500),
split_footer_cache_kind: CacheKind::default(),
partial_request_cache_capacity: ByteSize::mb(64),
partial_request_cache_kind: CacheKind::default(),
max_num_concurrent_split_streams: 100,
max_num_concurrent_split_searches: 100,
aggregation_memory_limit: ByteSize::mb(500),
Expand Down
4 changes: 4 additions & 0 deletions quickwit/quickwit-config/src/node_config/serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,7 @@ mod tests {

use super::*;
use crate::storage_config::StorageBackendFlavor;
use crate::CacheKind;

fn get_config_filepath(config_filename: &str) -> String {
format!(
Expand Down Expand Up @@ -606,8 +607,11 @@ mod tests {
aggregation_memory_limit: ByteSize::gb(1),
aggregation_bucket_limit: 500_000,
fast_field_cache_capacity: ByteSize::gb(10),
fast_field_cache_kind: CacheKind::Lru,
split_footer_cache_capacity: ByteSize::gb(1),
split_footer_cache_kind: CacheKind::Lru,
partial_request_cache_capacity: ByteSize::mb(64),
partial_request_cache_kind: CacheKind::Lru,
max_num_concurrent_split_searches: 150,
max_num_concurrent_split_streams: 120,
split_cache: None,
Expand Down
9 changes: 6 additions & 3 deletions quickwit/quickwit-search/src/leaf_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use std::ops::Bound;

use prost::Message;
use quickwit_config::CacheKind;
use quickwit_proto::search::{
CountHits, LeafSearchResponse, SearchRequest, SplitIdAndFooterOffsets,
};
Expand Down Expand Up @@ -47,11 +48,12 @@ pub struct LeafSearchCache {
// queries which vary only by search_after.

impl LeafSearchCache {
pub fn new(capacity: usize) -> LeafSearchCache {
pub fn new(capacity: usize, cache_kind: CacheKind) -> LeafSearchCache {
LeafSearchCache {
content: MemorySizedCache::with_capacity_in_bytes(
capacity,
&quickwit_storage::STORAGE_METRICS.partial_request_cache,
cache_kind,
),
}
}
Expand Down Expand Up @@ -191,6 +193,7 @@ impl std::ops::RangeBounds<i64> for Range {

#[cfg(test)]
mod tests {
use quickwit_config::CacheKind;
use quickwit_proto::search::{
LeafSearchResponse, PartialHit, SearchRequest, SortValue, SplitIdAndFooterOffsets,
};
Expand All @@ -199,7 +202,7 @@ mod tests {

#[test]
fn test_leaf_search_cache_no_timestamp() {
let cache = LeafSearchCache::new(64_000_000);
let cache = LeafSearchCache::new(64_000_000, CacheKind::default());

let split_1 = SplitIdAndFooterOffsets {
split_id: "split_1".to_string(),
Expand Down Expand Up @@ -264,7 +267,7 @@ mod tests {

#[test]
fn test_leaf_search_cache_timestamp() {
let cache = LeafSearchCache::new(64_000_000);
let cache = LeafSearchCache::new(64_000_000, CacheKind::default());

let split_1 = SplitIdAndFooterOffsets {
split_id: "split_1".to_string(),
Expand Down
7 changes: 5 additions & 2 deletions quickwit/quickwit-search/src/list_fields_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

use quickwit_config::CacheKind;
use quickwit_proto::search::{
deserialize_split_fields, serialize_split_fields, ListFields, SplitIdAndFooterOffsets,
};
Expand All @@ -31,11 +32,12 @@ pub struct ListFieldsCache {
// TODO For now this simply caches the whole ListFieldsEntryResponse. We could
// be more clever and cache aggregates instead.
impl ListFieldsCache {
pub fn new(capacity: usize) -> ListFieldsCache {
pub fn new(capacity: usize, cache_kind: CacheKind) -> ListFieldsCache {
ListFieldsCache {
content: MemorySizedCache::with_capacity_in_bytes(
capacity,
&quickwit_storage::STORAGE_METRICS.partial_request_cache,
cache_kind,
),
}
}
Expand Down Expand Up @@ -71,6 +73,7 @@ impl CacheKey {

#[cfg(test)]
mod tests {
use quickwit_config::CacheKind;
use quickwit_proto::search::{
ListFieldType, ListFields, ListFieldsEntryResponse, SplitIdAndFooterOffsets,
};
Expand All @@ -79,7 +82,7 @@ mod tests {

#[test]
fn test_list_fields_cache() {
let cache = ListFieldsCache::new(64_000_000);
let cache = ListFieldsCache::new(64_000_000, CacheKind::default());

let split_1 = SplitIdAndFooterOffsets {
split_id: "split_1".to_string(),
Expand Down
18 changes: 13 additions & 5 deletions quickwit/quickwit-search/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -490,18 +490,26 @@ impl SearcherContext {
let global_split_footer_cache = MemorySizedCache::with_capacity_in_bytes(
capacity_in_bytes,
&quickwit_storage::STORAGE_METRICS.split_footer_cache,
searcher_config.split_footer_cache_kind.clone(),
);
let leaf_search_split_semaphore = Arc::new(Semaphore::new(
searcher_config.max_num_concurrent_split_searches,
));
let split_stream_semaphore =
Semaphore::new(searcher_config.max_num_concurrent_split_streams);
let fast_field_cache_capacity = searcher_config.fast_field_cache_capacity.as_u64() as usize;
let storage_long_term_cache = Arc::new(QuickwitCache::new(fast_field_cache_capacity));
let leaf_search_cache =
LeafSearchCache::new(searcher_config.partial_request_cache_capacity.as_u64() as usize);
let list_fields_cache =
ListFieldsCache::new(searcher_config.partial_request_cache_capacity.as_u64() as usize);
let storage_long_term_cache = Arc::new(QuickwitCache::new(
fast_field_cache_capacity,
searcher_config.fast_field_cache_kind.clone(),
));
let leaf_search_cache = LeafSearchCache::new(
searcher_config.partial_request_cache_capacity.as_u64() as usize,
searcher_config.partial_request_cache_kind.clone(),
);
let list_fields_cache = ListFieldsCache::new(
searcher_config.partial_request_cache_capacity.as_u64() as usize,
searcher_config.partial_request_cache_kind.clone(),
);
let aggregation_limit = AggregationLimitsGuard::new(
Some(searcher_config.aggregation_memory_limit.as_u64()),
Some(searcher_config.aggregation_bucket_limit),
Expand Down
1 change: 1 addition & 0 deletions quickwit/quickwit-storage/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ hyper = { workspace = true }
lru = { workspace = true }
md5 = { workspace = true }
mockall = { workspace = true, optional = true }
moka = { workspace = true }
once_cell = { workspace = true }
pin-project = { workspace = true }
rand = { workspace = true }
Expand Down
Loading

0 comments on commit 59b25e7

Please sign in to comment.