Constellation, Spacedust, Slingshot, UFOs: atproto crates and services for microcosm

slingshot: add configurable cache sizes, host, and ports

- Add --cache-memory-mb and --cache-disk-gb flags

authored by bad-example.com and committed by tangled.org eeb94d8a d3d84a6e

+18 -3
+4 -2
slingshot/src/firehose_cache.rs
··· 4 4 5 5 pub async fn firehose_cache( 6 6 cache_dir: impl AsRef<Path>, 7 + memory_mb: usize, 8 + disk_gb: usize, 7 9 ) -> Result<HybridCache<String, CachedRecord>, String> { 8 10 let cache = HybridCacheBuilder::new() 9 11 .with_name("firehose") 10 - .memory(64 * 2_usize.pow(20)) 12 + .memory(memory_mb * 2_usize.pow(20)) 11 13 .with_weighter(|k: &String, v| k.len() + std::mem::size_of_val(v)) 12 14 .storage(Engine::large()) 13 15 .with_device_options( 14 16 DirectFsDeviceOptions::new(cache_dir) 15 - .with_capacity(2_usize.pow(30)) // TODO: configurable (1GB to have something) 17 + .with_capacity(disk_gb * 2_usize.pow(30)) 16 18 .with_file_size(16 * 2_usize.pow(20)), // note: this does limit the max cached item size, warning jumbo records 17 19 ) 18 20 .build()
+14 -1
slingshot/src/main.rs
··· 31 31 #[arg(long, env = "SLINGSHOT_BIND")] 32 32 #[clap(default_value = "0.0.0.0:8080")] 33 33 bind: std::net::SocketAddr, 34 + /// memory cache size in megabytes 35 + #[arg(long, env = "SLINGSHOT_CACHE_MEMORY_MB")] 36 + #[clap(default_value_t = 64)] 37 + cache_memory_mb: usize, 38 + /// disk cache size in gigabytes 39 + #[arg(long, env = "SLINGHSOT_CACHE_DISK_DB")] 40 + #[clap(default_value_t = 1)] 41 + cache_disk_gb: usize, 34 42 /// the domain pointing to this server 35 43 /// 36 44 /// if present: ··· 108 116 log::info!("cache dir ready at at {cache_dir:?}."); 109 117 110 118 log::info!("setting up firehose cache..."); 111 - let cache = firehose_cache(cache_dir.join("./firehose")).await?; 119 + let cache = firehose_cache( 120 + cache_dir.join("./firehose"), 121 + args.cache_memory_mb, 122 + args.cache_disk_gb, 123 + ) 124 + .await?; 112 125 log::info!("firehose cache ready."); 113 126 114 127 let mut tasks: tokio::task::JoinSet<Result<(), MainTaskError>> = tokio::task::JoinSet::new();