efiten and Claude Opus 5.5
3e21b179ec
fix(server): drive the reach scan from the observations time window ( #2155 )
...
Refs #2146 (item: `/api/nodes/:pubkey/reach`).
## Situation
The reach scan joins `observations` to `transmissions` and filters on
`o.timestamp >= ?` plus one `o.path_json LIKE '%"XX"%'` per token. With
the planner statistics `ANALYZE` produces on a large database, SQLite
runs it as `SCAN t`: every transmission, with an index probe into
`observations` (`idx_observations_tx_ts`) per row. The cost is then the
size of `transmissions`, whatever node is asked for and whatever the
window.
## My change in this PR
`scanReachRows` uses `CROSS JOIN` for the transmissions join. In SQLite
that fixes the join order: `observations` is the outer loop, read
through `idx_observations_timestamp` for the window, and each row looks
up its transmission by primary key. Results are the same rows; it is
still an inner join.
The query text moves into `reachScanSQL(nTokens)`, so a test can inspect
the plan.
## Measurements
Read-only on a database with 18.3M observations and 1.5M transmissions
(Python `sqlite3` 3.45.1 on the host), 7-day window:
| node (rows returned) | `JOIN`, first run | `JOIN`, warm | `CROSS
JOIN`, both runs |
|---|---|---|---|
| busiest relay (54,387) | 10.29 s | 3.27 s | 1.95 s |
| quartile (3,913) | 3.16 s | 3.15 s | 1.81 s |
| median (1,310) | 3.17 s | 3.18 s | 1.82 s |
| a repeater reported as timing out in the browser (34,209) | 14.11 s |
3.25 s | 1.93 s |
On that instance `/api/nodes/:pubkey/reach` reports p95 188.6 s and max
192.6 s over 34 calls in `/api/perf`; a single uncached call from the
host took 3.4 to 3.6 s, so most of that is waiting for the 2 build slots
and the read pool.
On a staging instance (smaller database), with unique cache keys and
`days` 6 or 7, one cycle per build after the ingestor's startup
`ANALYZE` had finished:
| | without this PR | with this PR |
|---|---|---|
| sequential, 12 calls, p50 | 3402-3801 ms | 2078-2467 ms |
| 2 concurrent clients (= `reachMaxConcurrentBuilds`), p50 / p95 |
3575-4087 / 4049-5291 ms | 2271-2462 / 2814-2928 ms |
| calls completed in 120 s | 58-68 | 96-101 |
The staging builds also contain #2147 .
## Verification
- `TestReachScanStartsFromObservationsTimeIndex` creates the two
production indexes, loads the `sqlite_stat1` values from the
18.3M-observation database, and checks that the plan starts with `SEARCH
o USING INDEX idx_observations_timestamp`. With the old `JOIN` it fails
with the production plan (`SCAN t`, then `SEARCH o USING INDEX
idx_observations_tx_ts`).
- The existing reach tests (`TestScanReachRows_DecodesRows`,
`TestScanReachRows_CapTruncates`, attribution tests) pass unchanged.
- `cmd/server`: `go test ./...` green.
## Not in this PR
- The scan still reads every observation in the window and applies the
`LIKE` per row, so its cost grows with the window and with traffic.
Removing the scan needs an index on hop tokens (for example a table the
ingestor maintains). I have not measured what that would cost in
storage.
- The build-slot limit (2) and the 5-minute cache are unchanged.
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com >
2026-10-09 21:20:34 +02:00
..
2026-04-21 09:09:39 -07:00
2026-10-08 22:16:49 +02:00
2026-10-08 22:16:49 +02:00
2026-10-07 09:25:29 +02:00
2026-10-07 09:25:29 +02:00
2026-10-08 21:38:30 +02:00
2026-10-08 21:38:30 +02:00
2026-10-08 22:02:39 +02:00
2026-10-08 21:38:30 +02:00
2026-10-08 21:38:30 +02:00
2026-10-08 21:38:30 +02:00
2026-10-03 12:16:55 +02:00
2026-04-03 13:51:13 -07:00
2026-10-03 12:16:55 +02:00
2026-10-03 12:16:55 +02:00
2026-10-03 12:16:55 +02:00
2026-10-03 12:16:55 +02:00
2026-09-22 07:55:37 +02:00
2026-05-21 14:00:15 -07:00
2026-09-22 07:55:37 +02:00
2026-09-13 19:59:37 +02:00
2026-09-13 19:59:37 +02:00
2026-09-04 16:02:59 +02:00
2026-09-03 18:52:03 +02:00
2026-10-07 09:25:29 +02:00
2026-10-08 22:02:39 +02:00
2026-10-08 22:02:39 +02:00
2026-10-08 21:38:30 +02:00
2026-10-07 09:25:29 +02:00
2026-10-08 21:38:30 +02:00
2026-10-08 21:38:30 +02:00
2026-10-08 22:02:39 +02:00
2026-10-08 22:02:39 +02:00
2026-10-07 09:25:29 +02:00
2026-10-07 11:20:44 +02:00
2026-10-08 22:16:49 +02:00
2026-10-08 22:16:49 +02:00
2026-10-07 09:25:29 +02:00
2026-10-07 11:20:44 +02:00
2026-05-03 17:56:42 -07:00
2026-05-03 17:56:42 -07:00
2026-10-08 16:26:10 +02:00
2026-09-16 09:02:13 +02:00
2026-05-18 22:51:23 -07:00
2026-05-18 22:51:23 -07:00
2026-05-18 22:51:23 -07:00
2026-06-27 22:03:05 -07:00
2026-06-04 03:21:26 -07:00
2026-09-03 18:52:03 +02:00
2026-10-09 19:58:42 +02:00
2026-10-09 19:58:42 +02:00
2026-06-04 13:14:09 +00:00
2026-09-03 18:52:03 +02:00
2026-09-03 18:52:03 +02:00
2026-04-20 21:46:34 -07:00
2026-10-05 20:32:40 +02:00
2026-09-13 20:36:34 +02:00
2026-09-03 18:52:03 +02:00
2026-05-25 22:16:14 -07:00
2026-06-07 03:43:29 -07:00
2026-09-16 09:02:13 +02:00
2026-09-16 09:02:13 +02:00
2026-09-03 18:52:03 +02:00
2026-10-03 12:16:55 +02:00
2026-06-03 13:58:04 -07:00
2026-06-06 22:45:05 -07:00
2026-09-02 09:50:18 +02:00
2026-09-03 18:52:03 +02:00
2026-09-02 09:50:18 +02:00
2026-05-18 12:27:44 -07:00
2026-09-03 18:52:03 +02:00
2026-09-13 19:59:37 +02:00
2026-05-21 14:00:15 -07:00
2026-05-21 11:39:49 -07:00
2026-05-21 11:39:49 -07:00
2026-05-21 11:39:49 -07:00
2026-09-03 18:52:03 +02:00
2026-10-08 15:56:42 +02:00
2026-06-06 22:45:05 -07:00
2026-10-08 21:51:42 +02:00
2026-05-30 13:22:41 -07:00
2026-05-30 13:22:41 -07:00
2026-05-30 13:22:41 -07:00
2026-06-19 11:37:16 -07:00
2026-06-27 22:03:05 -07:00
2026-06-27 22:03:05 -07:00
2026-10-09 19:58:42 +02:00
2026-06-04 14:41:00 -07:00
2026-09-02 13:10:43 +00:00
2026-09-23 10:05:59 +02:00
2026-10-09 19:58:42 +02:00
2026-10-09 19:58:42 +02:00
2026-06-12 19:10:44 -07:00
2026-05-15 22:34:21 -07:00
2026-09-03 18:52:03 +02:00
2026-09-03 18:52:03 +02:00
2026-09-22 23:55:55 +02:00
2026-09-22 23:55:55 +02:00
2026-05-05 01:16:57 -07:00
2026-09-03 18:52:03 +02:00
2026-06-29 15:53:59 -07:00
2026-09-17 21:58:34 +02:00
2026-04-16 00:09:36 -07:00
2026-09-20 15:12:36 +02:00
2026-09-17 21:58:16 +02:00
2026-06-04 16:27:48 -07:00
2026-05-05 01:58:52 -07:00
2026-05-19 23:53:41 -07:00
2026-03-31 01:10:56 -07:00
2026-09-05 09:57:44 +02:00
2026-10-08 21:51:42 +02:00
2026-10-07 09:25:29 +02:00
2026-06-27 22:03:05 -07:00
2026-09-04 15:15:16 +02:00
2026-09-04 15:15:16 +02:00
2026-09-03 18:52:03 +02:00
2026-06-07 09:28:51 -07:00
2026-04-03 13:11:59 -07:00
2026-06-19 11:37:16 -07:00
2026-09-16 09:02:13 +02:00
2026-06-11 10:10:12 -07:00
2026-06-11 10:10:12 -07:00
2026-05-15 16:21:14 +00:00
2026-05-16 19:55:00 +00:00
2026-09-03 18:52:03 +02:00
2026-05-15 20:24:55 -07:00
2026-05-15 22:46:25 -07:00
2026-09-16 09:02:13 +02:00
2026-09-06 21:00:44 +02:00
2026-09-03 18:52:03 +02:00
2026-09-16 09:02:13 +02:00
2026-05-21 14:00:15 -07:00
2026-10-09 19:58:42 +02:00
2026-05-02 20:35:15 -07:00
2026-05-17 16:13:11 +00:00
2026-05-19 08:08:28 -07:00
2026-05-18 23:19:27 -07:00
2026-09-16 09:02:13 +02:00
2026-06-25 05:05:46 -07:00
2026-09-16 09:02:13 +02:00
2026-06-11 07:38:36 -07:00
2026-09-03 18:52:03 +02:00
2026-06-11 07:38:36 -07:00
2026-06-06 22:44:59 -07:00
2026-09-16 09:02:13 +02:00
2026-09-16 09:02:13 +02:00
2026-09-16 09:02:13 +02:00
2026-09-16 09:02:13 +02:00
2026-10-07 09:25:29 +02:00
2026-10-07 09:25:29 +02:00
2026-10-07 09:25:29 +02:00
2026-09-03 18:52:03 +02:00
2026-09-16 09:02:13 +02:00
2026-09-16 09:02:13 +02:00
2026-09-02 10:27:48 +02:00
2026-06-30 15:16:31 -07:00
2026-06-12 08:11:02 -07:00
2026-09-02 10:27:48 +02:00
2026-10-08 15:58:07 +02:00
2026-09-16 09:02:13 +02:00
2026-05-03 08:56:09 -07:00
2026-05-21 14:00:15 -07:00
2026-09-16 09:02:13 +02:00
2026-09-03 18:52:03 +02:00
2026-04-02 23:45:03 -07:00
2026-09-03 18:52:03 +02:00
2026-09-03 18:52:03 +02:00
2026-05-29 02:42:21 -07:00
2026-05-29 02:42:21 -07:00
2026-05-29 02:42:21 -07:00
2026-05-29 02:42:21 -07:00
2026-05-16 10:14:44 -07:00
2026-09-02 11:07:18 +02:00
2026-09-03 18:52:03 +02:00
2026-09-16 09:02:13 +02:00
2026-09-13 19:59:56 +02:00
2026-09-16 09:02:13 +02:00
2026-05-19 23:53:41 -07:00
2026-05-05 01:41:00 -07:00
2026-05-05 01:41:00 -07:00
2026-09-03 18:52:03 +02:00
2026-09-13 21:09:51 +02:00
2026-09-22 07:55:37 +02:00
2026-09-22 07:55:37 +02:00
2026-09-13 19:59:56 +02:00
2026-09-13 19:59:56 +02:00
2026-09-16 09:02:13 +02:00
2026-06-09 03:23:48 -07:00
2026-10-08 16:26:15 +02:00
2026-09-16 09:02:13 +02:00
2026-10-09 21:20:34 +02:00
2026-10-09 21:20:34 +02:00
2026-06-19 11:37:16 -07:00
2026-06-19 11:37:16 -07:00
2026-09-23 09:45:18 +02:00
2026-05-18 09:22:27 -07:00
2026-09-03 18:52:03 +02:00
2026-10-08 22:02:39 +02:00
2026-10-08 22:02:39 +02:00
2026-10-08 22:02:39 +02:00
2026-10-08 22:02:39 +02:00
2026-10-08 22:02:39 +02:00
2026-10-08 22:02:39 +02:00
2026-10-08 22:02:39 +02:00
2026-10-08 22:02:39 +02:00
2026-04-03 13:33:26 -07:00
2026-09-22 11:08:17 +02:00
2026-09-03 18:52:03 +02:00
2026-09-02 11:07:08 +02:00
2026-09-03 18:52:03 +02:00
2026-09-02 09:50:26 +02:00
2026-05-29 01:08:12 -07:00
2026-05-29 01:08:12 -07:00
2026-05-29 02:42:21 -07:00
2026-05-29 02:42:21 -07:00
2026-09-03 18:52:03 +02:00
2026-09-03 18:52:03 +02:00
2026-06-19 11:37:16 -07:00
2026-07-07 00:12:44 -07:00
2026-09-03 18:52:03 +02:00
2026-10-08 22:16:49 +02:00
2026-09-02 18:34:59 +02:00
2026-05-17 16:13:11 +00:00
2026-05-25 22:32:00 -07:00
2026-06-04 23:48:47 -07:00
2026-10-05 20:32:40 +02:00
2026-05-15 22:46:28 -07:00
2026-05-15 22:46:28 -07:00
2026-05-15 22:46:28 -07:00
2026-05-15 22:46:28 -07:00
2026-05-15 22:46:28 -07:00
2026-09-02 09:50:09 +02:00
2026-09-03 18:52:03 +02:00
2026-10-08 14:34:31 +02:00
2026-10-08 14:34:31 +02:00
2026-10-08 14:34:31 +02:00
2026-09-02 14:34:20 +02:00
2026-10-08 14:34:31 +02:00
2026-10-09 19:58:42 +02:00
2026-09-30 11:39:25 +02:00
2026-10-09 19:58:42 +02:00
2026-09-30 11:39:25 +02:00
2026-09-30 11:39:25 +02:00
2026-09-30 11:39:25 +02:00
2026-09-03 18:52:03 +02:00
2026-09-03 18:52:03 +02:00
2026-05-08 16:29:23 -07:00
2026-05-08 16:29:23 -07:00
2026-06-07 09:28:51 -07:00
2026-05-05 17:56:56 -07:00
2026-09-16 09:02:13 +02:00
2026-04-01 19:26:11 -07:00
2026-06-06 22:45:05 -07:00
2026-05-15 09:16:39 -07:00
2026-09-16 09:02:13 +02:00
2026-10-08 21:51:42 +02:00
2026-10-08 21:51:42 +02:00
2026-10-08 21:51:42 +02:00
2026-10-07 09:25:29 +02:00
2026-06-27 22:03:05 -07:00
2026-06-27 22:03:05 -07:00
2026-05-03 19:50:01 -07:00
2026-10-05 23:42:07 +02:00
2026-10-05 23:42:07 +02:00
2026-10-03 12:16:55 +02:00
2026-06-22 10:07:49 -07:00
2026-10-03 12:16:55 +02:00
2026-05-21 11:39:43 -07:00
2026-05-20 20:57:02 -07:00
2026-09-03 18:52:03 +02:00
2026-05-28 15:01:58 -07:00
2026-10-08 14:34:31 +02:00
2026-06-06 20:46:42 -07:00
2026-06-06 20:46:42 -07:00
2026-07-08 15:13:39 -07:00
2026-09-02 18:34:59 +02:00
2026-09-06 21:00:44 +02:00
2026-05-20 20:57:02 -07:00
2026-10-08 14:34:31 +02:00
2026-10-07 09:25:29 +02:00
2026-05-15 16:21:14 +00:00
2026-05-15 09:16:39 -07:00
2026-09-03 18:52:03 +02:00
2026-09-03 18:52:03 +02:00
2026-09-16 09:02:13 +02:00
2026-10-09 19:58:42 +02:00
2026-10-09 19:58:42 +02:00
2026-09-13 20:37:14 +02:00
2026-09-13 20:37:14 +02:00
2026-10-04 22:11:34 +02:00
2026-10-04 22:11:34 +02:00
2026-05-18 07:36:28 -07:00
2026-05-03 17:56:12 -07:00
2026-09-03 18:52:03 +02:00
2026-09-04 16:02:59 +02:00
2026-10-09 19:58:42 +02:00
2026-09-03 18:52:03 +02:00
2026-06-19 11:37:16 -07:00
2026-10-04 17:15:50 +02:00
2026-10-04 17:15:50 +02:00
2026-06-19 11:37:16 -07:00
2026-06-19 11:37:16 -07:00
2026-05-15 16:21:14 +00:00
2026-09-19 11:44:47 +02:00
2026-09-19 11:44:47 +02:00
2026-09-11 15:07:31 +02:00
2026-09-11 15:07:31 +02:00
2026-09-19 11:44:47 +02:00
2026-09-09 17:58:09 +02:00
2026-09-10 22:30:24 +02:00
2026-10-07 11:20:44 +02:00
2026-10-07 11:20:44 +02:00
2026-10-07 11:20:44 +02:00
2026-10-07 11:20:44 +02:00
2026-05-03 17:40:54 -07:00
2026-06-03 13:58:04 -07:00
2026-06-30 18:21:21 -07:00
2026-04-20 23:10:33 -07:00
2026-10-09 19:58:42 +02:00
2026-10-09 19:58:42 +02:00
2026-10-09 19:58:42 +02:00
2026-04-21 09:09:39 -07:00
2026-10-09 19:58:42 +02:00
2026-05-29 02:42:21 -07:00
2026-06-06 21:59:23 -07:00
2026-05-03 17:41:22 -07:00
2026-05-03 17:41:22 -07:00
2026-09-16 09:02:13 +02:00
2026-09-17 21:58:16 +02:00
2026-06-27 22:03:05 -07:00
2026-09-02 18:34:59 +02:00
2026-10-08 22:02:39 +02:00
2026-06-27 22:03:05 -07:00
2026-06-27 22:03:05 -07:00
2026-06-27 22:03:05 -07:00
2026-06-27 22:03:05 -07:00
2026-10-08 22:16:49 +02:00
2026-10-08 22:16:49 +02:00
2026-10-08 22:16:49 +02:00
2026-10-08 22:16:49 +02:00
2026-10-08 22:16:49 +02:00
2026-06-29 05:48:58 -07:00
2026-09-13 19:59:18 +02:00
2026-09-13 19:59:18 +02:00
2026-09-06 21:11:29 +02:00
2026-09-06 21:11:29 +02:00
2026-09-02 14:21:42 +02:00