perf: expose and reduce message publish latency

This commit is contained in:
richjohnrambo
2026-09-27 21:08:35 +08:00
parent 8e778726e0
commit bde02e8eac
15 changed files with 274 additions and 98 deletions
+17
View File
@@ -66,6 +66,23 @@ func TestDeliveryRecorderCapturesOrderingViolationDetails(t *testing.T) {
}
}
func TestDeliveryRecorderSeparatesLocalAndCrossMachineLatency(t *testing.T) {
recorder := newDeliveryRecorder("run1", "a", 1)
local := AcceptedMessage{RunID: "run1", ClientMid: "run1-p-a-0001-01", Topic: "p2p-one", Seq: 1}
cross := AcceptedMessage{RunID: "run1", ClientMid: "run1-p-b-0001-01", Topic: "p2p-one", Seq: 2}
recorder.onData(AccountRecord{Index: 1}, testData(local, time.Now().Add(-10*time.Millisecond)))
recorder.onData(AccountRecord{Index: 1}, testData(cross, time.Now().Add(time.Second)))
summary := recorder.summarize(AgentSummary{}, nil)
if summary.DeliveryLatencyLocal.Count != 1 || summary.DeliveryLatencyCross.Count != 0 {
t.Fatalf("unexpected split latency counts: local=%d cross=%d",
summary.DeliveryLatencyLocal.Count, summary.DeliveryLatencyCross.Count)
}
if summary.CrossClockSkewSamples != 1 {
t.Fatalf("cross clock skew samples=%d", summary.CrossClockSkewSamples)
}
}
func testData(message AcceptedMessage, sentAt time.Time) dataPacket {
content, _ := json.Marshal(map[string]any{"run_id": message.RunID, "sent_at_unix_nano": sentAt.UnixNano()})
return dataPacket{Topic: message.Topic, Seq: message.Seq,