The first Sessions page after a start that showed Codex rows read usage.CodexModelEffort cold, from the whole ledger, while the page waited. The warm-up now reads it as its last step, after the stats it already warmed, and only when those stats hold a Codex session; every later ask is answered from what CodexModelEffort keeps per period. The steps move into warmSteps() so a test can run them. TestWarmUpReadsCodexEffort: with Codex keys in the stats the step reads the effort once, with none it reads nothing. With the step removed: red, "read 0 times, want 1". Measured on the same sandbox as the commit before (600k gateway calls, ~4,600 sessions), base1a3b92688against this branch, back to back, at a load average of 350-480 (nine agents running suites): manage?agent=codex, asked 3.5s after the routes: base 226s / 190s / 232s (cold) new 247s / 222s / 246s (cold) It is not faster here: asked at 3.5s, the page arrives before the warm-up reaches its last step, and both read the ledger at once; the load makes every one of these numbers mostly CPU wait. The step helps a first Codex page opened after the warm-up is done, which is the case in #2776 (a page opened some time after a restart). Not measured at that point under this load. Run on origin/main2ceff7370with all four #2776 commits' changes (this one and the three beside it), load average 291-568 (nine agents running suites), macOS: - go test -p 4 ./... -timeout 45m, 09:35-10:49: 62 packages ok, among them agent (2310s), gateway (1707s), provider (764s), usage (83s). Red: - internal/sessions: TestWSLOmpProfiles, TestWSLStoppedDistroKept, TestWSLStoppedSinceNotOpened, TestWSLNoneWithoutHomes, each "TempDir: mkdir ...: no space left on device" (the disk filled mid-run). After space was freed, ./internal/sessions alone: ok (139s). - internal/gui: TestDockJoinLeadsCommandTab, TestPanelCloseHidesIt, TestPanelJoinsFullScreenSpaces, TestPluginPageLoadsItsFilesInTheWindow, TestDockReopenKeepsTheWindowsSpace (each killed at 30s) and TestMainWindowCorners (86s): the real-window AppKit tests under load, already filed as #2645 and #1936. Rerun alone at load ~335: all pass, with TestSetAnswersWhileDevinAndProvidersHang (17s). - gofmt -l: none. go vet: darwin, GOOS=linux -tags nogui and GOOS=windows all exit 0. - No internal/gui/assets file changed, so the GUI Playwright suite was not run.
65 lines
1.8 KiB
Go
65 lines
1.8 KiB
Go
package gui
|
|
|
|
import (
|
|
"runtime"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/yetone/magpie/internal/sessions"
|
|
)
|
|
|
|
// The warm-up's garbage goes back to the system when it ends, not over the
|
|
// scavenger's next minutes: an idle magpie that just started read ~470 MB.
|
|
func TestWarmUpReturnsItsGarbage(t *testing.T) {
|
|
var keep [][]byte
|
|
warmUp(func() {
|
|
// a read that allocates far more than it keeps
|
|
for range 256 {
|
|
keep = append(keep, make([]byte, 1<<20))
|
|
}
|
|
keep = [][]byte{keep[0]}
|
|
})
|
|
var m runtime.MemStats
|
|
runtime.ReadMemStats(&m)
|
|
if held := m.HeapIdle - m.HeapReleased; held > 32<<20 {
|
|
t.Fatalf("after the warm-up %d MB of freed heap is still held from the system", held>>20)
|
|
}
|
|
if m.HeapAlloc > 128<<20 {
|
|
t.Fatalf("after the warm-up %d MB of heap is still in use", m.HeapAlloc>>20)
|
|
}
|
|
runtime.KeepAlive(keep)
|
|
}
|
|
|
|
// With Codex sessions on this computer the warm-up also reads Codex's
|
|
// per-thread effort, which a first Codex page after a start otherwise read
|
|
// from the whole ledger while it waited (#2776); without any it doesn't.
|
|
func TestWarmUpReadsCodexEffort(t *testing.T) {
|
|
statsMemo.Lock()
|
|
saved := statsMemo.m
|
|
statsMemo.Unlock()
|
|
old := warmCodexEffort
|
|
t.Cleanup(func() {
|
|
statsMemo.Lock()
|
|
statsMemo.m = saved
|
|
statsMemo.Unlock()
|
|
warmCodexEffort = old
|
|
})
|
|
for _, c := range []struct {
|
|
keys []string
|
|
want int
|
|
}{{[]string{"claude:a", "codex:b"}, 1}, {[]string{"claude:a"}, 0}} {
|
|
statsMemo.Lock()
|
|
statsMemo.m = map[int]*statsKept{}
|
|
for _, d := range []int{0, 30} {
|
|
statsMemo.m[d] = &statsKept{at: time.Now(), st: sessions.Stats{Keys: c.keys}}
|
|
}
|
|
statsMemo.Unlock()
|
|
read := 0
|
|
warmCodexEffort = func() { read++ }
|
|
warmUp(warmSteps()...)
|
|
if read != c.want {
|
|
t.Fatalf("with sessions %v Codex's effort was read %d times, want %d", c.keys, read, c.want)
|
|
}
|
|
}
|
|
}
|