Skip to content

Commit

Permalink
chore: add dynamic cache size adjustment for InvertedIndexConfig (#4433)
Browse files Browse the repository at this point in the history
* Add dynamic cache size adjustment for InvertedIndexConfig

* Increase cache sizes in integration tests for HTTP

 - Updated `metadata_cache_size` from 32MiB to 64MiB

* Remove cache size settings from config and update drop_lines_with_inconsistent_results function to handle them

* Add cache size configurations for inverted index metadata and content

 - Introduced `metadata_cache_size` with a default of 64MiB.
 - Introduced `content_cache_size` with a default of 128MiB.

* chore/index-content-cache-default-size: Add cache size configuration options for Mito engine's inverted index
v0y4g3r authored Jul 26, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent b81d3a2 commit bdd3d2d
Showing 4 changed files with 31 additions and 5 deletions.
2 changes: 2 additions & 0 deletions config/config.md
Original file line number Diff line number Diff line change
@@ -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 |
6 changes: 6 additions & 0 deletions config/standalone.example.toml
Original file line number Diff line number Diff line change
@@ -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]

24 changes: 21 additions & 3 deletions src/mito2/src/config.rs
Original file line number Diff line number Diff line change
@@ -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
@@ -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),
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
}
}

4 changes: 2 additions & 2 deletions tests-integration/tests/http.rs
Original file line number Diff line number Diff line change
@@ -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"
@@ -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

0 comments on commit bdd3d2d

Please sign in to comment.