Skip to content

perf(hscontrol): fixes latency due to loading machines from db - #6

Open
amitsingh21 wants to merge 6 commits into
rr-release-0.22.3from
perf/prefetch-machines
Open

perf(hscontrol): fixes latency due to loading machines from db#6
amitsingh21 wants to merge 6 commits into
rr-release-0.22.3from
perf/prefetch-machines

Conversation

@amitsingh21

Copy link
Copy Markdown
  • read the CONTRIBUTING guidelines
  • raised a GitHub issue or discussed it on the projects chat beforehand
  • added unit tests
  • added integration tests
  • updated documentation if needed
  • updated CHANGELOG.md

amitsingh21 and others added 6 commits March 4, 2025 18:41
When expandAlias falls through to getIPsForUser for a non-user alias
(e.g. CIDR destinations like "10.81.48.0/24"), filterMachinesByUser
returns an empty slice. The subsequent excludeCorrectlyTaggedNodes
call then iterates every entry in aclPolicy.TagOwners (1502 in our
prod policy) and allocates a fresh tags slice, only to operate on
an empty machine set. Short-circuit before that wasteful work.

Output is bit-identical: excludeCorrectlyTaggedNodes returns an empty
slice when given empty nodes, which already hits the
"if len(filteredMachines) == 0" branch below. The new check just
avoids the wasted iteration and allocations in between.

Measured on io-prod (perf-iter4 -> perf-iter5):
- Pod CPU: 4.6 -> 3.0 cores (-33%, -1.5 cores) sustained.
- runtime.scanobject (GC): -63%.
- gcBgMarkWorker: -46%.

Local bench against real prod data (901 machines, 1502-rule policy):
- ns/op:     85.1 ms -> 59.0 ms  (-31%)
- B/op:      30.2 MB -> 7.49 MB  (-75%)
- allocs/op: 456,485 -> 50,659   (-89%)
Default gRPC limit is 4 MiB. The DB-backed ACL policy and large node
lists now exceed it, producing "received message larger than max
(4194314 vs. 4194304)" on the REST -> grpc-gateway -> socket path.

Raise MaxRecvMsgSize on the local socket server, remote TLS server,
grpc-gateway client dial, and CLI client to 64 MiB.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
2026-07-10 outage: the network path between AKS and Azure Postgres
silently dropped all established connections (no RST). Every pool
connection sat in ExecPrepared waiting on a dead socket; the pgx
default dialer keepalive of 5m left the kernel probing for the better
part of an hour, and with the pool exhausted (max 10) every handler
and the health check queued behind it until a manual restart.

Harden the postgres connection path:
- aggressive TCP keepalive (idle 15s, interval 5s, count 4)
- TCP_USER_TIMEOUT 30s so writes into dead flows also fail fast
  (keepalive only covers idle sockets; Linux-only, build-tagged)
- 10s connect timeout
- statement_timeout / idle_in_transaction_session_timeout 60s
- pool 10 -> 25, recycle idle conns after 5m (Azure middleboxes
  silently expire idle flows)

Verified against a real black-hole (docker postgres + iptables DROP
mid-query): dead connection now fails in ~30s and the pool self-heals;
previously the idle-read case took 461s in the lab and never recovered
in production.

Co-Authored-By: Claude Fable 5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant