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

slingshot: configurable cache sizes #3

closed opened by nekomimi.pet targeting main from nekomimi.pet/microcosm-rs: main

I noticed defaults were hardcoded

./slingshot --jetstream us-east-1 --cache-dir ./foyer \
    --cache-memory-mb 128 \
    --cache-disk-gb 2
Labels

None yet.

Participants 2
AT URI
at://did:plc:ttdrpj45ibqunmfhdsb4zdwq/sh.tangled.repo.pull/3m5zrhmq67x22
+33 -8
Diff #1
+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()
+22 -5
slingshot/src/main.rs
··· 25 25 /// where to keep disk caches 26 26 #[arg(long)] 27 27 cache_dir: PathBuf, 28 + /// memory cache size in MB 29 + #[arg(long, default_value_t = 64)] 30 + cache_memory_mb: usize, 31 + /// disk cache size in GB 32 + #[arg(long, default_value_t = 1)] 33 + cache_disk_gb: usize, 34 + /// port for HTTP server (when not using --domain) 35 + #[arg(long, default_value_t = 3000)] 36 + port: u16, 37 + /// port for metrics/prometheus server 38 + #[arg(long, default_value_t = 8765)] 39 + metrics_port: u16, 28 40 /// the domain pointing to this server 29 41 /// 30 42 /// if present: ··· 62 74 63 75 let args = Args::parse(); 64 76 65 - if let Err(e) = install_metrics_server() { 77 + if let Err(e) = install_metrics_server(args.metrics_port) { 66 78 log::error!("failed to install metrics server: {e:?}"); 67 79 } else { 68 - log::info!("metrics listening at http://0.0.0.0:8765"); 80 + log::info!("metrics listening at http://0.0.0.0:{}", args.metrics_port); 69 81 } 70 82 71 83 std::fs::create_dir_all(&args.cache_dir).map_err(|e| { ··· 83 95 log::info!("cache dir ready at at {cache_dir:?}."); 84 96 85 97 log::info!("setting up firehose cache..."); 86 - let cache = firehose_cache(cache_dir.join("./firehose")).await?; 98 + let cache = firehose_cache( 99 + cache_dir.join("./firehose"), 100 + args.cache_memory_mb, 101 + args.cache_disk_gb, 102 + ) 103 + .await?; 87 104 log::info!("firehose cache ready."); 88 105 89 106 let mut tasks: tokio::task::JoinSet<Result<(), MainTaskError>> = tokio::task::JoinSet::new(); ··· 112 129 args.domain, 113 130 args.acme_contact, 114 131 args.certs, 132 + args.port, 115 133 server_shutdown, 116 134 ) 117 135 .await?; ··· 172 190 Ok(()) 173 191 } 174 192 175 - fn install_metrics_server() -> Result<(), metrics_exporter_prometheus::BuildError> { 193 + fn install_metrics_server(port: u16) -> Result<(), metrics_exporter_prometheus::BuildError> { 176 194 log::info!("installing metrics server..."); 177 195 let host = [0, 0, 0, 0]; 178 - let port = 8765; 179 196 PrometheusBuilder::new() 180 197 .set_quantiles(&[0.5, 0.9, 0.99, 1.0])? 181 198 .set_bucket_duration(std::time::Duration::from_secs(300))?
+7 -1
slingshot/src/server.rs
··· 694 694 domain: Option<String>, 695 695 acme_contact: Option<String>, 696 696 certs: Option<PathBuf>, 697 + port: u16, 697 698 shutdown: CancellationToken, 698 699 ) -> Result<(), ServerError> { 699 700 let repo = Arc::new(repo); ··· 752 753 ) 753 754 .await 754 755 } else { 755 - run(TcpListener::bind("127.0.0.1:3000"), app, shutdown).await 756 + run( 757 + TcpListener::bind(format!("127.0.0.1:{port}")), 758 + app, 759 + shutdown, 760 + ) 761 + .await 756 762 } 757 763 } 758 764

History

4 rounds 4 comments
sign up or login to add to the discussion
1 commit
expand
slingshot: add configurable cache sizes, host, and ports
expand 4 comments

sorry about the messy history, i ordered the git reset soft and amend wrong

thank you!!!

the cache size config is perfect, host and port close: i've started moving to a bind arg and giving clap the SocketAddr type directly so it gets parsed out early + one less thing to pass around.

bind stuff came in through a different pr that i just picked up to get merged, so i'm going to get these cache sizes in by picking this up and extracting that for merging

thanks for getting it started!

closed without merging
1 commit
expand
slingshot: add configurable cache sizes, host, and ports
expand 0 comments
2 commits
expand
slingshot: configurable cache sizes
slingshot: add configurable port and host to slingshot, configurable port to metrics
expand 0 comments
1 commit
expand
slingshot: configurable cache sizes
expand 0 comments