diff --git a/slingshot/readme.md b/slingshot/readme.md index beb4de8..2e97416 100644 --- a/slingshot/readme.md +++ b/slingshot/readme.md @@ -5,3 +5,11 @@ local dev running: ```bash RUST_LOG=info,slingshot=trace ulimit -n 4096 && RUST_LOG=info cargo run -- --jetstream us-east-1 --cache-dir ./foyer ``` + +the identity cache uses a lot of files so you probably need to bump ulimit + +on macos: + +```bash +ulimit -n 4096 +``` diff --git a/slingshot/src/firehose_cache.rs b/slingshot/src/firehose_cache.rs index 7b069ec..bbb42d7 100644 --- a/slingshot/src/firehose_cache.rs +++ b/slingshot/src/firehose_cache.rs @@ -1,5 +1,8 @@ use crate::CachedRecord; -use foyer::{BlockEngineConfig, DeviceBuilder, FileDeviceBuilder, HybridCache, HybridCacheBuilder}; +use foyer::{ + BlockEngineConfig, DeviceBuilder, FsDeviceBuilder, HybridCache, HybridCacheBuilder, + PsyncIoEngineConfig, +}; use std::path::Path; pub async fn firehose_cache( @@ -7,7 +10,7 @@ pub async fn firehose_cache( memory_mb: usize, disk_gb: usize, ) -> Result, String> { - let device = FileDeviceBuilder::new(cache_dir) + let device = FsDeviceBuilder::new(cache_dir) .with_capacity(disk_gb * 2_usize.pow(30)) .build() .map_err(|e| format!("foyer device setup error: {e}"))?; @@ -21,6 +24,7 @@ pub async fn firehose_cache( std::mem::size_of_val(k.as_str()) + v.weight() }) .storage() + .with_io_engine_config(PsyncIoEngineConfig::default()) .with_engine_config(engine) .build() .await diff --git a/slingshot/src/identity.rs b/slingshot/src/identity.rs index 25c7ddc..4e24b1c 100644 --- a/slingshot/src/identity.rs +++ b/slingshot/src/identity.rs @@ -26,7 +26,10 @@ use atrium_identity::{ handle::{AtprotoHandleResolver, AtprotoHandleResolverConfig, DnsTxtResolver}, }; use atrium_oauth::DefaultHttpClient; // it's probably not worth bringing all of atrium_oauth for this but -use foyer::{BlockEngineConfig, DeviceBuilder, FileDeviceBuilder, HybridCache, HybridCacheBuilder}; +use foyer::{ + BlockEngineConfig, DeviceBuilder, FsDeviceBuilder, HybridCache, HybridCacheBuilder, + PsyncIoEngineConfig, +}; use serde::{Deserialize, Serialize}; use time::UtcDateTime; @@ -202,7 +205,7 @@ impl Identity { http_client: http_client.clone(), }); - let device = FileDeviceBuilder::new(cache_dir) + let device = FsDeviceBuilder::new(cache_dir) .with_capacity(disk_gb * 2_usize.pow(30)) .build()?; let engine = BlockEngineConfig::new(device).with_block_size(2_usize.pow(20)); // note: this does limit the max cached item size @@ -212,6 +215,7 @@ impl Identity { .memory(memory_mb * 2_usize.pow(20)) .with_weighter(|k: &IdentityKey, v: &IdentityVal| k.weight() + v.weight()) .storage() + .with_io_engine_config(PsyncIoEngineConfig::default()) .with_engine_config(engine) .build() .await?; diff --git a/slingshot/src/main.rs b/slingshot/src/main.rs index 8b9147f..19b49b3 100644 --- a/slingshot/src/main.rs +++ b/slingshot/src/main.rs @@ -4,6 +4,7 @@ use metrics_exporter_prometheus::PrometheusBuilder; use slingshot::{ Identity, Repo, consume, error::MainTaskError, firehose_cache, healthcheck, serve, }; +use std::net::SocketAddr; use std::path::PathBuf; use clap::Parser; @@ -30,7 +31,7 @@ struct Args { /// cannot be used with acme -- if you need ipv6 see --acme-ipv6 #[arg(long, env = "SLINGSHOT_BIND")] #[clap(default_value = "0.0.0.0:8080")] - bind: std::net::SocketAddr, + bind: SocketAddr, /// memory cache size in megabytes for records #[arg(long, env = "SLINGSHOT_RECORD_CACHE_MEMORY_MB")] #[clap(default_value_t = 64)] diff --git a/slingshot/src/server.rs b/slingshot/src/server.rs index 5e1344b..1552299 100644 --- a/slingshot/src/server.rs +++ b/slingshot/src/server.rs @@ -713,7 +713,7 @@ pub async fn serve( .server(if let Some(ref h) = acme_domain { format!("https://{h}") } else { - "http://localhost:3000".to_string() + format!("http://{bind}") // yeah should probably fix this for reverse-proxy scenarios but it's ok for dev for now }) .url_prefix("/xrpc") .contact(