mirror of
https://github.com/aziascreations/BakaShrot.git
synced 2026-11-23 20:58:46 +01:00
e044fcf359
The rewrite's plan and decisions are in revamp.md. Steps 0 to 10 are done: the workspace and checks, bakashrot-proto, bakashrot-pki and bakashrot-cert, bakashrot-config, bakashrot-storage (schema v9), the server and the client library (every request but replication's, attachments and retention included), the C DLL with its C, PureBasic and Python bindings, and the bakashrot tool. Step 11 (replication) is next. OldSource/ is the old implementation, kept building and passing as the reference. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RwFeVTGs2SsufaH6zquzcb
183 lines
12 KiB
Markdown
183 lines
12 KiB
Markdown
# Benchmark results, 2026-11-07
|
|
|
|
`Bench-Replication.ps1` with its defaults: 4 servers in a Y (a hub linked to
|
|
3 leaves), 5-10 nodes pushing to each, ~200-byte JSON messages, 30 s per
|
|
stage, `PeerSyncInterval = 5`, `PeerBatchSize = 100`. All on one machine
|
|
(i5-13500, 16 GB, NVMe), PureBasic 5.73 x64 unless said otherwise, SQLite
|
|
3.54.1. Table made with `Compare-Runs.ps1`.
|
|
|
|
| Version | What changed |
|
|
|---|---|
|
|
| Before | Rollback journal, a sync to disk per push, every wait a `Delay(5)` / `Delay(1)` loop |
|
|
| WAL + wake-ups | WAL with `synchronous = NORMAL`, threads woken by an event / `select()`, a write mutex instead of SQLite's busy-wait |
|
|
| + grouping | Pushes arriving together share one transaction (group commit) |
|
|
| + no per-push log | The `PrintN()` per push / read / query removed (`#BakaShrot_Net_LogRequests`) |
|
|
| + prepared/cache/checkpoints/heads | One writer connection with prepared statements (SQLite's own API), next ids cached in memory, WAL checkpoints in a background thread, the sync state from `node_heads` (`Server/Storage/Writer.pbi`) |
|
|
| same on PB 6.40 C | The same code, built with PureBasic 6.40's C backend and `/OPTIMIZER` (the load generator too) |
|
|
|
|
| | Before | WAL + wake-ups | + grouping | + no per-push log | + prepared/cache/checkpoints/heads (5.73) | same on PB 6.40 C |
|
|
|---|---|---|---|---|---|---|
|
|
| **Push ceiling**, msg/s, 5 nodes/server | 958 | 5,771 | 5,709 | 25,681 | 33,522 | 37,162 |
|
|
| **Push ceiling**, msg/s, 10 nodes/server | 904 | 5,726 | 5,814 | 25,707 | 34,345 | 38,358 |
|
|
| Pushed of 2,000 offered (10 x 50) | 924 | 1,999 | 2,000 | 2,000 | 2,000 | 1,999 |
|
|
| Pushed of 4,000 offered (10 x 100) | 899 | 4,000 | 4,000 | 4,000 | 4,000 | 4,000 |
|
|
| Push p50 / p99 ms, 10 x 50 | 18.0 / 491.5 | 0.4 / 5.1 | 0.5 / 7.2 | 0.5 / 13.6 | 0.3 / 0.8 | 0.2 / 0.9 |
|
|
| Push p50 / p99 / max ms, flat out (10 nodes) | 18.0 / 574.9 / 2,642 | 5.5 / 25.2 / 193 | 5.6 / 23.1 / 56 | 0.9 / 16.5 / 149 | 0.5 / 2.8 / 854 | 0.5 / 2.5 / 1,485 |
|
|
| Replication lag, s of pushes, flat out | 8.9 | 5.1 | 5.0 | 8.9 | 9.9 | 8.3 |
|
|
| Drain after the push, s, flat out | 6.2 | 5.8 | 5.8 | 10.3 | 11.3 | 11.3 |
|
|
| Server CPU, % of a core, flat out (avg of the 4) | 45 | 65 | 66 | 130 | 120 | 121 |
|
|
| Machine CPU %, flat out | 41 | 33 | 34 | 67 | 65 | 65 |
|
|
| Hub RAM, working set MB, max | 34.6 | 42.9 | 44.6 | 45.2 | 38.8 | 40.1 |
|
|
| Rows per server at the end | 1,021,883 | 1,024,025 | 1,024,025 | 1,887,117 | 2,389,201 | 2,619,806 |
|
|
| Query: latest message, ms (1M rows) | 5.9 | 0.5 | 0.5 | 0.1 | 0.1 | 0.1 |
|
|
| Query: last 50 of a node, ms | 5.8 | 1.0 | 1.0 | 0.7 | 0.8 | 0.7 |
|
|
| Query: sync state (GROUP BY all), ms | 78.0 | 73.1 | 72.1 | 131.9 | 166.7 | 184.1 |
|
|
| Query: sync state from node_heads (what check-ins use now), ms | - | - | - | - | 0.6 | 0.5 |
|
|
| Query: JSON count over all rows, ms | 473.6 | 475.1 | 475.3 | 857.5 | 1,080.7 | 1,199.4 |
|
|
| Query: JSON aggregate over all rows, ms | 1,647.8 | 1,575.8 | 1,533.9 | 2,800.2 | 3,974.2 | 4,371.2 |
|
|
| **Mixed:** pushed of 400 msg/s with a query loop | 323 | 396 | 397 | 397 | 392 | 396 |
|
|
| Mixed: push p99 / max ms | 820.2 / 5,119 | 0.7 / 17 | 7.9 / 17 | 18.0 / 30 | 1.2 / 17 | 0.9 / 17 |
|
|
| Mixed: failed pushes | 1 | 0 | 0 | 0 | 0 | 0 |
|
|
| Mixed: JSON count over all rows, ms, under load | 545.4 | 502.3 | 506.5 | 925.0 | 1,148.2 | 1,265.6 |
|
|
| Mixed: latest message, ms, under load | 12.0 | 0.2 | 0.2 | 0.1 | 0.2 | 0.2 |
|
|
|
|
The full-table scans grow with the data, and the later runs' flat-out stages
|
|
wrote more of it: 1.9M, 2.4M, then 2.6M rows per server instead of ~1.02M.
|
|
Per row they cost the same (~0.45 ms per 1,000 rows for the JSON count).
|
|
PB 6.40 doesn't change them either, SQLite does the scanning.
|
|
|
|
## What limited each version
|
|
|
|
- **Before:** the sync to disk on every push, ~250 commits/s per database.
|
|
- **WAL + wake-ups:** not the database anymore. The `PrintN()` logging every
|
|
push takes ~0.4 ms and serializes every thread behind it: ~2,400 pushes/s
|
|
per server whatever the number of nodes, with the server mostly idle
|
|
(measured on a single server: the listener asleep in `select()` 91 % of
|
|
the time, the writes busy 33 %, 0.14 ms per push).
|
|
- **+ grouping:** same cap, so no gain yet: the pushes never piled up
|
|
behind the write mutex (1.0 per transaction on average). It did cut the
|
|
worst push from 193 to 56 ms.
|
|
- **+ no per-push log:** a single server went from ~2,400 to ~12,000
|
|
pushes/s, and grouping now kicks in: 2.5 pushes per transaction at 5
|
|
nodes, ~5-9 at 10-20, the database busy 70-90 % of the time at 0.07-0.11
|
|
ms per push. The cluster tops out at ~25,700 msg/s with the machine at
|
|
67 % CPU (the load generator itself ~85 % of a core). Next limits: each
|
|
server's write section, and running everything on one machine.
|
|
- **+ prepared/cache/checkpoints/heads:** ~25,700 -> ~34,300 msg/s. A push
|
|
costs ~0.05 ms of write time instead of 0.07-0.11, no statement is
|
|
prepared again, no MAX() per push. The p99 at moderate load is back under
|
|
1 ms (13.6 -> 0.8 ms at 10 x 50, 18 -> 1.2 ms in the mixed stage): the
|
|
checkpoints were what held the writes up. Flat out, the WAL grows faster
|
|
than the background checkpoints keep up with, so the writer checkpoints by
|
|
itself past 10,000 frames, and the worst push goes from 149 to 854 ms. The
|
|
sync state every check-in reads: 0.5 ms instead of a 167 ms GROUP BY.
|
|
- **Same on PB 6.40 C:** ~34,300 -> ~38,400 msg/s (+12 %), the same
|
|
latencies, slightly less lag. Both the servers and the load generator are
|
|
built with it, so part of it may be the generator. The SQLite side (the
|
|
write section, the queries) is the same DLL either way.
|
|
|
|
## Notes
|
|
|
|
- Ids checked after the last four runs: every node 1..N, no gap, no
|
|
duplicate, on all 4 servers, and `node_heads` exactly matching `data`.
|
|
- **p99 at moderate load went up with grouping** (0.7 -> 8-18 ms), and came
|
|
back down once the checkpoints left the write path (see above).
|
|
- Replication keeps up at every load: it drains within ~11 s even after
|
|
38,000 msg/s. The lag is the check-in wait (`PeerSyncInterval`) plus the
|
|
hub relaying to its leaves, see `Design/Suggestions.md` #2 to lower it.
|
|
- The worst push flat out (0.85-1.5 s) is the writer's backstop checkpoint,
|
|
see `Design/Suggestions.md` #3.
|
|
|
|
## Names and wildcards (evening)
|
|
|
|
Same benchmark, PureBasic 5.73, after topics and nodes got names, strict
|
|
"named on both sides" replication, and wildcards, run with `-Names
|
|
Wildcard`: each server only names its own nodes, and takes everyone else's
|
|
by `AcceptNodes = n*`, so each server adds the other servers' 30 nodes
|
|
under ids of its own (counting down from 65535), and the hub relays them on
|
|
by name. The worst case for the new code: every batch goes through a name
|
|
lookup and every check-in through the patterns. Run `20261107-220433`,
|
|
compared with `Compare-Runs.ps1` (`comparison.md` in the run's folder).
|
|
|
|
| | Before names (5.73) | Before names (PB 6.40 C) | Names + wildcards (5.73) |
|
|
|---|---|---|---|
|
|
| **Push ceiling**, msg/s, 5 nodes/server | 33,522 | 37,162 | 35,124 |
|
|
| **Push ceiling**, msg/s, 10 nodes/server | 34,345 | 38,358 | 32,846 |
|
|
| Push p50 / p99 ms, 10 x 50 | 0.3 / 0.8 | 0.2 / 0.9 | 0.3 / 1.1 |
|
|
| Push p50 / p99 / max ms, flat out (10 nodes) | 0.5 / 2.8 / 854 | 0.5 / 2.5 / 1,485 | 0.6 / 3.2 / 1,503 |
|
|
| Replication lag, s of pushes, flat out | 9.9 | 8.3 | 8.6 |
|
|
| Drain after the push, s, flat out | 11.3 | 11.3 | 11.8 |
|
|
| Server CPU, % of a core, flat out (avg of the 4) | 120 | 121 | 129 |
|
|
| Hub RAM, working set MB, max | 38.8 | 40.1 | 39.3 |
|
|
| Rows per server at the end | 2,389,201 | 2,619,806 | 2,395,509 |
|
|
| Query: sync state from node_heads, ms | 0.6 | 0.5 | 0.7 |
|
|
| Query: JSON count over all rows, ms | 1,080.7 | 1,199.4 | 1,105.8 |
|
|
| **Mixed:** pushed of 400 msg/s with a query loop | 392 | 396 | 397 |
|
|
| Mixed: push p99 / max ms | 1.2 / 17 | 0.9 / 17 | 0.9 / 18 |
|
|
| Failed pushes, refusals between servers | 0 | 0 | 0 |
|
|
|
|
- **Same speed, within run-to-run noise.** Flat out at 10 nodes, the same
|
|
build gave 32,976 and 37,003 msg/s in two ramp-only runs (declared names)
|
|
earlier this evening: ±6 % between runs is usual on this machine. The push
|
|
path itself didn't change, only the check-ins and the batches' first
|
|
lines.
|
|
- **Server CPU +7 %** flat out (129 vs 120 % of a core), the name lookups
|
|
and the bigger sync states, possibly part of the noise too.
|
|
- **Replication** keeps up at every load and drains in the same time; no
|
|
batch refused anywhere, every server ended with the same rows.
|
|
- **Measuring changed slightly:** the lag monitor now asks for each node's
|
|
latest id by name through the `messages` view (ids differ between
|
|
servers in this mode), the old runs asked `data` by id. Both are index
|
|
lookups.
|
|
|
|
## Big messages, no JSON check on push, is_json clause (2026-11-08)
|
|
|
|
Same setup as the evening run (`-Names Wildcard`), after: packets up to
|
|
16 MB once authenticated (new inbox: growth by doubling, a read offset),
|
|
replication batches still ~64 KB, pushes no longer checked to be JSON
|
|
(`ParseJSON()` gone from the push path, `is_json` flags them), and
|
|
`is_json = 1` added to the JSON queries.
|
|
|
|
| | Before names (5.73) | Before names (PB 6.40 C) | Names + wildcards (5.73) | Big messages, no JSON check, is_json clause (5.73) |
|
|
|---|---|---|---|---|
|
|
| **Push ceiling**, msg/s, 5 nodes/server | 33,522 | 37,162 | 35,124 | **38,199** |
|
|
| **Push ceiling**, msg/s, 10 nodes/server | 34,345 | 38,358 | 32,846 | **37,745** |
|
|
| Pushed of 2,000 offered (10 x 50) | 2,000 | 1,999 | 1,999 | 2,001 |
|
|
| Pushed of 4,000 offered (10 x 100) | 4,000 | 4,000 | 4,000 | 4,000 |
|
|
| Push p50 / p99 ms, 10 x 50 | 0.3 / 0.8 | 0.2 / 0.9 | 0.3 / 1.1 | 0.3 / 1.0 |
|
|
| Push p50 / p99 / max ms, flat out (10 nodes) | 0.5 / 2.8 / 854 | 0.5 / 2.5 / 1,485 | 0.6 / 3.2 / 1,503 | 0.5 / 2.9 / 822 |
|
|
| Replication lag, s of pushes, flat out | 9.9 | 8.3 | 8.6 | 10.5 |
|
|
| Drain after the push, s, flat out | 11.3 | 11.3 | 11.8 | 13.8 |
|
|
| Server CPU, % of a core, flat out (avg of the 4) | 120 | 121 | 129 | 120 |
|
|
| Machine CPU %, flat out | 65 | 65 | 69 | 66 |
|
|
| Hub RAM, working set MB, max | 38.8 | 40.1 | 39.3 | 42.8 |
|
|
| Rows per server at the end | 2,389,201 | 2,619,806 | 2,395,509 | 2,628,001 |
|
|
| Query: latest message, ms | 0.1 | 0.1 | 0.1 | 0.1 |
|
|
| Query: last 50 of a node, ms | 0.8 | 0.7 | 0.8 | 0.8 |
|
|
| Query: sync state (GROUP BY all), ms | 166.7 | 184.1 | 170.5 | 187.9 |
|
|
| Query: sync state from node_heads (what check-ins use now), ms | 0.6 | 0.5 | 0.7 | 0.6 |
|
|
| Query: JSON count over all rows, ms | 1,080.7 | 1,199.4 | 1,105.8 | 1,233.6 |
|
|
| Query: JSON aggregate over all rows, ms | 3,974.2 | 4,371.2 | 4,084.2 | 4,464.4 |
|
|
| Same, per million rows: sync state / JSON count / JSON aggregate, ms | 69.8 / 452 / 1,663 | 70.3 / 458 / 1,669 | 71.2 / 462 / 1,705 | 71.5 / 469 / 1,699 |
|
|
| **Mixed:** pushed of 400 msg/s with a query loop | 392 | 396 | 397 | 384 |
|
|
| Mixed: push p99 / max ms | 1.2 / 17 | 0.9 / 17 | 0.9 / 18 | 1.0 / 15 |
|
|
| Mixed: failed pushes | 0 | 0 | 0 | 0 |
|
|
| Mixed: JSON count over all rows, ms, under load | 1,148.2 | 1,265.6 | 1,179.5 | 1,313.4 |
|
|
| Mixed: latest message, ms, under load | 0.2 | 0.2 | 0.2 | 0.2 |
|
|
|
|
Runs: `20261107-140556`, `20261107-141735`, `20261107-220433`, `20261108-033149` (all 4 servers in a Y, ~200-byte messages; the last two with `-Names Wildcard`). Query times are from the end of each run, so they scale with its row count: compare the per-million row.
|
|
|
|
- **Push ceiling up 9-15 %** (38,199 / 37,745 msg/s), the best yet on 5.73,
|
|
for the same server CPU (120 % of a core). Likely mostly `ParseJSON()`
|
|
leaving the push path, though runs of one build have spread 33-37k.
|
|
- **Lag and drain** are a bit higher in seconds, with 15 % more messages
|
|
pushed per second to relay (397,066 messages behind at most, vs 282,621).
|
|
- **The `is_json = 1` clause costs nothing measurable:** per million rows,
|
|
the JSON count is 469 ms vs 462, the aggregate 1,699 vs 1,705.
|
|
- **Mixed: 384 of 400 msg/s pushed** (397 before), with no failures and a
|
|
lower p99. The bench's pushers are paced by its own loop, and this run's
|
|
database was 10 % bigger, so the query loop beside them was slower. Worth
|
|
a second run before reading anything into it.
|
|
- 0 refused, failed or "too big" in the server logs, 2,628,001 rows on all
|
|
4 servers.
|