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

slingshot: configurable cache sizes (#3 round 2) #11

merged opened by bad-example.com targeting main from np-config-cache

Pick up from #3 to get the configurable cache sizes in

Listener binding landed in another PR so this is stripped back just to the cache size config. Note that I added a separate pair of configs for the identity cache, so the arg names for all changed slightly.

Labels

None yet.

Participants 1
AT URI
at://did:plc:hdhoaan3xa3jiuq4fg4mefid/sh.tangled.repo.pull/3mdvjenmgu222
+43 -11
Diff #0
+5 -3
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) 16 - .with_file_size(16 * 2_usize.pow(20)), // note: this does limit the max cached item size, warning jumbo records 17 + .with_capacity(disk_gb * 2_usize.pow(30)) 18 + .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) 17 19 ) 18 20 .build() 19 21 .await
+8 -4
slingshot/src/identity.rs
··· 161 161 } 162 162 163 163 impl Identity { 164 - pub async fn new(cache_dir: impl AsRef<Path>) -> Result<Self, IdentityError> { 164 + pub async fn new( 165 + cache_dir: impl AsRef<Path>, 166 + memory_mb: usize, 167 + disk_gb: usize, 168 + ) -> Result<Self, IdentityError> { 165 169 let http_client = Arc::new(DefaultHttpClient::default()); 166 170 let handle_resolver = AtprotoHandleResolver::new(AtprotoHandleResolverConfig { 167 171 dns_txt_resolver: HickoryDnsTxtResolver::new().unwrap(), ··· 174 178 175 179 let cache = HybridCacheBuilder::new() 176 180 .with_name("identity") 177 - .memory(16 * 2_usize.pow(20)) 181 + .memory(memory_mb * 2_usize.pow(20)) 178 182 .with_weighter(|k, v| std::mem::size_of_val(k) + std::mem::size_of_val(v)) 179 183 .storage(Engine::small()) 180 184 .with_device_options( 181 185 DirectFsDeviceOptions::new(cache_dir) 182 - .with_capacity(2_usize.pow(30)) // TODO: configurable (1GB to have something) 183 - .with_file_size(2_usize.pow(20)), // note: this does limit the max cached item size, warning jumbo records 186 + .with_capacity(disk_gb * 2_usize.pow(30)) // TODO: configurable (1GB to have something) 187 + .with_file_size(2_usize.pow(20)), // note: this does limit the max cached item size! 184 188 ) 185 189 .build() 186 190 .await?;
+30 -4
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 for records 35 + #[arg(long, env = "SLINGSHOT_RECORD_CACHE_MEMORY_MB")] 36 + #[clap(default_value_t = 64)] 37 + record_cache_memory_mb: usize, 38 + /// disk cache size in gigabytes for records 39 + #[arg(long, env = "SLINGSHOT_RECORD_CACHE_DISK_DB")] 40 + #[clap(default_value_t = 1)] 41 + record_cache_disk_gb: usize, 42 + /// memory cache size in megabytes for identities 43 + #[arg(long, env = "SLINGSHOT_IDENTITY_CACHE_MEMORY_MB")] 44 + #[clap(default_value_t = 64)] 45 + identity_cache_memory_mb: usize, 46 + /// disk cache size in gigabytes for identities 47 + #[arg(long, env = "SLINGSHOT_IDENTITY_CACHE_DISK_DB")] 48 + #[clap(default_value_t = 1)] 49 + identity_cache_disk_gb: usize, 34 50 /// the domain pointing to this server 35 51 /// 36 52 /// if present: ··· 108 124 log::info!("cache dir ready at at {cache_dir:?}."); 109 125 110 126 log::info!("setting up firehose cache..."); 111 - let cache = firehose_cache(cache_dir.join("./firehose")).await?; 127 + let cache = firehose_cache( 128 + cache_dir.join("./firehose"), 129 + args.record_cache_memory_mb, 130 + args.record_cache_disk_gb, 131 + ) 132 + .await?; 112 133 log::info!("firehose cache ready."); 113 134 114 135 let mut tasks: tokio::task::JoinSet<Result<(), MainTaskError>> = tokio::task::JoinSet::new(); 115 136 116 137 log::info!("starting identity service..."); 117 - let identity = Identity::new(cache_dir.join("./identity")) 118 - .await 119 - .map_err(|e| format!("identity setup failed: {e:?}"))?; 138 + let identity = Identity::new( 139 + cache_dir.join("./identity"), 140 + args.identity_cache_memory_mb, 141 + args.identity_cache_disk_gb, 142 + ) 143 + .await 144 + .map_err(|e| format!("identity setup failed: {e:?}"))?; 145 + 120 146 log::info!("identity service ready."); 121 147 let identity_refresher = identity.clone(); 122 148 let identity_shutdown = shutdown.clone();

History

1 round 0 comments
sign up or login to add to the discussion
bad-example.com submitted #0
2 commits
expand
slingshot: add configurable cache sizes, host, and ports
make identity cache also configurable
expand 0 comments
pull request successfully merged