From 73d876643cf6d94f97dbe2658279c67f89dc130f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20K=C3=B6sters?= Date: Wed, 1 Sep 2021 11:03:12 +0200 Subject: [PATCH] improvement: make pdu cache capacity configurable --- src/database.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/database.rs b/src/database.rs index 79571f67..e9dd661a 100644 --- a/src/database.rs +++ b/src/database.rs @@ -47,6 +47,8 @@ pub struct Config { database_path: String, #[serde(default = "default_db_cache_capacity_mb")] db_cache_capacity_mb: f64, + #[serde(default = "default_pdu_cache_capacity")] + pdu_cache_capacity: u32, #[serde(default = "default_sqlite_wal_clean_second_interval")] sqlite_wal_clean_second_interval: u32, #[serde(default = "default_max_request_size")] @@ -107,6 +109,10 @@ fn default_db_cache_capacity_mb() -> f64 { 200.0 } +fn default_pdu_cache_capacity() -> u32 { + 100_000 +} + fn default_sqlite_wal_clean_second_interval() -> u32 { 1 * 60 // every minute } @@ -281,7 +287,12 @@ impl Database { softfailedeventids: builder.open_tree("softfailedeventids")?, referencedevents: builder.open_tree("referencedevents")?, - pdu_cache: Mutex::new(LruCache::new(100_000)), + pdu_cache: Mutex::new(LruCache::new( + config + .pdu_cache_capacity + .try_into() + .expect("pdu cache capacity fits into usize"), + )), auth_chain_cache: Mutex::new(LruCache::new(1_000_000)), shorteventid_cache: Mutex::new(LruCache::new(1_000_000)), eventidshort_cache: Mutex::new(LruCache::new(1_000_000)),