From d253f9236a87f0571c8561290cebda0437885a62 Mon Sep 17 00:00:00 2001 From: Jonathan de Jong Date: Tue, 20 Jul 2021 11:01:35 +0200 Subject: [PATCH] change fraction type --- src/database.rs | 6 +++--- src/database/abstraction/sqlite.rs | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/database.rs b/src/database.rs index 34bce734..9452e638 100644 --- a/src/database.rs +++ b/src/database.rs @@ -126,7 +126,7 @@ fn default_sqlite_wal_clean_second_timeout() -> u32 { } fn default_sqlite_spillover_reap_fraction() -> f64 { - 2.0 + 0.5 } fn default_sqlite_spillover_reap_interval_secs() -> u32 { @@ -558,7 +558,7 @@ impl Database { #[cfg(feature = "sqlite")] pub async fn start_spillover_reap_task(engine: Arc, config: &Config) { - let fraction_factor = config.sqlite_spillover_reap_fraction.max(1.0); + let fraction = config.sqlite_spillover_reap_fraction.clamp(0.01, 1.0); let interval_secs = config.sqlite_spillover_reap_interval_secs as u64; let weak = Arc::downgrade(&engine); @@ -574,7 +574,7 @@ impl Database { i.tick().await; if let Some(arc) = Weak::upgrade(&weak) { - arc.reap_spillover_by_fraction(fraction_factor); + arc.reap_spillover_by_fraction(fraction); } else { break; } diff --git a/src/database/abstraction/sqlite.rs b/src/database/abstraction/sqlite.rs index f7c178fc..8100ed91 100644 --- a/src/database/abstraction/sqlite.rs +++ b/src/database/abstraction/sqlite.rs @@ -244,14 +244,14 @@ impl Engine { .map_err(Into::into) } - // Reaps (at most) (.len() / `fraction`) (rounded down, min 1) connections. + // Reaps (at most) (.len() * `fraction`) (rounded down, min 1) connections. pub fn reap_spillover_by_fraction(&self, fraction: f64) { let mut reaped = 0; let spill_amount = self.pool.spills.1.len() as f64; - let fraction = fraction.max(1.0 /* Can never be too sure */); + let fraction = fraction.clamp(0.01, 1.0); - let amount = (spill_amount / fraction).max(1.0) as u32; + let amount = (spill_amount * fraction).max(1.0) as u32; for _ in 0..amount { if self.pool.spills.try_take().is_some() {