From 04db2203bb646e4f42bddb3d0c63fdc76eccf1ca Mon Sep 17 00:00:00 2001 From: Greg Heartsfield Date: Wed, 3 May 2023 07:22:44 -0500 Subject: [PATCH] perf: use standard allocator, limit sqlite mmap to 4GB This is an experimental change to see if we can reduce memory usage with large SQLite databases. If successful, we'll do this again and further reduce the database mmap size. This will cause greater use of the page cache, but that is more easily reclaimed by the kernel, and should reduce memory pressure, as well as making it clearer how much memory the application is actually using for connections, subscriptions, etc. --- Cargo.lock | 21 --------------------- Cargo.toml | 2 -- src/main.rs | 7 ------- src/repo/sqlite_migration.rs | 2 +- 4 files changed, 1 insertion(+), 31 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9533514..b515fab 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1689,7 +1689,6 @@ dependencies = [ "serde_json", "sqlx", "thiserror", - "tikv-jemallocator", "tokio", "tokio-tungstenite", "tonic", @@ -2959,26 +2958,6 @@ dependencies = [ "once_cell", ] -[[package]] -name = "tikv-jemalloc-sys" -version = "0.5.3+5.3.0-patched" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a678df20055b43e57ef8cddde41cdfda9a3c1a060b67f4c5836dfb1d78543ba8" -dependencies = [ - "cc", - "libc", -] - -[[package]] -name = "tikv-jemallocator" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "20612db8a13a6c06d57ec83953694185a367e16945f66565e8028d2c0bd76979" -dependencies = [ - "libc", - "tikv-jemalloc-sys", -] - [[package]] name = "time" version = "0.1.45" diff --git a/Cargo.toml b/Cargo.toml index b04ef07..25f4f03 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -54,8 +54,6 @@ bech32 = "0.9.1" url = "2.3.1" qrcode = { version = "0.12.0", default-features = false, features = ["svg"] } nostr = { version = "0.18.0", default-features = false, features = ["base", "nip04", "nip19"] } -[target.'cfg(not(target_env = "msvc"))'.dependencies] -tikv-jemallocator = "0.5" [dev-dependencies] anyhow = "1" diff --git a/src/main.rs b/src/main.rs index 97aa032..712c902 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,13 +9,6 @@ use std::sync::mpsc::{Receiver as MpscReceiver, Sender as MpscSender}; use std::thread; use tracing::info; -#[cfg(not(target_env = "msvc"))] -use tikv_jemallocator::Jemalloc; - -#[cfg(not(target_env = "msvc"))] -#[global_allocator] -static GLOBAL: Jemalloc = Jemalloc; - /// Start running a Nostr relay server. fn main() { let args = CLIArgs::parse(); diff --git a/src/repo/sqlite_migration.rs b/src/repo/sqlite_migration.rs index 709a572..60544b2 100644 --- a/src/repo/sqlite_migration.rs +++ b/src/repo/sqlite_migration.rs @@ -19,7 +19,7 @@ PRAGMA foreign_keys = ON; PRAGMA journal_size_limit = 32768; PRAGMA temp_store = 2; -- use memory, not temp files PRAGMA main.cache_size = 20000; -- 80MB max cache size per conn -pragma mmap_size = 17179869184; -- cap mmap at 16GB +pragma mmap_size = 4294967296; -- cap mmap at 4GB "##; /// Latest database version