perf(net): reduce status transport and controller memory overhead - #744
Conversation
29bec0c to
2899cc3
Compare
2899cc3 to
72da951
Compare
72da951 to
6f9ec53
Compare
There was a problem hiding this comment.
🟢 Approval recommended
The changes are cohesive, extensively covered by new unit tests/benchmarks, and the updated node/controller implementations and documentation align with the stated transport and memory-reduction goals.
Pull request overview
This PR reduces allocation/CPU overhead in Unbounded net status transport by switching delta construction from JSON round-trips to typed protobuf deltas, adding a compact “peer measurements” delta path, and reusing buffers/writers in the controller WebSocket and gzip response paths.
Changes:
- Introduce typed protobuf
NodeStatusDeltafields (timestamps/errors/source/pod info) and compactPeerMeasurementscolumns guarded by identity digests and revision checks. - Update the node WebSocket publisher to batch critical vs stats updates, negotiate compact support via ACK, and enforce a single in-flight update per connection.
- Update the controller to decode protobuf frames once, apply compact peer-measurement deltas with bounded-cardinality metrics, reuse WebSocket frame buffers, and pool idle gzip writers; document the new behavior and scaling implications.
File summaries
| File | Description |
|---|---|
| internal/net/status/proto/status.proto | Adds peer_measurements capability to ACK, extends typed deltas, and defines PeerMeasurements compact columns. |
| internal/net/status/proto/status.pb.go | Regenerates Go protobuf bindings for the updated status schema. |
| internal/net/status/measurements.go | Adds shared helpers for peer identity digests, metadata comparison, and compact measurements encoding. |
| internal/net/status/measurements_test.go | Adds unit coverage for digest unambiguity, duplicate detection, and metadata equality behavior. |
| docs/net/operations.md | Documents connectivity-matrix omission threshold and controller transport pooling behavior. |
| docs/net/configuration.md | Updates transport semantics/docs: protobuf deltas, critical vs stats behavior, compact negotiation, and sizing guidance. |
| cmd/unbounded-net-node/status_websocket_auth_test.go | Adjusts WS tests to account for required initial ACK ordering. |
| cmd/unbounded-net-node/status_server.go | Removes JSON delta computation from production WS path; adds ACK gating, typed delta usage, peer sorting, and ACK timeout handling. |
| cmd/unbounded-net-node/status_proto.go | Removes JSON-delta-to-proto conversion; standardizes zero-time handling via statusUnixNano. |
| cmd/unbounded-net-node/status_legacy_delta_test.go | Retains legacy JSON delta helpers for compatibility tests/benchmarks only. |
| cmd/unbounded-net-node/status_delta.go | Adds typed delta construction, compact measurement selection, canonical peer ordering, and “critical vs stats” snapshot logic. |
| cmd/unbounded-net-node/status_delta_test.go | Adds extensive tests/benchmarks for typed delta semantics, compact compatibility, field clearing, ordering, and ACK negotiation. |
| cmd/unbounded-net-node/status_ack.go | Introduces per-connection ACK state (revision/resync/pending/compact) with protobuf+JSON fallback decoding. |
| cmd/unbounded-net-controller/ws_frame_buffer.go | Implements bounded size-class pooled frame buffers and a single-read frame acquisition path. |
| cmd/unbounded-net-controller/ws_frame_buffer_test.go | Adds correctness/ownership/allocation tests and benchmarks for pooled frame reads. |
| cmd/unbounded-net-controller/status_proto.go | Adds typed-delta parsing for new fields, single-decode protobuf WS handling, and measurement/full conflict checks. |
| cmd/unbounded-net-controller/status_proto_test.go | Updates tests to use the new decode+handle flow and validates identity extraction via decode. |
| cmd/unbounded-net-controller/server.go | Switches WS reads to pooled frame buffers; decodes protobuf once; pools gzip writers in the gzip handler. |
| cmd/unbounded-net-controller/proto_ws_identity_test.go | Adds tests ensuring protobuf identity validation happens before registration/cache mutation. |
| cmd/unbounded-net-controller/peer_measurements.go | Implements controller-side validation/application of compact measurement columns with optional identity memoization. |
| cmd/unbounded-net-controller/peer_measurements_test.go | Adds tests/benchmarks for compact apply behavior, immutability, rejection semantics, and ACK capability propagation. |
| cmd/unbounded-net-controller/peer_identity_cache_test.go | Adds tests/benchmarks for identity-digest memoization correctness, invalidation, and concurrency behavior. |
| cmd/unbounded-net-controller/node_status.go | Extends cache delta application to support compact measurements, typed clears, and a per-entry identity memo. |
| cmd/unbounded-net-controller/metrics.go | Adds bounded-cardinality metric for compact peer-measurement update outcomes. |
| cmd/unbounded-net-controller/memory_bench_test.go | Adds benchmarks for protobuf WS decode/apply and connectivity-matrix size gating. |
| cmd/unbounded-net-controller/matrix_memory_test.go | Adds tests ensuring oversize scopes omit matrices without mutating snapshots or copying peer data. |
| cmd/unbounded-net-controller/gzip_writer_pool.go | Introduces a small bounded pool for idle gzip writers to reduce per-request allocations. |
| cmd/unbounded-net-controller/gzip_writer_pool_test.go | Adds behavior equivalence tests, pooling bounds/detachment tests, failure-path tests, and benchmarks for gzip pooling. |
| cmd/unbounded-net-controller/cni_status_test.go | Updates proto WS handling in CNI guard tests to use the new decode+handle helper. |
| cmd/unbounded-net-controller/cluster_status.go | Avoids per-node peer-slice copies for connectivity matrices; filters peers at read time and enforces size gating. |
Review details
Files not reviewed (1)
- internal/net/status/proto/status.pb.go: Generated file
- Files reviewed: 29/30 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Use typed deltas and negotiated compact peer measurements with complete controller validation, connection-scoped acknowledgments, and legacy fallbacks. Decode WebSocket frames once, bound and reuse frame buffers and gzip writers, memoize validated peer identities, and avoid connectivity-matrix peer copies. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: d2243398-6c36-4c3d-969e-7ed7bfb5b459
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: d2243398-6c36-4c3d-969e-7ed7bfb5b459
6f9ec53 to
2b31c32
Compare
There was a problem hiding this comment.
🔵 Needs a closer look
The protocol, cache concurrency, authentication path, and pooled resource-lifecycle changes warrant final human review despite strong test coverage.
Review details
Files not reviewed (1)
- internal/net/status/proto/status.pb.go: Generated file
- Files reviewed: 29/30 changed files
- Comments generated: 0 new
- Review effort level: Balanced
Summary
Production status-transport and controller CPU/allocation reductions, based on #743. No simulator or e2e files are included.
Stack: #731 -> #743 (status collection) -> #744 (this PR) -> #745 (health checks).
Validation
internal/net/status/....make fmt,make lint(including actionlint), and controller/node builds passed.protocandprotoc-gen-go.These measurements are controlled microbenchmarks, not a whole-cluster performance guarantee. Dense peer caches still grow with topology size, active frames still require memory, and periodic full refreshes remain necessary.