commit 032be4b3e4dffc8b225ff77e9bd3780996a2c7f7
parent 2899d9a21758daa8f485897d60cac447bd24e650
Author: anon <anon@example.com>
Date: Sat, 7 Nov 2026 07:07:07 +0000
Report stress latency and throughput separately for each zone
Diffstat:
5 files changed, 135 insertions(+), 40 deletions(-)
diff --git a/tools/stress/README.md b/tools/stress/README.md
@@ -29,7 +29,10 @@ the server, without browsers or rendering.
JSON lines report cumulative admission and action latency, steady-period action
latency, scheduled-action latency including client scheduling delay, received
traffic, ready/disconnected clients, generator heap/goroutines, missed scheduled
-actions and unanswered actions. Millisecond histograms have bounded memory;
+actions and unanswered actions. The `zones` object reports the same latency and
+throughput counters by playfield, so a hotspot cannot hide stalls in quiet zones.
+Compare each zone's `steady_actions` divided by the measured steady-window duration
+and its `steady_action` percentiles; do not infer isolation from aggregate latency. Millisecond histograms have bounded memory;
the 60000 ms bucket includes all larger values. Outstanding actions at the end
are reported separately. Failed connections or incomplete admission produce a
nonzero exit status. Slow responses never silently reduce the expected action
diff --git a/tools/stress/main.go b/tools/stress/main.go
@@ -32,6 +32,7 @@ type visitor struct {
}
type event struct {
+ playfield uint32
kind string
at time.Time
elapsed time.Duration
@@ -114,17 +115,17 @@ func run(ctx context.Context, address string, count int, ramp, duration time.Dur
defer workers.Done()
scheduled := started.Add(time.Duration(index) * ramp / time.Duration(count))
if !waitUntil(load, scheduled) {
- events <- event{kind: "not_started"}
+ events <- event{playfield: person.Place.Playfield, kind: "not_started"}
return
}
- events <- event{kind: "attempted"}
+ events <- event{playfield: person.Place.Playfield, kind: "attempted"}
if err := exercise(load, address, person, scheduled, events); err != nil && load.Err() == nil {
- events <- event{kind: "failed", err: fmt.Errorf("client %d: %w", person.ID, err)}
+ events <- event{playfield: person.Place.Playfield, kind: "failed", err: fmt.Errorf("client %d: %w", person.ID, err)}
}
}(index, person)
}
go func() { workers.Wait(); close(events) }()
- err = collect(events, started, ramp)
+ err = collect(os.Stdout, events, started, ramp)
if ctx.Err() != nil {
return ctx.Err()
}
@@ -227,17 +228,56 @@ func (h *histogram) percentiles() map[string]int {
return result
}
-func collect(events <-chan event, started time.Time, ramp time.Duration) error {
- counts := make(map[string]int)
- var admission, action, scheduled, steady histogram
+type measurements struct {
+ counts map[string]int
+ admission, action, scheduled, steady histogram
+}
+
+func (measurements *measurements) add(result event, steadyAt time.Time) {
+ measurements.counts[result.kind]++
+ measurements.counts["missed_actions"] += result.missed
+ measurements.counts["received_packets"] += result.packets
+ measurements.counts["received_bytes"] += result.bytes
+ switch result.kind {
+ case "ready":
+ measurements.admission.add(result.elapsed)
+ case "action":
+ measurements.action.add(result.elapsed)
+ if !result.at.Before(steadyAt) {
+ measurements.steady.add(result.elapsed)
+ measurements.counts["steady_actions"]++
+ }
+ case "scheduled_action":
+ measurements.scheduled.add(result.elapsed)
+ }
+}
+
+func (measurements *measurements) report() map[string]any {
+ return map[string]any{"counts": measurements.counts,
+ "active": measurements.counts["ready"] - measurements.counts["disconnected"],
+ "admission": measurements.admission.percentiles(), "action": measurements.action.percentiles(),
+ "scheduled_action": measurements.scheduled.percentiles(), "steady_action": measurements.steady.percentiles()}
+}
+
+func collect(output io.Writer, events <-chan event, started time.Time, ramp time.Duration) error {
+ total := measurements{counts: make(map[string]int)}
+ zones := make(map[uint32]*measurements)
+ steadyAt := started.Add(ramp)
var outputError error
ticker := time.NewTicker(5 * time.Second)
defer ticker.Stop()
write := func(phase string) error {
var memory runtime.MemStats
runtime.ReadMemStats(&memory)
- return json.NewEncoder(os.Stdout).Encode(map[string]any{"phase": phase, "seconds": time.Since(started).Seconds(), "counts": counts,
- "active": counts["ready"] - counts["disconnected"], "admission": admission.percentiles(), "action": action.percentiles(), "scheduled_action": scheduled.percentiles(), "steady_action": steady.percentiles(), "generator_heap_bytes": memory.HeapAlloc, "generator_goroutines": runtime.NumGoroutine()})
+ report := total.report()
+ report["phase"], report["seconds"] = phase, time.Since(started).Seconds()
+ report["generator_heap_bytes"], report["generator_goroutines"] = memory.HeapAlloc, runtime.NumGoroutine()
+ zoneReports := make(map[uint32]map[string]any, len(zones))
+ for playfield, zone := range zones {
+ zoneReports[playfield] = zone.report()
+ }
+ report["zones"] = zoneReports
+ return json.NewEncoder(output).Encode(report)
}
for {
select {
@@ -249,30 +289,18 @@ func collect(events <-chan event, started time.Time, ramp time.Duration) error {
if outputError != nil {
return outputError
}
- if counts["failed"] != 0 || counts["not_started"] != 0 || counts["attempted"] != counts["ready"] {
- return fmt.Errorf("load incomplete: %d failed, %d not started, %d unready", counts["failed"], counts["not_started"], counts["attempted"]-counts["ready"])
+ if total.counts["failed"] != 0 || total.counts["not_started"] != 0 || total.counts["attempted"] != total.counts["ready"] {
+ return fmt.Errorf("load incomplete: %d failed, %d not started, %d unready", total.counts["failed"], total.counts["not_started"], total.counts["attempted"]-total.counts["ready"])
}
return nil
}
- counts[result.kind]++
- counts["missed_actions"] += result.missed
- counts["received_packets"] += result.packets
- counts["received_bytes"] += result.bytes
- switch result.kind {
- case "ready":
- admission.add(result.elapsed)
- case "action":
- action.add(result.elapsed)
- if !result.at.Before(started.Add(ramp)) {
- steady.add(result.elapsed)
- counts["steady_actions"]++
- }
- case "scheduled_action":
- scheduled.add(result.elapsed)
- case "failed":
- if counts["failed"] <= 10 {
- fmt.Fprintln(os.Stderr, result.err)
- }
+ total.add(result, steadyAt)
+ if zones[result.playfield] == nil {
+ zones[result.playfield] = &measurements{counts: make(map[string]int)}
+ }
+ zones[result.playfield].add(result, steadyAt)
+ if result.kind == "failed" && total.counts["failed"] <= 10 {
+ fmt.Fprintln(os.Stderr, result.err)
}
case <-ticker.C:
if outputError == nil {
diff --git a/tools/stress/measurements_test.go b/tools/stress/measurements_test.go
@@ -0,0 +1,61 @@
+package main
+
+import (
+ "bytes"
+ "encoding/json"
+ "testing"
+ "time"
+)
+
+func TestCollectKeepsHotAndQuietZoneMeasurementsSeparate(t *testing.T) {
+ started := time.Now()
+ events := make(chan event, 10)
+ for _, result := range []event{
+ {playfield: 705, kind: "attempted"},
+ {playfield: 800, kind: "attempted"},
+ {playfield: 705, kind: "ready", elapsed: 500 * time.Millisecond},
+ {playfield: 800, kind: "ready", elapsed: time.Millisecond},
+ {playfield: 705, kind: "action", at: started, elapsed: 30 * time.Millisecond},
+ {playfield: 705, kind: "action", at: started.Add(time.Second), elapsed: 900 * time.Millisecond},
+ {playfield: 800, kind: "action", at: started.Add(time.Second), elapsed: 2 * time.Millisecond},
+ {playfield: 705, kind: "late", missed: 7},
+ {playfield: 705, kind: "traffic", packets: 12, bytes: 1234},
+ {playfield: 800, kind: "unanswered_action"},
+ } {
+ events <- result
+ }
+ close(events)
+ var output bytes.Buffer
+
+ if err := collect(&output, events, started, time.Second); err != nil {
+ t.Fatal(err)
+ }
+
+ type measurement struct {
+ Counts map[string]int
+ Admission map[string]int
+ Steady map[string]int `json:"steady_action"`
+ }
+ var report struct {
+ Phase string
+ Counts map[string]int
+ Zones map[uint32]measurement
+ }
+ if err := json.Unmarshal(output.Bytes(), &report); err != nil {
+ t.Fatal(err)
+ }
+ if report.Phase != "complete" || report.Counts["action"] != 3 || report.Counts["steady_actions"] != 2 || len(report.Zones) != 2 {
+ t.Fatal("incorrect combined measurements", report)
+ }
+ if report.Zones[705].Admission["p99_ms"] != 500 || report.Zones[705].Steady["p50_ms"] != 900 ||
+ report.Zones[705].Counts["action"] != 2 || report.Zones[705].Counts["steady_actions"] != 1 ||
+ report.Zones[705].Counts["missed_actions"] != 7 || report.Zones[705].Counts["received_packets"] != 12 ||
+ report.Zones[705].Counts["received_bytes"] != 1234 {
+ t.Fatal("hot zone measurements mixed with another zone or the ramp", report.Zones[705])
+ }
+ if report.Zones[800].Admission["p99_ms"] != 1 || report.Zones[800].Steady["p99_ms"] != 2 ||
+ report.Zones[800].Counts["action"] != 1 || report.Zones[800].Counts["missed_actions"] != 0 ||
+ report.Zones[800].Counts["unanswered_action"] != 1 || report.Zones[800].Counts["received_bytes"] != 0 {
+ t.Fatal("quiet zone measurements contaminated by the hot zone", report.Zones[800])
+ }
+}
diff --git a/tools/stress/protocol.go b/tools/stress/protocol.go
@@ -85,7 +85,7 @@ func exercise(ctx context.Context, address string, person visitor, scheduled tim
defer stopReader()
go func() {
defer close(readDone)
- traffic := event{kind: "traffic"}
+ traffic := event{playfield: person.Place.Playfield, kind: "traffic"}
reported := time.Now()
defer func() { events <- traffic }()
for {
@@ -98,7 +98,7 @@ func exercise(ctx context.Context, address string, person visitor, scheduled tim
traffic.bytes += len(body)
if time.Since(reported) >= time.Second {
events <- traffic
- traffic = event{kind: "traffic"}
+ traffic = event{playfield: person.Place.Playfield, kind: "traffic"}
reported = time.Now()
}
if binary.BigEndian.Uint16(body[2:4]) != 10 || len(body) < 36 || binary.BigEndian.Uint32(body[28:32]) != person.ID {
@@ -159,8 +159,8 @@ func exercise(ctx context.Context, address string, person visitor, scheduled tim
if err := await(acknowledgement{opcode: 0x570c2039}); err != nil {
return err
}
- events <- event{kind: "ready", elapsed: time.Since(scheduled)}
- defer func() { events <- event{kind: "disconnected"} }()
+ events <- event{playfield: person.Place.Playfield, kind: "ready", elapsed: time.Since(scheduled)}
+ defer func() { events <- event{playfield: person.Place.Playfield, kind: "disconnected"} }()
// One scheduled action per second per client. Skipped deadlines are counted;
// a slow reply must not silently turn the test into a lighter workload.
@@ -168,7 +168,7 @@ func exercise(ctx context.Context, address string, person visitor, scheduled tim
pending := false
defer func() {
if pending {
- events <- event{kind: "unanswered_action"}
+ events <- event{playfield: person.Place.Playfield, kind: "unanswered_action"}
}
}()
for step := 0; waitUntil(ctx, next); step++ {
@@ -189,8 +189,8 @@ func exercise(ctx context.Context, address string, person visitor, scheduled tim
return err
}
pending = false
- events <- event{kind: "action", elapsed: time.Since(sent), at: time.Now()}
- events <- event{kind: "scheduled_action", elapsed: time.Since(next)}
+ events <- event{playfield: person.Place.Playfield, kind: "action", elapsed: time.Since(sent), at: time.Now()}
+ events <- event{playfield: person.Place.Playfield, kind: "scheduled_action", elapsed: time.Since(next)}
if action == 87 {
if err := write(movement(person, uint32(1+2*(step/2%2)))); err != nil {
return err
@@ -199,7 +199,7 @@ func exercise(ctx context.Context, address string, person visitor, scheduled tim
next = next.Add(time.Second)
if late := time.Since(next); late >= 0 {
missed := int(late/time.Second) + 1
- events <- event{kind: "late", missed: missed}
+ events <- event{playfield: person.Place.Playfield, kind: "late", missed: missed}
next = next.Add(time.Duration(missed) * time.Second)
}
}
diff --git a/tools/stress/protocol_test.go b/tools/stress/protocol_test.go
@@ -61,12 +61,15 @@ func TestExerciseWaitsForItsOwnGameAcknowledgementAndStopsReader(t *testing.T) {
events := make(chan event, 100)
done := make(chan error, 1)
go func() {
- done <- exercise(ctx, server.URL, visitor{ID: 42, Cookie: "ao_client=test", Place: placement{Rotation: [4]float32{0, 0, 0, 1}}}, time.Now(), events)
+ done <- exercise(ctx, server.URL, visitor{ID: 42, Cookie: "ao_client=test", Place: placement{Playfield: 705, Rotation: [4]float32{0, 0, 0, 1}}}, time.Now(), events)
}()
ready, acknowledged := false, false
for !acknowledged {
select {
case result := <-events:
+ if result.playfield != 705 {
+ t.Fatal("event lost its client zone", result)
+ }
if result.kind == "ready" {
ready = true
}