Fork Sync: Update from parent repository (#3)

* improvement: use appropriate paths for systemd example

* improvement: add a configurable postgres write conn string

This adds a new configurable connection string for postgres writes.

* improvement: document pg connection_write config

* build: upgrade checkout action for github ci

* 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.

* docs: reformatting

* docs: allow host header prefix matching, required for Damus compatibility

* perf: disable sqlite mmap to reduce memory pressure

* perf: switch to jemalloc allocator

* docs: helpful ubuntu packages for building

* 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.

---------

Co-authored-by: Petr Kracik <petrkr@petrkr.net>
Co-authored-by: Kieran <kieran@harkin.me>
Co-authored-by: Greg Heartsfield <scsibug@imap.cc>
This commit is contained in:
github-actions[bot] 2023-05-10 10:30:18 +02:00 committed by GitHub
parent 264c03bbab
commit 8bf52646c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 13 additions and 8 deletions

View File

@ -93,6 +93,11 @@ https://hub.docker.com/r/scsibug/nostr-rs-relay
Building `nostr-rs-relay` requires an installation of Cargo & Rust: https://www.rust-lang.org/tools/install Building `nostr-rs-relay` requires an installation of Cargo & Rust: https://www.rust-lang.org/tools/install
The following OS packages will be helpful; on Debian/Ubuntu:
```console
$ sudo apt-get install build-essentials cmake protobuf-compiler pkg-config libssl-dev
```
Clone this repository, and then build a release version of the relay: Clone this repository, and then build a release version of the relay:
```console ```console

View File

@ -42,7 +42,7 @@ description = "A newly created nostr-rs-relay.\n\nCustomize this with your own i
# Database connection pool settings for subscribers: # Database connection pool settings for subscribers:
# Minimum number of SQLite reader connections # Minimum number of SQLite reader connections
#min_conn = 4 #min_conn = 0
# Maximum number of SQLite reader connections. Recommend setting this # Maximum number of SQLite reader connections. Recommend setting this
# to approx the number of cores. # to approx the number of cores.

View File

@ -29,7 +29,7 @@ frontend fe_prod
bind :80 bind :80
http-request set-header X-Forwarded-Proto https if { ssl_fc } http-request set-header X-Forwarded-Proto https if { ssl_fc }
redirect scheme https code 301 if !{ ssl_fc } redirect scheme https code 301 if !{ ssl_fc }
acl host_relay hdr(host) -i relay.example.com acl host_relay hdr(host) -i -m beg relay.example.com
use_backend relay if host_relay use_backend relay if host_relay
# HSTS (1 year) # HSTS (1 year)
http-response set-header Strict-Transport-Security max-age=31536000 http-response set-header Strict-Transport-Security max-age=31536000

View File

@ -8,7 +8,6 @@ use std::sync::mpsc as syncmpsc;
use std::sync::mpsc::{Receiver as MpscReceiver, Sender as MpscSender}; use std::sync::mpsc::{Receiver as MpscReceiver, Sender as MpscSender};
use std::thread; use std::thread;
use tracing::info; use tracing::info;
#[cfg(not(target_env = "msvc"))] #[cfg(not(target_env = "msvc"))]
use tikv_jemallocator::Jemalloc; use tikv_jemallocator::Jemalloc;

View File

@ -62,7 +62,7 @@ impl SqliteRepo {
"writer", "writer",
settings, settings,
OpenFlags::SQLITE_OPEN_READ_WRITE | OpenFlags::SQLITE_OPEN_CREATE, OpenFlags::SQLITE_OPEN_READ_WRITE | OpenFlags::SQLITE_OPEN_CREATE,
1, 0,
2, 2,
false, false,
); );
@ -70,7 +70,7 @@ impl SqliteRepo {
"maintenance", "maintenance",
settings, settings,
OpenFlags::SQLITE_OPEN_READ_WRITE | OpenFlags::SQLITE_OPEN_CREATE, OpenFlags::SQLITE_OPEN_READ_WRITE | OpenFlags::SQLITE_OPEN_CREATE,
1, 0,
2, 2,
true, true,
); );
@ -1199,6 +1199,7 @@ pub fn build_pool(
.test_on_check_out(true) // no noticeable performance hit .test_on_check_out(true) // no noticeable performance hit
.min_idle(Some(min_size)) .min_idle(Some(min_size))
.max_size(max_size) .max_size(max_size)
.idle_timeout(Some(Duration::from_secs(10)))
.max_lifetime(Some(Duration::from_secs(30))) .max_lifetime(Some(Duration::from_secs(30)))
.build(manager) .build(manager)
.unwrap(); .unwrap();

View File

@ -19,7 +19,7 @@ PRAGMA foreign_keys = ON;
PRAGMA journal_size_limit = 32768; PRAGMA journal_size_limit = 32768;
PRAGMA temp_store = 2; -- use memory, not temp files PRAGMA temp_store = 2; -- use memory, not temp files
PRAGMA main.cache_size = 20000; -- 80MB max cache size per conn PRAGMA main.cache_size = 20000; -- 80MB max cache size per conn
pragma mmap_size = 17179869184; -- cap mmap at 16GB pragma mmap_size = 0; -- disable mmap (default)
"##; "##;
/// Latest database version /// Latest database version