From 4f97aa0f3dda6fa88634c206f8184641bc0a7e6b Mon Sep 17 00:00:00 2001 From: k2safe Date: Tue, 22 Sep 2026 16:16:36 +0800 Subject: [PATCH] test: inspect proxy drain state --- internal/perfcheck/main.go | 10 +++++++++- scripts/verifyProxy.py | 4 ++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/internal/perfcheck/main.go b/internal/perfcheck/main.go index d7e4281..ea97070 100644 --- a/internal/perfcheck/main.go +++ b/internal/perfcheck/main.go @@ -46,6 +46,7 @@ type snapshot struct { Goroutines int `json:"goroutines"` Connections int64 `json:"connections"` Accepted int64 `json:"accepted"` + ActiveRequests int64 `json:"activeRequests,omitempty"` FileDescriptors int `json:"fileDescriptors,omitempty"` } @@ -193,12 +194,14 @@ func serve(adapter string, tlsEnabled bool) error { }) done := make(chan error, 1) var shutdown func(context.Context) error + var stats func() native.Stats switch adapter { case "native": server := native.New(application) server.MaxConnections = 8192 server.MaxConcurrentRequests = 4096 shutdown = server.Shutdown + stats = server.Stats go func() { done <- server.Serve(context.Background(), serveListener) }() case "nethttp": server := &http.Server{ @@ -246,11 +249,16 @@ func serve(adapter string, tlsEnabled bool) error { } var memory runtime.MemStats runtime.ReadMemStats(&memory) + connections, accepted, activeRequests := tracked.active.Load(), tracked.accepted.Load(), int64(0) + if stats != nil { + value := stats() + connections, accepted, activeRequests = value.ActiveConnections, int64(value.AcceptedConnections), value.ActiveRequests + } if err := encoder.Encode(snapshot{ HeapAlloc: memory.HeapAlloc, HeapInuse: memory.HeapInuse, StackInuse: memory.StackInuse, TotalAlloc: memory.TotalAlloc, Mallocs: memory.Mallocs, NumGC: memory.NumGC, - Goroutines: runtime.NumGoroutine(), Connections: tracked.active.Load(), Accepted: tracked.accepted.Load(), + Goroutines: runtime.NumGoroutine(), Connections: connections, Accepted: accepted, ActiveRequests: activeRequests, FileDescriptors: openFileDescriptorCount(), }); err != nil { return err diff --git a/scripts/verifyProxy.py b/scripts/verifyProxy.py index 7806083..bc4d726 100644 --- a/scripts/verifyProxy.py +++ b/scripts/verifyProxy.py @@ -249,6 +249,10 @@ def main() -> None: stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) assert backend.stdin is not None + assert backend.stdout is not None + backend.stdin.write('"snapshot"\n') + backend.stdin.flush() + print(f"native after proxy drain: {backend.stdout.readline().strip()}", flush=True) backend.stdin.write('"stop"\n') backend.stdin.flush() exit_code = backend.wait(timeout=5)