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

feat: add a new ratio config instead of table_data_deserialized_data_bytes #14896

Merged
merged 4 commits into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
12 changes: 6 additions & 6 deletions src/query/config/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2803,18 +2803,18 @@ pub struct CacheConfig {
#[serde(rename = "disk")]
pub disk_cache_config: DiskCacheConfig,

/// Max size of in memory table column object cache. By default it is 0 (disabled)
/// Max percentage of in memory table column object cache relative to whole memory. By default it is 0 (disabled)
///
/// CAUTION: The cached items are deserialized table column objects, may take a lot of memory.
/// CAUTION: The cached items are deserialized table column objects, ma take a lot of memory.
chienguo marked this conversation as resolved.
Show resolved Hide resolved
///
/// Only if query nodes have plenty of un-utilized memory, the working set can be fitted into,
/// and the access pattern will benefit from caching, consider enabled this cache.
#[clap(
long = "cache-table-data-deserialized-data-bytes",
long = "cache-table-data-deserialized-memory-ratio",
value_name = "VALUE",
default_value = "0"
)]
pub table_data_deserialized_data_bytes: u64,
pub table_data_deserialized_memory_ratio: u64,

// ----- the following options/args are all deprecated ----
/// Max number of cached table segment
Expand Down Expand Up @@ -2946,7 +2946,7 @@ mod cache_config_converters {
table_data_cache_population_queue_size: value
.table_data_cache_population_queue_size,
disk_cache_config: value.disk_cache_config.try_into()?,
table_data_deserialized_data_bytes: value.table_data_deserialized_data_bytes,
table_data_deserialized_memory_ratio: value.table_data_deserialized_memory_ratio,
})
}
}
Expand All @@ -2967,7 +2967,7 @@ mod cache_config_converters {
table_data_cache_population_queue_size: value
.table_data_cache_population_queue_size,
disk_cache_config: value.disk_cache_config.into(),
table_data_deserialized_data_bytes: value.table_data_deserialized_data_bytes,
table_data_deserialized_memory_ratio: value.table_data_deserialized_memory_ratio,
table_meta_segment_count: None,
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/query/config/src/inner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -557,13 +557,13 @@ pub struct CacheConfig {
/// Storage that hold the raw data caches
pub disk_cache_config: DiskCacheConfig,

/// Max size of in memory table column object cache. By default it is 0 (disabled)
/// Max percentage of in memory table column object cache relative to whole memory. By default it is 0 (disabled)
///
/// CAUTION: The cache items are deserialized table column objects, may take a lot of memory.
/// CAUTION: The cached items are deserialized table column objects, ma take a lot of memory.
chienguo marked this conversation as resolved.
Show resolved Hide resolved
///
/// Only if query nodes have plenty of un-utilized memory, the working set can be fitted into,
/// and the access pattern will benefit from caching, consider enabled this cache.
pub table_data_deserialized_data_bytes: u64,
pub table_data_deserialized_memory_ratio: u64,
}

#[derive(Clone, Debug, PartialEq, Eq)]
Expand Down Expand Up @@ -621,7 +621,7 @@ impl Default for CacheConfig {
data_cache_storage: Default::default(),
table_data_cache_population_queue_size: 0,
disk_cache_config: Default::default(),
table_data_deserialized_data_bytes: 0,
table_data_deserialized_memory_ratio: 0,
}
}
}
6 changes: 5 additions & 1 deletion src/query/service/src/global_services.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,11 @@ impl GlobalServices {
&config.query.share_endpoint_auth_token_file,
config.query.tenant_id.to_string(),
)?;
CacheManager::init(&config.cache, config.query.tenant_id.to_string())?;
CacheManager::init(
&config.cache,
&config.query.max_server_memory_usage,
config.query.tenant_id.to_string(),
)?;

if let Some(addr) = config.query.cloud_control_grpc_server_address.clone() {
CloudControlApiProvider::init(addr, config.query.cloud_control_grpc_timeout).await?;
Expand Down
2 changes: 1 addition & 1 deletion src/query/service/tests/it/storages/fuse/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ async fn test_array_cache_of_nested_column_iusse_14502() -> Result<()> {

let mut config = InnerConfig::default();
// memory cache is not enabled by default, let's enable it
config.cache.table_data_deserialized_data_bytes = 1024 * 1024 * 10;
config.cache.table_data_deserialized_memory_ratio = 10;
let fixture = TestFixture::setup_with_config(&config).await?;

fixture.create_default_database().await?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ DB.Table: 'system'.'configs', Table: configs-table_id:1, ver:0, Engine: SystemCo
| 'cache' | 'table_bloom_index_filter_size' | '2147483648' | '' |
| 'cache' | 'table_bloom_index_meta_count' | '3000' | '' |
| 'cache' | 'table_data_cache_population_queue_size' | '0' | '' |
| 'cache' | 'table_data_deserialized_data_bytes' | '0' | '' |
| 'cache' | 'table_data_deserialized_memory_ratio' | '0' | '' |
| 'cache' | 'table_meta_segment_bytes' | '1073741824' | '' |
| 'cache' | 'table_meta_segment_count' | 'null' | '' |
| 'cache' | 'table_meta_snapshot_count' | '256' | '' |
Expand Down
10 changes: 8 additions & 2 deletions src/query/storages/common/cache_manager/src/cache_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ pub struct CacheManager {

impl CacheManager {
/// Initialize the caches according to the relevant configurations.
pub fn init(config: &CacheConfig, tenant_id: impl Into<String>) -> Result<()> {
pub fn init(
config: &CacheConfig,
max_server_memory_usage: &u64,
tenant_id: impl Into<String>,
) -> Result<()> {
// setup table data cache
let table_data_cache = {
match config.data_cache_storage {
Expand Down Expand Up @@ -94,8 +98,10 @@ impl CacheManager {
};

// setup in-memory table column cache
let memory_cache_capacity =
max_server_memory_usage * config.table_data_deserialized_memory_ratio / 100;
let table_column_array_cache = Self::new_in_memory_cache(
config.table_data_deserialized_data_bytes,
memory_cache_capacity,
ColumnArrayMeter,
"table_data_column_array",
);
Expand Down
Loading