Files
magpie/internal/usage/request_big_build_test.go
T
yetone c8095d1101 usage: pages of 131k rows or more pair one at a time (#2278)
On a cold start the Usage page's requests (All) and heatmap (a year),
and the warm-up's Codex effort, each paired the whole history side by
side, and the live heap reached 624–630 MB at ~10–12 s: the peak. Now
a page's build, or Codex effort's pairing, of bigBuildRows (1<<17) rows
or more holds bigBuilds; a smaller page, Today's, goes beside them, and
its IO never waits (TestQueryPageIOOutsideCacheLock passes). Nothing
under the gate takes requestCache's lock or waits on a flight.

Measured on mote (M5 Pro), cold start with no caches, 390k calls,
a growing Codex rollout, 10 endpoints polled every 5 s, 60 s each:
- before (v0.1.2113): phys_footprint_peak 794 / 783 MB, CPU
  2:01.55 / 2:01.12
- after: 610 / 646 MB, CPU 2:01.08 / 2:03.22
- the first round's slowest usage answers, before 7.9 / 10.3 s and
  7.9 / 10.3 s, after 7.9 / 11.5 s and 6.4 / 8.7 s
On v0.1.2111 plus the warm-up fix alone, the gate cut the max live heap
from 624/630 to 473/480 MB but not the peak, which the request file's
write then set (8e1b1b26d).

Tests at this head, through mote-run:
- go vet -tags nogui ./..., GOOS linux, windows and darwin: ok
- go test -count=1 -timeout 45m ./internal/usage/ ./internal/gui/
  ./internal/sessions/: usage, sessions ok; gui only
  TestMainWindowCorners/macOS_26_SDK, #3949.
- TestBigPagesPairInTurn (two big pages, a 200 ms pairing each): 1 at
  once; with bigBuildRows at 1<<40 it was red, 2 at once.
2026-10-30 06:48:56 +08:00

41 lines
969 B
Go

package usage
import (
"sync"
"testing"
"time"
)
// Two big pages pair their rows one after another, not side by side: on a
// cold start the heatmap's year and the requests' All each held every
// call paired at once, most of the footprint's peak (#2278).
func TestBigPagesPairInTurn(t *testing.T) {
pageHome(t)
settleLogClock(t)
holdClock(t, time.Date(2026, 9, 30, 12, 0, 0, 0, time.Local))
historyLog(t, 1034)
rows := bigBuildRows
bigBuildRows = 1
t.Cleanup(func() { bigBuildRows = rows })
var mu sync.Mutex
in, most := 0, 0
pairing = func() {
mu.Lock()
in++
most = max(most, in)
mu.Unlock()
time.Sleep(200 * time.Millisecond) // the other page pairs now, if it can
mu.Lock()
in--
mu.Unlock()
}
t.Cleanup(func() { pairing = nil })
var wg sync.WaitGroup
wg.Go(func() { QueryPage(All, Filter{}, 0, 100) })
wg.Go(func() { HeatmapOf(Filter{}) })
wg.Wait()
if most != 1 {
t.Fatalf("%d big pages paired at once, want 1", most)
}
}