Skip to content
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

chore: add dynamic cache size adjustment for InvertedIndexConfig #4433

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions config/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@
| `region_engine.mito.inverted_index.apply_on_query` | String | `auto` | Whether to apply the index on query<br/>- `auto`: automatically (default)<br/>- `disable`: never |
| `region_engine.mito.inverted_index.mem_threshold_on_create` | String | `auto` | Memory threshold for performing an external sort during index creation.<br/>- `auto`: automatically determine the threshold based on the system memory size (default)<br/>- `unlimited`: no memory limit<br/>- `[size]` e.g. `64MB`: fixed memory threshold |
| `region_engine.mito.inverted_index.intermediate_path` | String | `""` | Deprecated, use `region_engine.mito.index.aux_path` instead. |
| `region_engine.mito.inverted_index.metadata_cache_size` | String | `64MiB` | Cache size for inverted index metadata. |
| `region_engine.mito.inverted_index.content_cache_size` | String | `128MiB` | Cache size for inverted index content. |
| `region_engine.mito.fulltext_index` | -- | -- | The options for full-text index in Mito engine. |
| `region_engine.mito.fulltext_index.create_on_flush` | String | `auto` | Whether to create the index on flush.<br/>- `auto`: automatically (default)<br/>- `disable`: never |
| `region_engine.mito.fulltext_index.create_on_compaction` | String | `auto` | Whether to create the index on compaction.<br/>- `auto`: automatically (default)<br/>- `disable`: never |
Expand Down
6 changes: 6 additions & 0 deletions config/standalone.example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,12 @@ mem_threshold_on_create = "auto"
## Deprecated, use `region_engine.mito.index.aux_path` instead.
intermediate_path = ""

## Cache size for inverted index metadata.
metadata_cache_size = "64MiB"

## Cache size for inverted index content.
content_cache_size = "128MiB"

## The options for full-text index in Mito engine.
[region_engine.mito.fulltext_index]

Expand Down
24 changes: 21 additions & 3 deletions src/mito2/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ const DEFAULT_SCAN_CHANNEL_SIZE: usize = 32;
const GLOBAL_WRITE_BUFFER_SIZE_FACTOR: u64 = 8;
/// Use `1/SST_META_CACHE_SIZE_FACTOR` of OS memory size as SST meta cache size in default mode
const SST_META_CACHE_SIZE_FACTOR: u64 = 32;
/// Use `1/INDEX_CONTENT_CACHE_SIZE_FACTOR` of OS memory size for inverted index file content cache by default.
const INDEX_CONTENT_CACHE_SIZE_FACTOR: u64 = 32;
/// Use `1/MEM_CACHE_SIZE_FACTOR` of OS memory size as mem cache size in default mode
const MEM_CACHE_SIZE_FACTOR: u64 = 16;
/// Use `1/INDEX_CREATE_MEM_THRESHOLD_FACTOR` of OS memory size as mem threshold for creating index
Expand Down Expand Up @@ -389,19 +391,35 @@ pub struct InvertedIndexConfig {
pub content_cache_size: ReadableSize,
}

impl InvertedIndexConfig {
/// Adjusts the cache size of [InvertedIndexConfig] according to system memory size.
fn adjust_cache_size(&mut self, sys_memory: ReadableSize) {
let content_cache_size = cmp::min(
sys_memory / INDEX_CONTENT_CACHE_SIZE_FACTOR,
ReadableSize::mb(128),
);
self.content_cache_size = content_cache_size;
}
}

impl Default for InvertedIndexConfig {
#[allow(deprecated)]
fn default() -> Self {
Self {
let mut index_config = Self {
create_on_flush: Mode::Auto,
create_on_compaction: Mode::Auto,
apply_on_query: Mode::Auto,
mem_threshold_on_create: MemoryThreshold::Auto,
write_buffer_size: ReadableSize::mb(8),
intermediate_path: String::new(),
metadata_cache_size: ReadableSize::mb(32),
content_cache_size: ReadableSize::mb(32),
metadata_cache_size: ReadableSize::mb(64),
v0y4g3r marked this conversation as resolved.
Show resolved Hide resolved
content_cache_size: ReadableSize::mb(128),
};

if let Some(sys_memory) = common_config::utils::get_sys_total_memory() {
index_config.adjust_cache_size(sys_memory);
}
index_config
}
}

Expand Down
4 changes: 2 additions & 2 deletions tests-integration/tests/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -839,8 +839,6 @@ create_on_flush = "auto"
create_on_compaction = "auto"
apply_on_query = "auto"
mem_threshold_on_create = "auto"
metadata_cache_size = "32MiB"
content_cache_size = "32MiB"

[region_engine.mito.fulltext_index]
create_on_flush = "auto"
Expand Down Expand Up @@ -889,6 +887,8 @@ fn drop_lines_with_inconsistent_results(input: String) -> String {
"vector_cache_size =",
"page_cache_size =",
"selector_result_cache_size =",
"metadata_cache_size =",
"content_cache_size =",
];

input
Expand Down
Loading