ac4af582301a4e8a29245dbba767eba31334ddf9
3
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
1360689ef2 |
provider: Served is shared while a request holds the catalog, not copied for each look (#3725)
Served built a fresh copy of the whole catalog on every call: the
unlisted groups' entries plus every provider entry. An Entry is ~1.3KB,
and a request looks at Served from outputLimit, userOutput, askedOutput
and windowIn, so with 12 providers of 20 models each look copied ~380KB
and a request ~800KB, all garbage by the reply.
Served now goes through heldFrom like providerEntries: one slice, built
once while a request holds the catalog and kept across requests until a
file it is built from changes. It is clipped, so a caller's append makes
its own copy and never reaches the next caller. The four gateway loops
take each entry by pointer instead of copying 1.3KB a step. Every
caller of Served (gateway, gui, cli, tui, agent, provider) was read for
writes into the slice or its entries; all only read.
Measured on BenchmarkZZIO (12 providers x 20 models, an 8KB request,
not committed): 1.57MB allocated per request before, 640KB after.
TestServedSharedWhileHeld: under Hold two calls give the same backing
entry, and an append to one doesn't show in the next. Red on the old
code (a new copy each call), green now.
Run at
|
||
|
|
627e8e7d95 |
provider: a request's groups are built once under its Hold, not again by each look-up
groupsIn read providers.json's groups, matched each pattern against every model and found the automatic groups over the whole catalog, and every caller did it again: a request to a group asks FindGroup for its route, members and window, and the group list, several times each. Under a Hold the built groups are now kept (heldFrom, keyed on the catalog's entries, dropped by a write as the other held values are), and each caller gets a deep copy (cloneGroups) so a change of its own, such as the TUI's edit before a failed save, never reaches the next. Tests: - TestGroupsBuiltOnceWhileHeld: 40 look-ups under one Hold build the groups 0 more times; a change to a returned group's members isn't the next caller's; a SaveGroup under the Hold is seen. Broken by hand (groupsIn built every time): red, "the groups were built 40 times more in 40 looks under one Hold, want 0". Without the copy: red, "a change to a held group's members reached the next caller" (and TestHeldGroupsAreTheCallers red too). - TestCloneGroupsSharesNothing fills every field of a Group and its Rules by reflection and fails on any slice, map or pointer the copy shares, so a field added later is caught. Broken by hand (Weights not cloned): red, "Group.Weights is shared with the held group". BenchmarkGroupLooksHeld (30 providers x 60 models, 4 FindGroup and 1 Groups under one Hold; -benchtime 200x, two rounds; load average ~450): before 13.8 / 23.9 ms/op 26.2MB/op 41080 allocs/op after 0.18 / 0.14 ms/op 310KB/op 413 allocs/op User+sys CPU of the binary, 300 iterations minus 3: before 4.5/4.2 s (~15 ms per request's look-ups), after 0.08/0.06 s (~0.2 ms). BenchmarkGroupOverhead (200KB, not streamed, 30x): allocs of a group request fell (30x60 g4 72.9K/75.0K -> 60.5K/75.8K, g1 70.9K/73.1K -> 62.4K/68.4K; 12x20 g4 46.1K/45.8K -> 43.7K/44.7K); cpu-ms/op moved within the noise of a machine at load ~450, where a request's wall time passes heldFor and the held values are built again. Run: go vet ./internal/provider; go test ./internal/provider -run 'Group|Hold|Held|Rule|Clone' -count 1: ok (17.0s); go test ./internal/gateway -run Group -count 1: ok (53.1s). |
||
|
|
a595f1559c |
provider: a request to a routing group builds the groups' entries once, not once per look at every member of every group (colmugx, Yayoi_no_yume on X)
colmugx found magpie hotter with groups, and worse since ~v0.1.1225. Yayoi_no_yume saw CPU jump to 100% as soon as a request entered a group, and stay there under concurrency. Cause: one request to a group asked for the groups' entries (groupEntries) five or six times: Catalog from Resolve and IsDecider, and Served from membersImageInput, outputLimit, windowIn and roomy. A direct provider/model request asked through Resolve too. Nothing held that work. Each build: - went through every member of every group, the found auto-<model> ones included, with a linear pass over the whole catalog per member. It copied each large Entry it passed (groupEntries, resolveIn); - since |