From 0c2941c4157ffe29c63c74f4439fbc39a600ff03 Mon Sep 17 00:00:00 2001 From: "@nekomimi.pet" Date: Wed, 19 Nov 2025 21:49:35 -0500 Subject: [PATCH] slingshot: configurable cache sizes --- slingshot/src/firehose_cache.rs | 6 ++++-- slingshot/src/main.rs | 13 ++++++++++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/slingshot/src/firehose_cache.rs b/slingshot/src/firehose_cache.rs index 1ff33da..29ce666 100644 --- a/slingshot/src/firehose_cache.rs +++ b/slingshot/src/firehose_cache.rs @@ -4,15 +4,17 @@ use std::path::Path; pub async fn firehose_cache( cache_dir: impl AsRef, + memory_mb: usize, + disk_gb: usize, ) -> Result, String> { let cache = HybridCacheBuilder::new() .with_name("firehose") - .memory(64 * 2_usize.pow(20)) + .memory(memory_mb * 2_usize.pow(20)) .with_weighter(|k: &String, v| k.len() + std::mem::size_of_val(v)) .storage(Engine::large()) .with_device_options( DirectFsDeviceOptions::new(cache_dir) - .with_capacity(2_usize.pow(30)) // TODO: configurable (1GB to have something) + .with_capacity(disk_gb * 2_usize.pow(30)) .with_file_size(16 * 2_usize.pow(20)), // note: this does limit the max cached item size, warning jumbo records ) .build() diff --git a/slingshot/src/main.rs b/slingshot/src/main.rs index ae5fdbb..e769cd9 100644 --- a/slingshot/src/main.rs +++ b/slingshot/src/main.rs @@ -25,6 +25,12 @@ struct Args { /// where to keep disk caches #[arg(long)] cache_dir: PathBuf, + /// memory cache size in MB + #[arg(long, default_value_t = 64)] + cache_memory_mb: usize, + /// disk cache size in GB + #[arg(long, default_value_t = 1)] + cache_disk_gb: usize, /// the domain pointing to this server /// /// if present: @@ -83,7 +89,12 @@ async fn main() -> Result<(), String> { log::info!("cache dir ready at at {cache_dir:?}."); log::info!("setting up firehose cache..."); - let cache = firehose_cache(cache_dir.join("./firehose")).await?; + let cache = firehose_cache( + cache_dir.join("./firehose"), + args.cache_memory_mb, + args.cache_disk_gb, + ) + .await?; log::info!("firehose cache ready."); let mut tasks: tokio::task::JoinSet> = tokio::task::JoinSet::new(); -- 2.51.0