From ec44f3d568fd0093c7cfab821d7a43eb01af4843 Mon Sep 17 00:00:00 2001 From: Jonathan de Jong Date: Tue, 20 Jul 2021 10:47:36 +0200 Subject: [PATCH] change to f64 --- src/database.rs | 10 ++++------ src/database/abstraction/sqlite.rs | 8 +++++--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/database.rs b/src/database.rs index f7c3d9d..34bce73 100644 --- a/src/database.rs +++ b/src/database.rs @@ -54,7 +54,7 @@ pub struct Config { #[serde(default = "default_sqlite_wal_clean_second_timeout")] sqlite_wal_clean_second_timeout: u32, #[serde(default = "default_sqlite_spillover_reap_fraction")] - sqlite_spillover_reap_fraction: u32, + sqlite_spillover_reap_fraction: f64, #[serde(default = "default_sqlite_spillover_reap_interval_secs")] sqlite_spillover_reap_interval_secs: u32, #[serde(default = "default_max_request_size")] @@ -125,8 +125,8 @@ fn default_sqlite_wal_clean_second_timeout() -> u32 { 2 } -fn default_sqlite_spillover_reap_fraction() -> u32 { - 2 +fn default_sqlite_spillover_reap_fraction() -> f64 { + 2.0 } fn default_sqlite_spillover_reap_interval_secs() -> u32 { @@ -558,9 +558,7 @@ impl Database { #[cfg(feature = "sqlite")] pub async fn start_spillover_reap_task(engine: Arc, config: &Config) { - use std::convert::TryInto; - - let fraction_factor = config.sqlite_spillover_reap_fraction.max(1).try_into().unwrap(/* We just converted it to be at least 1 */); + let fraction_factor = config.sqlite_spillover_reap_fraction.max(1.0); let interval_secs = config.sqlite_spillover_reap_interval_secs as u64; let weak = Arc::downgrade(&engine); diff --git a/src/database/abstraction/sqlite.rs b/src/database/abstraction/sqlite.rs index 445093a..f7c178f 100644 --- a/src/database/abstraction/sqlite.rs +++ b/src/database/abstraction/sqlite.rs @@ -9,7 +9,6 @@ use rusqlite::{params, Connection, DatabaseName::Main, OptionalExtension}; use std::{ collections::BTreeMap, future::Future, - num::NonZeroU32, ops::Deref, path::{Path, PathBuf}, pin::Pin, @@ -246,10 +245,13 @@ impl Engine { } // Reaps (at most) (.len() / `fraction`) (rounded down, min 1) connections. - pub fn reap_spillover_by_fraction(&self, fraction: NonZeroU32) { + pub fn reap_spillover_by_fraction(&self, fraction: f64) { let mut reaped = 0; - let amount = ((self.pool.spills.1.len() as u32) / fraction).max(1); + let spill_amount = self.pool.spills.1.len() as f64; + let fraction = fraction.max(1.0 /* Can never be too sure */); + + let amount = (spill_amount / fraction).max(1.0) as u32; for _ in 0..amount { if self.pool.spills.try_take().is_some() {