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 6ef8058..07438f2 100644 --- a/slingshot/src/main.rs +++ b/slingshot/src/main.rs @@ -31,6 +31,14 @@ struct Args { #[arg(long, env = "SLINGSHOT_BIND")] #[clap(default_value = "0.0.0.0:8080")] bind: std::net::SocketAddr, + /// memory cache size in megabytes + #[arg(long, env = "SLINGSHOT_CACHE_MEMORY_MB")] + #[clap(default_value_t = 64)] + cache_memory_mb: usize, + /// disk cache size in gigabytes + #[arg(long, env = "SLINGHSOT_CACHE_DISK_DB")] + #[clap(default_value_t = 1)] + cache_disk_gb: usize, /// the domain pointing to this server /// /// if present: @@ -108,7 +116,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();