From 09aac33b9d68954f7938b7e1411005f2c16bec18 Mon Sep 17 00:00:00 2001 From: "Lei, HUANG" Date: Thu, 25 Jul 2024 17:52:05 +0800 Subject: [PATCH 1/5] Add dynamic cache size adjustment for InvertedIndexConfig --- src/mito2/src/config.rs | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/mito2/src/config.rs b/src/mito2/src/config.rs index 012c31aaad00..7fd87d774f6e 100644 --- a/src/mito2/src/config.rs +++ b/src/mito2/src/config.rs @@ -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 } } From a120f4b59b01a0c197b64ac1a80cef729e3b7054 Mon Sep 17 00:00:00 2001 From: "Lei, HUANG" Date: Thu, 25 Jul 2024 19:40:12 +0800 Subject: [PATCH 2/5] Increase cache sizes in integration tests for HTTP - Updated `metadata_cache_size` from 32MiB to 64MiB --- tests-integration/tests/http.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests-integration/tests/http.rs b/tests-integration/tests/http.rs index 75939b7c9485..b3dbe96a3366 100644 --- a/tests-integration/tests/http.rs +++ b/tests-integration/tests/http.rs @@ -839,8 +839,8 @@ 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" +metadata_cache_size = "64MiB" +content_cache_size = "128MiB" [region_engine.mito.fulltext_index] create_on_flush = "auto" From c6e8165b61160ce5ac4bb4cfec9d79959178aff1 Mon Sep 17 00:00:00 2001 From: "Lei, HUANG" Date: Fri, 26 Jul 2024 11:04:51 +0800 Subject: [PATCH 3/5] Remove cache size settings from config and update drop_lines_with_inconsistent_results function to handle them --- tests-integration/tests/http.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests-integration/tests/http.rs b/tests-integration/tests/http.rs index b3dbe96a3366..38c87d865dd4 100644 --- a/tests-integration/tests/http.rs +++ b/tests-integration/tests/http.rs @@ -839,8 +839,6 @@ create_on_flush = "auto" create_on_compaction = "auto" apply_on_query = "auto" mem_threshold_on_create = "auto" -metadata_cache_size = "64MiB" -content_cache_size = "128MiB" [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 From 98d8aa9b5896661a7212470353c6e4d09ac66932 Mon Sep 17 00:00:00 2001 From: "Lei, HUANG" Date: Fri, 26 Jul 2024 11:07:04 +0800 Subject: [PATCH 4/5] 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. --- config/standalone.example.toml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/config/standalone.example.toml b/config/standalone.example.toml index 0944d5985e80..7d40927703fe 100644 --- a/config/standalone.example.toml +++ b/config/standalone.example.toml @@ -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] From e7572c3a86c008b18e03468fb7f057c06367ef8e Mon Sep 17 00:00:00 2001 From: "Lei, HUANG" Date: Fri, 26 Jul 2024 03:17:50 +0000 Subject: [PATCH 5/5] chore/index-content-cache-default-size: Add cache size configuration options for Mito engine's inverted index --- config/config.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/config/config.md b/config/config.md index 14f22f5b6c9a..7f48597737d3 100644 --- a/config/config.md +++ b/config/config.md @@ -129,6 +129,8 @@ | `region_engine.mito.inverted_index.apply_on_query` | String | `auto` | Whether to apply the index on query
- `auto`: automatically (default)
- `disable`: never | | `region_engine.mito.inverted_index.mem_threshold_on_create` | String | `auto` | Memory threshold for performing an external sort during index creation.
- `auto`: automatically determine the threshold based on the system memory size (default)
- `unlimited`: no memory limit
- `[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.
- `auto`: automatically (default)
- `disable`: never | | `region_engine.mito.fulltext_index.create_on_compaction` | String | `auto` | Whether to create the index on compaction.
- `auto`: automatically (default)
- `disable`: never |