ac4af582301a4e8a29245dbba767eba31334ddf9
11
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
e94fb18b8f |
usage: a page's cells and the heatmap's days read strings where they were decoded (#2278)
partsOf, cellsBefore and heatDaysOf read each chunk through a chunkRows that copied the chunk's whole string section first. What they keep is unique's handles (a cell), a date made by Format and numbers (a day), so the copy was thrown away chunk by chunk. They now read through lentRows(), as newest and the Codex readers already do. Run on mote: - go test ./internal/usage/ -count=1 -timeout 45m: ok (40s). - -race -count=3 on TestPartsReadStringsWhereDecoded, TestRowBufferKeptPastCollections, TestRequestCells*, *Heat*, *PageSplit*: ok. - TestPartsReadStringsWhereDecoded (new): 8 packed chunks, 1.1MB of strings. With the three sites put back to `var rows chunkRows` by sed it is red: partsOf 1,188,672 bytes, cellsBefore 1,197,568, heatDaysOf 1,187,616. Green with the change; the cells' names and the days' counts are right after the buffer was decoded over again. - Real history copy (66GB, ~12k session files), magpie web in a sandbox HOME, heap profile 40s after start, two rounds each: unpackReusing 183MB / 174MB before, 106MB / 113MB after; partsOf 76MB / 78MB before, 55MB / 56MB after. A warm poll of every page reads cached parts and is unchanged. Not tried: the Windows and Linux boxes (no OS-specific code). |
||
|
|
4023a2e999 |
usage: a page's newest rows are kept on each chunk's part, not decoded again for every page (#2278)
A Usage page read again after a call picked its newest rows by decoding the few newest chunks again, then decoded them once more for the rows themselves (rowsOf). Under an agent at work that is the long session's own file among them (57k calls): in the writer bench (a call every 3s, the GUI's 10 endpoints polled) pairedRows.newest was 392 MB of 90s. newest now keeps what a chunk gave on the chunk's part: its newest rows the filter keeps, up to take, each with its row (strings copied, as the chunk is decoded lent), and whether that was all of them. The part is the cell cache's: its chunk serial and pairing sig, under the page's period and filter, dropped with the rest when the clears, names or prices change (meta). A page that wants more rows than the chunk gave reads it again. The page's rows come from newest, and rowsOf is not called for them. Run at the pushed head, on mote: - TestNewestKeptOnPart: pages of take 2, 2, 1, 4, 4, 6 decode 1, 0, 0, 2, 0, 0 chunks with the same refs and rows; new parts decode again; rows read stay as they were after the chunks are decoded again over the lent block. Broken by hand, red each way: the kept rows never used; the take check dropped; the lent strings not copied. - go test ./internal/usage/ ./internal/usageapi/: ok - go vet -tags nogui, GOOS linux, windows, darwin: ok - Writer bench, second start of each binary, 90s, load ~25: newest 392 MB and rowsOf 88 MB (v0.1.2190) -> 6 MB and none. Everything allocated: 3698 MB with only the refs kept -> 2742 MB. fp_peak 312 -> 333 MB, late GCs 46 -> 26. Not changed: the decode buffers are a sync.Pool, emptied at each GC, so the big chunk's buffer is now grown by matchedBlocks (18 -> 553 MB) where newest and rowsOf grew it before. That is the next change. |
||
|
|
c7171a2561 |
usage: a page's cells before its last days are kept in page-v1.json, so a start pairs only the recent chunks for All (#2278)
A start's first page of All (the warm-up's, and the Usage page's own)
paired the whole history for the page's cells, every gateway call with
its session row: ~85 MB of a ~316 MB heap at 18s after the heatmap's days
and Codex's effort were kept (v0.1.2172). The cells of the rows before
cut (local midnight two days back) are now kept as heatSplit keeps its
days, in memory and in page-v1.json beside the sessions cache, under a
key from heatSettledKey plus the page's until, names and hours. A start
pairs only the chunks since the edge. A page whose rows are older than
cut (an offset past the recent rows) falls back to the full pairing.
Real history on mote (~/r2278, a copy of the owner's), 120s each,
three starts in a row:
v0.1.2165 fp_peak 451-471 MB, peaklive 326-364 MB
this, miss fp_peak 587 MB, peaklive 408 MB (a new binary's first start)
this, hit fp_peak 361/366 MB, peaklive 265 MB, gcs 150 (was ~150)
page-v1.json is ~240 KB.
The output is the same: /api/usage/requests for period all, 7d, 30d,
all with offset/limit and all filtered to codex, from a start that hit
page-v1.json and from a cold one (file moved away): 0 differences, each
float within 1e-6, on two hit runs.
Test: TestPageSettledFromDisk (first page pairs once and writes the file;
after a restart fewer chunks are paired and the page is equal; an older
offset falls back and equals the cold page; a changed settled file pairs
everything, then hits again). Broken by hand (pageSplit always false):
it goes red at "first page: pairings []".
Run at this head (rebased on
|
||
|
|
8d4c07ffed |
usage: the heatmap's settled days are kept on disk, so a start pairs only the last days (#2278)
The heatmap's days before the cut (two days ago) came from heatOld, a full pairing of the whole history kept in memory. A started magpie made it again on its first heatmap, and again every heatOldFresh (10 min): on the 52G Codex + 13G Claude bench history that was heatSplit's 88 MB of the cold start's ~325 MB in-use heap at 18 s. The days are now kept in heat-v1.json beside the sessions cache, under a key (heatSettledKey) naming what they were counted of: the request code and the index's root and meta (prices, names), the cut, since, zone, filter, the recent chunks' rows before the cut, the Codex thread identities, and each settled chunk (a session file's by path, size and mtime, like requests-v1.bin; any other chunk by its rows). The file is written through a temp file renamed over the last. A key that can't be named (a chunk with no serial) pairs as before; after heatOldFresh a same-named key keeps the days without pairing again. Measured on mote, ~/r2278/full, cold start + the page's 10 endpoints polled every 5 s: - heap at 18 s: v0.1.2149 324.6 MB in use, heatSplit 88.3 MB, HeatmapOf 135.8 MB; this 310.1 MB, no heatSplit, HeatmapOf 44.1 MB. - /api/usage/heatmap at 40 s: byte-for-byte the same as v0.1.2149's. - gcpeak 120 s, 3 rounds each, alternated (mote under other load): live 360/393/414 vs 378/404/387 MB, gcs 148/174/168 vs 201/209/160. The peak moves to CodexModelEffort's own full pairing (91 MB), next. - First start, no file yet: pairs as before and writes 7.9 KB. Tests: TestHeatmapAfterACallPairsOnlyTheLastDays now removes the file for its cold oracle, and past heatOldFresh with nothing changed pairs less than all, then a new settled file pairs all and equals cold. TestHeatmapSettledDaysFromDisk: restarted with memory cleared pairs less than all and gives the same heatmap; another filter, a rewritten settled file, and no file each pair all. Run at this tree (mote): go test ./internal/usage ok (71s); go test -tags nogui ./internal/gui -run 'Heat|Usage' ok, usageapi ok; go vet -tags nogui ./internal/usage/... ./internal/gui/... on linux, windows, darwin ok; gofmt -l clean. Rebased onto |
||
|
|
fddd7ff08f |
usage: pairing keeps its rows as bits and its groups by sums, and lets its pairs go (#2278)
A cold start pairs the whole history, and pairing held its row sets as map[rowRef]bool, ~40 bytes a row, several sets of most rows at once. They are now refSet: a bitset a chunk, a bit a row. matchScratch's groupOf was keyed by the whole matchKey (a session string and its tokens); it is keyed by a 128-bit maphash sum of them now, and the sessions map is filled when a group is made. pairedRows' pairs and compactions maps were filled and never read; they are gone. Measured on mote, a copy of the real full history (52G Codex, 13G Claude), GODEBUG=gctrace=1, 120s of /api polls, 3 rounds each, alternating, v0.1.2143 ( |
||
|
|
d7e9c37454 |
usage: a call pairs again only the heatmap's last days, not its year (#2278)
Each call through magpie changes the gateway's newest block, so the heatmap's 30 s reuse missed and HeatmapOf paired a year of gateway rows against every session file again: 15% of magpie's CPU on real history (HeatmapOf -> pairRows 5.2 s of 32.7 s sampled), ~2.3 s a refresh, and a large share of the allocation the GC marks. heatSplit keeps the days before cut (00:00 two days ago) from the last full pairing, with the serials of the chunks that can't reach past cut (newest row more than heatReach = 48 h before it). A call then pairs only the recent chunks, from cut on (pairRowsIn), and adds their days to the kept ones. Every chunk is paired again when: - a settled chunk changed or went (its serials differ), or - the recent chunks' rows before cut changed: a session file copied in or a rollout forked from an old one holds calls of then (heatBefore, a count, time and token sum of those rows), or - cut moved (a new day), or the kept pairing is heatOldFresh (10 min) old. heatReach covers a call paired across cut: a full gateway block whose newest call is before cut is still paired with the session row after it. TestHeatmapAfterACallAddsUpOnlyWhatChanged's gateway now has a call of the last days before its first build, as a gateway in use does: with only a call of 40 days ago its block went from settled to recent at the call, which is a full pairing by design. Run on mote, heat2278 at this head (based on |
||
|
|
b69f8e96af |
usage: a call through magpie adds up the heatmap only for the chunks it changed (#2278)
A call through magpie changes the gateway's log, so the heatmap's kept
page (heatFresh) is no use and the Requests tab's refresh read every
row of the year again: unpacked each session file's chunk and summed its
days. While an agent worked through magpie that was every refresh.
The heatmap now keeps each chunk's day sums (chunkPart.days, in
requestIndex.heatParts, apart from the pages' cells so neither pushes
the other's out), under the same pairing signature the cells use, and
adds up again only a chunk whose rows or pairing changed. A call is
still counted at once. pairedRows.visit had no other caller and is gone.
Measured on mote at #2278's scale (synthetic HOME: 15 GB of Codex
rollouts, 1.9 GB of Claude sessions, 240k-row usage.jsonl), the GUI's
polls every 5s and 4 gateway records appended a second, against
v0.1.1920:
- CPU of a 60s profile while appending: 57.9s -> 42.1s;
HeatmapOf 11.5s -> 6.7s, of it the visit 4.8s -> ~0
- /api/usage/heatmap mean 2.79s -> 1.69s; process CPU average
107% -> 83%
- peak footprint unchanged (579 MB, 607 MB this run: noise; what is
left is pairRows' pairing of the year, next)
Test: TestHeatmapAfterACallAddsUpOnlyWhatChanged (8 session files and
a gateway call: after one more call, at most 1 chunk is added up again,
the call is counted, and the sums equal a cold build). Broken by hand
(old sums never taken): red, "a call added up 9 chunks again".
Run at the pushed head (rebased on
|
||
|
|
0dc4cec85d |
usage: a row's Codex thread is kept as a 4-byte place, not a string (#2278)
Every row of a chunk had a 16-byte string header for its Codex
thread. A day's rows are a few hundred threads, one after another. At
the scale of #2278 (34k session files, 1M Codex rows), these headers
were the largest single holder in the heap, 24.5 MB of 184 MB live.
codexActors now keeps a []uint32 into the chunk's thread names. The
row before's thread is checked first, then the names. A clone shares
the names clipped, so adding a name to one never writes into the
other. The disk format is unchanged: each row's thread is still
written as a string.
Measured on mote, at 7e58591dc's parent with this change. The history
is synthetic: 25,000 Codex rollouts and 9,000 Claude Code sessions, 40
turns each (13 GB), plus a 115 MB usage.jsonl of 240k gateway calls on
the newest 3,000 of each. Cold `magpie web --no-open` in a sandbox
HOME, with `magpie heap` taken at 130 s:
- main: live heap 195.2 MB (both runs), physical footprint peak 389 to
417 MB.
- this change: live heap 175.6 MB, physical footprint peak 366 MB.
The reporter's 0.1.1318 peaked at 2.85 GB RSS on such a history.
Run at the pushed head (rebased onto
|
||
|
|
ba301e98e2 |
usage: a page's passes over the chunks decode into buffers kept between them (#3493)
Each pass of a Requests page over every chunk (foldCodexRows, the
response pairs, visibleLocal, matchedBlocks, visit, partsOf, newest,
rowsOf) started a chunkRows with no buffers and grew its rows, strings,
shapes and decode buffer from nothing. A warm start's All page and
Codex's effort after it read the same rows pass after pass, ~30 MB a
pass. chunkRows now takes a rowBuffer from a pool, unpacks into it
(unpackReusing gets a dst chunk too, so the open chunk isn't allocated
each block), and gives it back on release, its strings cleared so no
row text is held.
Measured on the real data copy (sbpairs: 12k Codex rollouts and the
Claude projects), warm-up harness TestZZWarm, each binary run 3 times
in a row and the first run dropped (the chunk file is named by this
package's source, so alternating binaries rebuilds it):
step 2 (QueryPage All) allocated 835 MB -> 666 MB
allocated through step 3 (effort) 994 MB -> 820 MB
unpackReusing in step 2 163 MB -> 34 MB
peak footprint ~240 MB, unchanged
Run at this head (base
|
||
|
|
4982ded8a6 |
usage: a turned page reuses the last pairing while its chunks are the same
A Requests page paired every Codex session file's calls with the
gateway's again on each query: clone, fold forks, match response ids.
That unpacked every session chunk three times and was about half of a
warm page (#3493). pairRowsMemo names the chunks of a pairing by their
serials (the probe chunk, which has none, by its rows' log offsets and
times) and keeps what the pairing found: the rows left out (skip,
matched), the actors it changed and each chunk's compactions. The next
query over the same chunks and window applies that to fresh clones
instead of pairing again. A changed file gets a new serial, a new
window or period misses, and adopt drops the memos with the parts.
Run at
|
||
|
|
a6399dd494 |
usage: a Requests page sums each chunk once and reuses it while the chunk is the same
Turning a page, or the 15s refresh of the open page, built every sum, chart and share from every row of history again. On the owner's real history that was 1.15-1.36s a page (load 170) after the chunks were already cached. Each chunk's rows are now folded into cells: one per provider, agent, model, kind, caller, account, computer, source, filter bits and chart bucket, with its totals. A page merges the cells. The cells of a chunk are kept per (period, filter, since, until, zone), up to 4 such sets, keyed by the chunk's serial (a new one every time a chunk is read or frozen) and a signature of what pairing gave it: rows skipped or matched, Codex actors and their identities (with the parent's role), and compactions. A changed file, a gateway tail block or an identity change from another file sums that chunk again. The newest rows are taken from chunks in Latest order, stopping once the heap holds rows newer than the next chunk. Cell strings are unique handles, so the cache holds no chunk's string block. Totals and Part sums are linear, so merged cells equal the row-by-row sums; date-mode buckets store the day number and are placed against the chart's first day at merge time. What was run (macOS, arm64): - Real history (sbmem sandbox HOME, read-only links to the owner's data), zzbench dump of 9 cases x 2 pages (offset 0/50 after a warm 7/50 call, and 120/30) with the base |