diff --git a/Cargo.lock b/Cargo.lock index a007236c..7a210562 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1910,6 +1910,7 @@ dependencies = [ "mac_address", "machine-uid 0.2.0", "minreq", + "num_cpus", "once_cell", "ping", "regex", diff --git a/Cargo.toml b/Cargo.toml index adc50b08..60699f8b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -59,6 +59,7 @@ ping = "0.5" sctgdesk-api-server = { git = "https://github.com/sctg-development/sctgdesk-api-server.git", branch = "main" } rocket = { version = "0.5", features = ["json", "secrets"] } +num_cpus = "1.16" [build-dependencies] hbb_common = { path = "libs/hbb_common" } diff --git a/db_v2.sqlite3 b/db_v2.sqlite3 index 1be6846a..bec00345 100644 Binary files a/db_v2.sqlite3 and b/db_v2.sqlite3 differ diff --git a/src/database.rs b/src/database.rs index 5d5ee481..f97ba905 100644 --- a/src/database.rs +++ b/src/database.rs @@ -1,4 +1,4 @@ -use hbb_common::{log, ResultType}; +use hbb_common::{log, toml::de, ResultType}; use sqlx::{ sqlite::SqliteConnectOptions, ConnectOptions, Connection, Error as SqlxError, SqliteConnection, }; @@ -50,11 +50,12 @@ impl Database { if !std::path::Path::new(url).exists() { std::fs::File::create(url).ok(); } + let deadpool_default_size = num_cpus::get()*4; // cf: https://docs.rs/deadpool/0.12.1/deadpool/managed/struct.PoolConfig.html#structfield.max_size let n: usize = std::env::var("MAX_DATABASE_CONNECTIONS") - .unwrap_or_else(|_| "1".to_owned()) + .unwrap_or_else(|_| deadpool_default_size.to_string().to_owned()) .parse() .unwrap_or(1); - log::debug!("MAX_DATABASE_CONNECTIONS={}", n); + log::info!("MAX_DATABASE_CONNECTIONS={}", n); let pool = Pool::builder(DbPool { url: url.to_owned(),