diff --git a/slingshot/src/firehose_cache.rs b/slingshot/src/firehose_cache.rs index 29ce666..5faffab 100644 --- a/slingshot/src/firehose_cache.rs +++ b/slingshot/src/firehose_cache.rs @@ -15,7 +15,7 @@ pub async fn firehose_cache( .with_device_options( DirectFsDeviceOptions::new(cache_dir) .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 + .with_file_size(16 * 2_usize.pow(20)), // note: this does limit the max cached item size (records should be max 1mb cbor, bit bigger json) ) .build() .await diff --git a/slingshot/src/identity.rs b/slingshot/src/identity.rs index 80e5286..16733ce 100644 --- a/slingshot/src/identity.rs +++ b/slingshot/src/identity.rs @@ -161,7 +161,11 @@ pub struct Identity { } impl Identity { - pub async fn new(cache_dir: impl AsRef) -> Result { + pub async fn new( + cache_dir: impl AsRef, + memory_mb: usize, + disk_gb: usize, + ) -> Result { let http_client = Arc::new(DefaultHttpClient::default()); let handle_resolver = AtprotoHandleResolver::new(AtprotoHandleResolverConfig { dns_txt_resolver: HickoryDnsTxtResolver::new().unwrap(), @@ -174,13 +178,13 @@ impl Identity { let cache = HybridCacheBuilder::new() .with_name("identity") - .memory(16 * 2_usize.pow(20)) + .memory(memory_mb * 2_usize.pow(20)) .with_weighter(|k, v| std::mem::size_of_val(k) + std::mem::size_of_val(v)) .storage(Engine::small()) .with_device_options( DirectFsDeviceOptions::new(cache_dir) - .with_capacity(2_usize.pow(30)) // TODO: configurable (1GB to have something) - .with_file_size(2_usize.pow(20)), // note: this does limit the max cached item size, warning jumbo records + .with_capacity(disk_gb * 2_usize.pow(30)) // TODO: configurable (1GB to have something) + .with_file_size(2_usize.pow(20)), // note: this does limit the max cached item size! ) .build() .await?; diff --git a/slingshot/src/main.rs b/slingshot/src/main.rs index 07438f2..8b9147f 100644 --- a/slingshot/src/main.rs +++ b/slingshot/src/main.rs @@ -31,14 +31,22 @@ 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")] + /// memory cache size in megabytes for records + #[arg(long, env = "SLINGSHOT_RECORD_CACHE_MEMORY_MB")] #[clap(default_value_t = 64)] - cache_memory_mb: usize, - /// disk cache size in gigabytes - #[arg(long, env = "SLINGHSOT_CACHE_DISK_DB")] + record_cache_memory_mb: usize, + /// disk cache size in gigabytes for records + #[arg(long, env = "SLINGSHOT_RECORD_CACHE_DISK_DB")] #[clap(default_value_t = 1)] - cache_disk_gb: usize, + record_cache_disk_gb: usize, + /// memory cache size in megabytes for identities + #[arg(long, env = "SLINGSHOT_IDENTITY_CACHE_MEMORY_MB")] + #[clap(default_value_t = 64)] + identity_cache_memory_mb: usize, + /// disk cache size in gigabytes for identities + #[arg(long, env = "SLINGSHOT_IDENTITY_CACHE_DISK_DB")] + #[clap(default_value_t = 1)] + identity_cache_disk_gb: usize, /// the domain pointing to this server /// /// if present: @@ -118,8 +126,8 @@ async fn main() -> Result<(), String> { log::info!("setting up firehose cache..."); let cache = firehose_cache( cache_dir.join("./firehose"), - args.cache_memory_mb, - args.cache_disk_gb, + args.record_cache_memory_mb, + args.record_cache_disk_gb, ) .await?; log::info!("firehose cache ready."); @@ -127,9 +135,14 @@ async fn main() -> Result<(), String> { let mut tasks: tokio::task::JoinSet> = tokio::task::JoinSet::new(); log::info!("starting identity service..."); - let identity = Identity::new(cache_dir.join("./identity")) - .await - .map_err(|e| format!("identity setup failed: {e:?}"))?; + let identity = Identity::new( + cache_dir.join("./identity"), + args.identity_cache_memory_mb, + args.identity_cache_disk_gb, + ) + .await + .map_err(|e| format!("identity setup failed: {e:?}"))?; + log::info!("identity service ready."); let identity_refresher = identity.clone(); let identity_shutdown = shutdown.clone();