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
+38 -8
Diff #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()
+26 -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 + /// host for HTTP server (when not using --domain) 35 + #[arg(long, default_value = "127.0.0.1")] 36 + host: String, 37 + /// port for HTTP server (when not using --domain) 38 + #[arg(long, default_value_t = 3000)] 39 + port: u16, 40 + /// port for metrics/prometheus server 41 + #[arg(long, default_value_t = 8765)] 42 + metrics_port: u16, 28 43 /// the domain pointing to this server 29 44 /// 30 45 /// if present: ··· 62 77 63 78 let args = Args::parse(); 64 79 65 - if let Err(e) = install_metrics_server() { 80 + if let Err(e) = install_metrics_server(args.metrics_port) { 66 81 log::error!("failed to install metrics server: {e:?}"); 67 82 } else { 68 - log::info!("metrics listening at http://0.0.0.0:8765"); 83 + log::info!("metrics listening at http://0.0.0.0:{}", args.metrics_port); 69 84 } 70 85 71 86 std::fs::create_dir_all(&args.cache_dir).map_err(|e| { ··· 83 98 log::info!("cache dir ready at at {cache_dir:?}."); 84 99 85 100 log::info!("setting up firehose cache..."); 86 - let cache = firehose_cache(cache_dir.join("./firehose")).await?; 101 + let cache = firehose_cache( 102 + cache_dir.join("./firehose"), 103 + args.cache_memory_mb, 104 + args.cache_disk_gb, 105 + ) 106 + .await?; 87 107 log::info!("firehose cache ready."); 88 108 89 109 let mut tasks: tokio::task::JoinSet<Result<(), MainTaskError>> = tokio::task::JoinSet::new(); ··· 112 132 args.domain, 113 133 args.acme_contact, 114 134 args.certs, 135 + args.host, 136 + args.port, 115 137 server_shutdown, 116 138 ) 117 139 .await?; ··· 172 194 Ok(()) 173 195 } 174 196 175 - fn install_metrics_server() -> Result<(), metrics_exporter_prometheus::BuildError> { 197 + fn install_metrics_server(port: u16) -> Result<(), metrics_exporter_prometheus::BuildError> { 176 198 log::info!("installing metrics server..."); 177 199 let host = [0, 0, 0, 0]; 178 - let port = 8765; 179 200 PrometheusBuilder::new() 180 201 .set_quantiles(&[0.5, 0.9, 0.99, 1.0])? 181 202 .set_bucket_duration(std::time::Duration::from_secs(300))?
+8 -1
slingshot/src/server.rs
··· 694 694 domain: Option<String>, 695 695 acme_contact: Option<String>, 696 696 certs: Option<PathBuf>, 697 + host: String, 698 + port: u16, 697 699 shutdown: CancellationToken, 698 700 ) -> Result<(), ServerError> { 699 701 let repo = Arc::new(repo); ··· 752 754 ) 753 755 .await 754 756 } else { 755 - run(TcpListener::bind("127.0.0.1:3000"), app, shutdown).await 757 + run( 758 + TcpListener::bind(format!("{host}:{port}")), 759 + app, 760 + shutdown, 761 + ) 762 + .await 756 763 } 757 764 } 758 765

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