diff --git a/SPECS.md b/SPECS.md index f0da94c..1e6e7d2 100644 --- a/SPECS.md +++ b/SPECS.md @@ -157,8 +157,13 @@ starting a design-heavy item; see "Working with the owner". - **Public node memory** was measured (`cmd/allmende-conns`): 1000 inbound connections cost about 130 MB, 156 MB at the peak with 100 listings flooded to all of them, against the 512 MiB pod limit; the manifest sets - `GOMEMLIMIT=400MiB` as a safety net. Not measured: real peers (DHT queries, - relayed streams) and a node with a large database. + `GOMEMLIMIT=400MiB` as a safety net. With a 269 MB database (50,000 + listings) the same node idled at 53 MB, held 137 MB with 1000 connections and + peaked at 174 MB with 1000 connections plus 30 real nodes catching up. + Not measured: relayed streams (need a node behind a NAT). The run found that + a newcomer stored only ~137 listings/s with SQLite's `synchronous=FULL` and + its 2-minute sync cut-off left 18% of a 20k region for the next round; the + store now uses `synchronous=NORMAL` (63 s for all 20,140). - **What the abuse limits do not cover** (`internal/p2p/guard.go`, `ipgate.go`, `internal/api/ratelimit.go`): attackers with many real addresses, valid but unwanted records under the limits, and bans are per node and not shared diff --git a/docs/PROTOCOL.md b/docs/PROTOCOL.md index 5082e40..828e362 100644 --- a/docs/PROTOCOL.md +++ b/docs/PROTOCOL.md @@ -727,6 +727,26 @@ Findings (see "What is left" in SPECS.md for the open ones): than these clients (identify, DHT queries, relayed streams), so the manifest also sets `GOMEMLIMIT=400MiB`, which makes the Go runtime collect harder as the limit nears instead of being killed by it. + + **With a large database and real nodes** (50,000 listings, 269 MB database, + in the regions u0u and u1h, made with `allmende-load`): the same node idled + at 53 MB, so the database costs no resident memory to speak of. With 1000 + clients connected it held 137 MB. With 1000 clients connected *and* 30 real + `allmende run` processes (DHT on) catching up from it at the same time it + peaked at 174 MB, a third of the pod limit. About a minute after the + connections were opened the node's connection manager closed most of the + idle ones (970 connected, 154 left after 2.5 minutes) once real nodes had + joined, which is its job at the high-water mark. Relayed streams were not + tried (they need a node behind a NAT). + + The run also found a slow spot, not in the serving node but in the + newcomer: a catch-up is cut off after 2 minutes (`syncTimeout`), and with + SQLite's default `synchronous=FULL` a newcomer stored only about 137 + listings a second, so one sync from a region of 20,140 listings ended at + 16,438 and the rest waited for the next round. With `synchronous=NORMAL` + (WAL mode: no corruption on a crash, only the last few commits may be lost, + and listings come back from peers) the same sync took 63 s for all 20,140. + The store now uses `NORMAL`. 2. **Peer limits are crude.** The first run had no peer scoring: the attacker stayed connected to all 10 nodes it dialed after 500 bad messages. Now every node counts, per relaying peer and minute, the messages it gets (over 1200 diff --git a/internal/store/store.go b/internal/store/store.go index 68ce311..8d2cd21 100644 --- a/internal/store/store.go +++ b/internal/store/store.go @@ -215,7 +215,7 @@ CREATE TABLE IF NOT EXISTS addresses ( // Open opens (creating if needed) the database at path. Use ":memory:" for // an ephemeral store. func Open(path string, opt Options) (*Store, error) { - dsn := "file:" + path + "?_pragma=busy_timeout(5000)&_pragma=journal_mode(WAL)" + dsn := "file:" + path + "?_pragma=busy_timeout(5000)&_pragma=journal_mode(WAL)&_pragma=synchronous(NORMAL)" if path == ":memory:" { dsn = "file::memory:?_pragma=busy_timeout(5000)" }