Each poll of the Sessions list and of every stats range titled each of ~5000 gateway sessions with GatewayTitle, which made the recordings folder's name and Stat-ed it each time. With nothing recorded, as for most users, that was the whole cost: os.Stat 62 MB and gatewayDir 18 MB of 90 s of polls while an agent worked. GatewayTitler makes the folder's name and asks once, and gives "" with no work when nothing is recorded; gatewayListed takes it. GatewayTitle is GatewayTitler()(agent, id), for one session. Bench (mote, ~/r2278/full, hmw.sh second runs), e14 =bed604efb, e15 = this: GatewayTitle 81 MB -> gone, gatewayListed 100 -> 19 MB, polls 170 x 200 in both; total 2308 -> 2350 MB is the run-to-run band. TestGatewayTitlerAsksOnce: with nothing recorded a title makes 0 allocations; after a turn is recorded a titler made then finds what GatewayTitle finds. Broken by hand (Stat and the folder's name again per session): red. At 825db07aa onbed604efb(mote): gofmt clean; go vet -tags nogui ./internal/gui/ ./internal/sessions/ for linux, windows, darwin ok; go test ./internal/sessions/ ok; go test ./internal/gui/ -run 'Gateway|Sessions|Stats' ok.
26 lines
1013 B
Go
26 lines
1013 B
Go
package gui
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/yetone/magpie/internal/sessions"
|
|
"github.com/yetone/magpie/internal/usage"
|
|
)
|
|
|
|
// A list, a manage page and a detail never read a gateway session's days,
|
|
// and copying every session's days for each poll of an open Sessions page
|
|
// was ~1.8 GB in 4 minutes over ~720k calls (#2776). Only the stats copy
|
|
// them, and they still count each one (TestGatewaySessionHistoryAndCalendar).
|
|
func TestGatewayListCopiesNoDays(t *testing.T) {
|
|
g := usage.GatewaySession{Agent: "pi", ID: "s", Models: []usage.GatewayModel{{Model: "m"}}}
|
|
for range 365 {
|
|
g.Daily = append(g.Daily, usage.GatewayDayUsage{Date: "2026-10-19", Agent: "pi", Model: "m"})
|
|
}
|
|
if e := gatewayListed(g, sessions.GatewayTitle); len(e.Daily) != 0 || len(e.Models) != 1 {
|
|
t.Fatalf("a listed session copied %d days and %d models, want 0 and 1", len(e.Daily), len(e.Models))
|
|
}
|
|
if d := gatewayDays(g); len(d) != len(g.Daily) {
|
|
t.Fatalf("the stats' copy has %d days, want %d", len(d), len(g.Daily))
|
|
}
|
|
}
|