Skip to content

mesh-dns: forwarded path is ~93% of CPU and dials a fresh UDP socket per query (DialContext 20.97% > Exchange 18.47%) #674

Closed

Description

@bpalermo

Summary

Continuous profiling shows that ~93% of mesh-dns CPU is spent on the forwarded (non-mesh) path, and that within that path the single largest frame is dialing a fresh UDP socket for every forwarded query, not the exchange itself.

Measurement

Pyroscope, {service_name="aether-mesh-dns"}, process_cpu:cpu:nanoseconds, 2026-09-04 07:05–07:30Z, fleet-wide (5 nodes), during a steady-state soak:

frame % of mesh-dns CPU
ServeDNS / serve 42.50%
└ exchange (forward to upstream) 39.68%
  └ DialContext 20.97%
  └ Exchange (the actual query) 18.47%
authoritative mesh path (<svc>.<ns>.aether.internal) ~3%

Two things fall out of this:

  1. The forwarded path costs ~13× the authoritative path. The mesh records we actually serve from the snapshot are nearly free; almost all of the daemon's work is proxying everything else to kube-dns.
  2. DialContext exceeds Exchange. We spend more CPU creating the socket than using it — the classic signature of one fresh UDP conn per query with no reuse. dnsmsg/Client.Exchange in miekg/dns dials per call unless a connection is supplied.

Absolute cost is small (mesh-dns is a minor consumer fleet-wide), so this is an efficiency issue, not an incident. But roughly one fifth of the daemon's total CPU is socket setup that a pooled or persistent upstream connection would remove, and it scales linearly with forwarded QPS — which is most of the traffic.

Suggested direction

Reuse upstream connections on the forward path rather than dialing per query. Options, roughly in order of effort:

  • A small pool of long-lived UDP *dns.Conn per upstream, with Client.ExchangeWithConn.
  • dns.Client with SingleInflight for duplicate-query coalescing (helps the burst case, not the steady case).
  • TCP/DoT keepalive to upstream if we ever want the connection reuse to be unambiguous — heavier, and probably not worth it for node-local kube-dns.

Care needed on two points: UDP source-port randomisation is a spoofing defence, so a pool must still rotate ports rather than pinning one; and a pooled conn must not serialise concurrent queries behind a single socket's read loop, which would trade CPU for latency.

Context

Found during the dedicated profiling pass of the 2026-09-04 soak. Not a regression — mesh-dns had zero errors on the authoritative path and all dns_* prober series were clean for the whole run. Filing so the forward-path cost is on record rather than rediscovered.

Activity

  1. bpalermo commented on Sep 5, 2026

    @bpalermo
    OwnerAuthor

    Production validation — 8h soak 2026-09-05, rev192 / chart 0.92.0 / a3cde6c

    Auto-closed by its PR merge on 2026-09-04T21:24Z, before deploy. Recording the production evidence.

    The gate — forwarded p99 must not regress. histogram_quantile(0.99, sum by (le) (rate(aether_mesh_dns_query_duration_seconds_bucket{result="forwarded"}[5m]))), range 01:00→09:06Z step 5m, 98 points:

    • min 83.5ms (08:30Z), max 99.0ms (03:45Z), last 88.6ms (09:05Z)
    • vs pre-deploy 137ms → −35.3%; vs T0 (90.6ms) −2.1%. Gate PASSES, flat all night in an 83–99ms band across 31 rolls.

    Dial elimination holds. sum(rate(aether_mesh_dns_forward_conn_dials_total[15m])) / sum(rate(aether_mesh_dns_query_duration_seconds_count{result="forwarded"}[15m])) = 0.0272 → 1 dial per ~37 forwarded queries (was 1:1). Flat against T0's 0.0274 and the 03:32Z checkpoint's 0.0269.

    Pool. aether_mesh_dns_forward_conn_pool_open = 8 on all 5 nodes. Fleet sum held at 40 for the whole window; the only dips are the three mesh-dns DaemonSet rolls (e.g. 06:50:51Z: 40 → 32 → 8 → 40 across two 1-min samples). A naive min_over_time(...[8h]) returns 0 for that reason — it is the rolling restart, not pool loss.

    Recycles. aether_mesh_dns_forward_conn_recycles_total{reason="error"} = 1 on w01, 1 on w05, absent on the other three against {reason="rotated"} 2103/2112/2105/2131/2109 — 2 errors in ~10,560 rotations (0.019%). Note these counters reset on every mesh-dns roll; the values above are the current generation only (rolled 06:50:51Z, ~2h18m of counter at read time).

    Profiling (07:08:30–07:33:30Z): DialContext 58.30 core-s → absent (<2.15 core-s), ≥−96%; ExchangeWithConnContext 51.34→53.10 (flat — the entire win is dial elimination); dial rate flat 1.28–1.34/s over 6.5h. The predicted authoritative-path denominator artifact did not even materialise (2.82pp→2.63pp).

    Verdict: holds in production. Staying closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions