stampedLists (each agent's magpie models, options, Codex's picks) builds
a list again once it is older than magpieModelsFor, but never let the old
one go. Every agent's list a window poll asked for once stayed for the
life of the process, though it would never be served again: with real
accounts, Pi's alone was 10.9 MB of an idle heap and dsh's 4.1 MB
(piOffered.sharedModels, dshRounds.magpieModels). Now a sweep, armed when
a list is kept, drops the lists past their minute and looks again when the
next of the rest will be; it stops when none is left.
Ran on mote at this head (rebased on 459405960; internal/agent again ok at 5df062f0f): go test ./internal/agent
./internal/gui ./internal/gateway ok; GOOS=windows and GOOS=linux go vet
./... ok. TestKeptListsPastTheirMinuteLetGo is red with the delete removed.
Measured with a copy of the real accounts, 600s idle, two runs each order:
Footprint at the end 114/91 MB before, 109/104 MB after, within the noise.
The end heaps of both still hold 7.5-11 MB of these lists: KeepDshWired
asks for dsh's every 30s, inside the minute, so they are rebuilt and kept
while it runs. The gain is for lists only a window asked for (Pi's
thinking levels, an agent's options) once the window is gone.
Not tried: a run without dsh wired, where the sweep would show.
60 lines
1.3 KiB
Go
60 lines
1.3 KiB
Go
package agent
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
// A kept list past magpieModelsFor is built again on its next ask, so the
|
|
// sweep lets it go; one still fresh stays, and the sweep looks again for it.
|
|
func TestKeptListsPastTheirMinuteLetGo(t *testing.T) {
|
|
var s stampedLists[string]
|
|
builds := 0
|
|
build := func() []string { builds++; return []string{"a", "b"} }
|
|
s.shared("old", build)
|
|
s.shared("fresh", build)
|
|
s.Lock()
|
|
if !s.sweeping {
|
|
s.Unlock()
|
|
t.Fatal("no sweep armed for the lists kept")
|
|
}
|
|
b := s.m["old"]
|
|
b.at = b.at.Add(-2 * magpieModelsFor)
|
|
s.m["old"] = b
|
|
s.Unlock()
|
|
|
|
s.sweep()
|
|
s.Lock()
|
|
_, old := s.m["old"]
|
|
_, fresh := s.m["fresh"]
|
|
sweeping := s.sweeping
|
|
s.Unlock()
|
|
if old || !fresh || !sweeping {
|
|
t.Fatalf("after a sweep: old kept %v, fresh kept %v, sweep armed %v; want false, true, true", old, fresh, sweeping)
|
|
}
|
|
|
|
s.Lock()
|
|
b = s.m["fresh"]
|
|
b.at = b.at.Add(-2 * magpieModelsFor)
|
|
s.m["fresh"] = b
|
|
s.Unlock()
|
|
s.sweep()
|
|
s.Lock()
|
|
n, sweeping := len(s.m), s.sweeping
|
|
s.Unlock()
|
|
if n != 0 || sweeping {
|
|
t.Fatalf("after the last went: %d kept, sweep armed %v", n, sweeping)
|
|
}
|
|
|
|
n0 := builds
|
|
s.shared("old", build)
|
|
if builds != n0+1 {
|
|
t.Fatal("a list let go wasn't built again on its next ask")
|
|
}
|
|
s.Lock()
|
|
sweeping = s.sweeping
|
|
s.Unlock()
|
|
if !sweeping {
|
|
t.Fatal("no sweep armed again for a list kept after the last one went")
|
|
}
|
|
}
|