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

slingshot: configurable cache sizes

Changed files
+16 -3
slingshot
+4 -2
slingshot/src/firehose_cache.rs
···
pub async fn firehose_cache(
cache_dir: impl AsRef<Path>,
) -> Result<HybridCache<String, CachedRecord>, String> {
let cache = HybridCacheBuilder::new()
.with_name("firehose")
-
.memory(64 * 2_usize.pow(20))
.with_weighter(|k: &String, v| k.len() + std::mem::size_of_val(v))
.storage(Engine::large())
.with_device_options(
DirectFsDeviceOptions::new(cache_dir)
-
.with_capacity(2_usize.pow(30)) // TODO: configurable (1GB to have something)
.with_file_size(16 * 2_usize.pow(20)), // note: this does limit the max cached item size, warning jumbo records
)
.build()
···
pub async fn firehose_cache(
cache_dir: impl AsRef<Path>,
+
memory_mb: usize,
+
disk_gb: usize,
) -> Result<HybridCache<String, CachedRecord>, String> {
let cache = HybridCacheBuilder::new()
.with_name("firehose")
+
.memory(memory_mb * 2_usize.pow(20))
.with_weighter(|k: &String, v| k.len() + std::mem::size_of_val(v))
.storage(Engine::large())
.with_device_options(
DirectFsDeviceOptions::new(cache_dir)
+
.with_capacity(disk_gb * 2_usize.pow(30))
.with_file_size(16 * 2_usize.pow(20)), // note: this does limit the max cached item size, warning jumbo records
)
.build()
+12 -1
slingshot/src/main.rs
···
/// where to keep disk caches
#[arg(long)]
cache_dir: PathBuf,
/// the domain pointing to this server
///
/// if present:
···
log::info!("cache dir ready at at {cache_dir:?}.");
log::info!("setting up firehose cache...");
-
let cache = firehose_cache(cache_dir.join("./firehose")).await?;
log::info!("firehose cache ready.");
let mut tasks: tokio::task::JoinSet<Result<(), MainTaskError>> = tokio::task::JoinSet::new();
···
/// where to keep disk caches
#[arg(long)]
cache_dir: PathBuf,
+
/// memory cache size in MB
+
#[arg(long, default_value_t = 64)]
+
cache_memory_mb: usize,
+
/// disk cache size in GB
+
#[arg(long, default_value_t = 1)]
+
cache_disk_gb: usize,
/// the domain pointing to this server
///
/// if present:
···
log::info!("cache dir ready at at {cache_dir:?}.");
log::info!("setting up firehose cache...");
+
let cache = firehose_cache(
+
cache_dir.join("./firehose"),
+
args.cache_memory_mb,
+
args.cache_disk_gb,
+
)
+
.await?;
log::info!("firehose cache ready.");
let mut tasks: tokio::task::JoinSet<Result<(), MainTaskError>> = tokio::task::JoinSet::new();