From eba7a32615b6862c20e96bed9442022ca7ee0894 Mon Sep 17 00:00:00 2001 From: Greg Heartsfield Date: Sun, 7 May 2023 19:38:18 -0500 Subject: [PATCH] perf: reduce SQLite connection count and idle lifetime On lightly loaded relays, we free up memory faster by letting idle connections be reclaimed in 10 seconds instead of the default 10 minutes. This also sets the minimum to zero connections, instead of always trying to hold one open. --- config.toml | 2 +- src/repo/sqlite.rs | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/config.toml b/config.toml index a3edb91..3dea8ee 100644 --- a/config.toml +++ b/config.toml @@ -42,7 +42,7 @@ description = "A newly created nostr-rs-relay.\n\nCustomize this with your own i # Database connection pool settings for subscribers: # Minimum number of SQLite reader connections -#min_conn = 4 +#min_conn = 0 # Maximum number of SQLite reader connections. Recommend setting this # to approx the number of cores. diff --git a/src/repo/sqlite.rs b/src/repo/sqlite.rs index 91b48e6..b156f0c 100644 --- a/src/repo/sqlite.rs +++ b/src/repo/sqlite.rs @@ -62,7 +62,7 @@ impl SqliteRepo { "writer", settings, OpenFlags::SQLITE_OPEN_READ_WRITE | OpenFlags::SQLITE_OPEN_CREATE, - 1, + 0, 2, false, ); @@ -70,7 +70,7 @@ impl SqliteRepo { "maintenance", settings, OpenFlags::SQLITE_OPEN_READ_WRITE | OpenFlags::SQLITE_OPEN_CREATE, - 1, + 0, 2, true, ); @@ -1199,6 +1199,7 @@ pub fn build_pool( .test_on_check_out(true) // no noticeable performance hit .min_idle(Some(min_size)) .max_size(max_size) + .idle_timeout(Some(Duration::from_secs(10))) .max_lifetime(Some(Duration::from_secs(30))) .build(manager) .unwrap();