store: synchronous=NORMAL (a newcomer's catch-up 2.4x faster); memory measured with a 50,000-listing database and 30 real nodes
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AeFqV96dVeBX94inzcgZKw
This commit is contained in:
@@ -157,8 +157,13 @@ starting a design-heavy item; see "Working with the owner".
|
|||||||
- **Public node memory** was measured (`cmd/allmende-conns`): 1000 inbound
|
- **Public node memory** was measured (`cmd/allmende-conns`): 1000 inbound
|
||||||
connections cost about 130 MB, 156 MB at the peak with 100 listings flooded
|
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
|
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,
|
`GOMEMLIMIT=400MiB` as a safety net. With a 269 MB database (50,000
|
||||||
relayed streams) and a node with a large database.
|
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`,
|
- **What the abuse limits do not cover** (`internal/p2p/guard.go`, `ipgate.go`,
|
||||||
`internal/api/ratelimit.go`): attackers with many real addresses, valid but
|
`internal/api/ratelimit.go`): attackers with many real addresses, valid but
|
||||||
unwanted records under the limits, and bans are per node and not shared
|
unwanted records under the limits, and bans are per node and not shared
|
||||||
|
|||||||
@@ -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
|
than these clients (identify, DHT queries, relayed streams), so the
|
||||||
manifest also sets `GOMEMLIMIT=400MiB`, which makes the Go runtime collect
|
manifest also sets `GOMEMLIMIT=400MiB`, which makes the Go runtime collect
|
||||||
harder as the limit nears instead of being killed by it.
|
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
|
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
|
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
|
node counts, per relaying peer and minute, the messages it gets (over 1200
|
||||||
|
|||||||
@@ -215,7 +215,7 @@ CREATE TABLE IF NOT EXISTS addresses (
|
|||||||
// Open opens (creating if needed) the database at path. Use ":memory:" for
|
// Open opens (creating if needed) the database at path. Use ":memory:" for
|
||||||
// an ephemeral store.
|
// an ephemeral store.
|
||||||
func Open(path string, opt Options) (*Store, error) {
|
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:" {
|
if path == ":memory:" {
|
||||||
dsn = "file::memory:?_pragma=busy_timeout(5000)"
|
dsn = "file::memory:?_pragma=busy_timeout(5000)"
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user