Skip to content

Commit

Permalink
perf: use standard allocator, limit sqlite mmap to 4GB
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
scsibug committed May 3, 2023
1 parent 1c1b1a1 commit 04db220
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 31 deletions.
21 changes: 0 additions & 21 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions Cargo.toml
Expand Up @@ -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"
Expand Down
7 changes: 0 additions & 7 deletions src/main.rs
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/repo/sqlite_migration.rs
Expand Up @@ -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
Expand Down

0 comments on commit 04db220

Please sign in to comment.