Skip to content

mesh-dns CPU +11% net despite #674: OTel log batching (TryDequeue 6.7%) exceeds the authoritative path; ~45 core-s/25min unexplained (--debug=true?) #684

Closed

Description

@bpalermo

Summary

mesh-dns total CPU went up 11% between the 09-04 and 09-05 soak profiling passes (278.00 → 308.65 core-seconds per 25 min fleet-wide, 0.185 → 0.206 fleet cores) despite #674 removing ≥56 core-seconds of DialContext. Load is comparable (forwarded ~48.5 q/s both days). So ~76 core-seconds of new cost appeared, and the pass could only attribute ~40% of it.

What is accounted for

  1. The exec readiness probe — ~10 core-seconds (filed separately as the proxy readiness probe re-execs the whole agent binary every 2s: >=31% of supervisor CPU is Go package init #673-redux issue).
  2. OTel log batching: log.(*queue).TryDequeue = 20.70 core-seconds (6.71%), with mallocgc 11.15 and memclrNoHeapPointers 8.60 beneath it. That is larger than the entire authoritative mesh-name path (8.10 core-seconds). A dequeue loop that allocates and zeroes memory this heavily at a modest log rate looks like either a busy-poll in the log processor's batch queue or per-record allocation on the export path. Worth reading the OTel SDK log-processor version in go.mod and the exporter config in common/telemetry — and checking whether mesh-dns's --debug=true (it IS on in the deployed DaemonSet args) is what feeds this queue.

Those two are ~31 of the ~76 core-seconds. ~45 core-seconds are unexplained.

Candidates for the remainder (not measured)

  • --debug=true on the DaemonSet: per-query debug logging on the forward path would scale with QPS and would show up exactly as item 2 plus scattered slog/fmt frames.
  • The pool's ExchangeWithConnContext read loop draining mismatched IDs (it is 53.10 vs 51.34 core-seconds, +3% — flat, so probably not).
  • GC pressure from the log records (mallocgc under TryDequeue says yes).

Ask

  1. Confirm whether --debug=true is intentional on mesh-dns in production and what it logs per query; if it is the driver, the fix is a chart default, not code.
  2. Profile mesh-dns once with debug off to bound item 2.
  3. Re-baseline: after the exec-probe fix and whatever (1)–(2) yields, mesh-dns should land below the 09-04 figure by roughly mesh-dns: forwarded path is ~93% of CPU and dials a fresh UDP socket per query (DialContext 20.97% > Exchange 18.47%) #674's saving.

Numbers from the 2026-09-05 soak profiling pass ({service_name="aether-mesh-dns"}, 07:08–07:33Z, cutoff 0.70%), compared in core-seconds because the two windows differed by 11% in load and the 10% share-comparison rule did not allow a share comparison. Related: #674 (the pool), the mesh-dns exec-probe issue.

Activity

  1. bpalermo commented on Sep 5, 2026

    @bpalermo
    OwnerAuthor

    Root cause of the TryDequeue cost — and it is not --debug, and not mesh-dns-specific

    Investigated while implementing #683 (PR #688):

    • --debug on mesh-dns is log-level only (common/log.levelFor, Info→Trace). The mesh-DNS forward path has no per-query log call at any level — the only Debug site in agent/internal/meshdns is the snapshot reload. So there was never any log volume for --debug to add on the hot path, and flipping it (done in perf(mesh-dns): stdlib-only readiness prober, and --debug off by default (#683, #684) #688, scoped to a new agent.meshDnsDaemon.debug, default false) will move TryDequeue very little. The chart change still ships, but treat a large post-deploy drop in TryDequeue as evidence this analysis is wrong.

    • The actual cost is a fixed ~1 Hz allocation in the OTel SDK log batch processor, independent of log volume. common/telemetry builds the logger provider with NewBatchProcessor on all defaults (otel/sdk/[email protected]: dfltExpInterval = 1s, dfltExpMaxBatchSize = 512). The processor's poll allocates buf := make([]Record, 512) and ticks every second; bufferExporter.EnqueueExport returns true for an empty slice, so the export callback "succeeds" on an empty queue and poll then runs buf = slices.Clone(buf) on the full 512-element buffer — allocating and zeroing a fresh []Record (each carrying a 5-element inline attribute array) once per second, forever, on every process that uses the shared provider. That is exactly the mallocgc / memclrNoHeapPointers beneath log.(*queue).TryDequeue in the profile.

    So this is a fleet-wide fixed tax paid by the agent, mesh-dns, controller, registrar and edge alike, most visible on mesh-dns only because its total is small.

    Fix direction (separate PR; touches every component)

    In common/telemetry's log provider setup, pass explicit log.WithExportInterval(...) / log.WithExportMaxBatchSize(...) (a larger interval and a batch size sized to real log rates), and check whether a newer otel/sdk/log fixes the empty-queue clone (it looks like an upstream inefficiency worth an issue there too — the clone should be skipped when the dequeue returned nothing). Measure on one component before and after with the Pyroscope query in the 09-05 profiling record.

    The remaining ~45 unexplained core-seconds in this issue are still unexplained; this accounts for the TryDequeue term only.

  2. bpalermo commented on Sep 5, 2026

    @bpalermo
    OwnerAuthor

    Correction — the previous comment's root cause was wrong; --debug=false DID collapse the cost

    Measured after #688 deployed (helm rev193, 2026-09-05 13:16Z), Pyroscope {service_name="aether-mesh-dns"}, normalised by window length:

    pre (12:30–13:00Z, 1800s) post (13:19–13:28Z, 555s)
    mesh-dns fleet cores 0.1909 0.0944 (−50.6%)
    log.(*queue).TryDequeue 34.35 core-s = 10.00% = 0.0191 cores 0.55 core-s = 1.05% = 0.00099 cores (19.3× lower)

    So the TryDequeue cost was overwhelmingly driven by debug log records, not by a fixed 1 Hz allocation. The previous comment's claim ("independent of log volume … will move very little") is withdrawn. The SDK's empty-queue slices.Clone is real but small (~0.001 cores fleet-wide); it is not worth a change on its own.

    Where the debug records came from, given that agent/internal/meshdns has no per-query log call: the remaining candidates are library-level debug logging reaching the handler at Trace level (miekg/dns, the OTel SDK's own diagnostics, slog handlers wrapped by common/log) — not measured. The effect is what matters: #688 halved mesh-dns CPU, and TryDequeue accounts for ~19% of that saving; the rest is elsewhere in record construction under the same level gate.

    Two further observations from the same profile, for whoever picks this up:

    • The runc/libcontainer.linuxSetnsInit.Init/second-runtime.main frames from the exec probe are still present at roughly the same absolute cost (0.005 → 0.004 cores) — their share rose only because the denominator halved. mesh-dns: exec readiness probe re-launches the whole daemon every 15s (~3–4% of mesh-dns CPU) — #673 redux #683 shrank what the probe binary does, not the kubelet→runc→setns entry, which is inherent to any exec probe.
    • New in the post profile: seccomp.InitSeccomp → bpf_int_jit_compile 3.30 core-s (6.3%) — the exec probe's seccomp filter JIT-compiled on every entry. At that absolute rate it should have been ~3% of the pre-window, above its 1.73% cutoff, yet it was not there. Needs a depth-400 re-read of the pre-window to tell "unmasked" from "new tax"; if new, the probe's securityContext/seccomp profile is the lever.

    The "~45 core-seconds unexplained" from the original filing is superseded: with mesh-dns now at 0.094 cores, the remaining budget is serve/exchange plus the probe entry, and the +11% the issue opened on is gone.

  3. bpalermo commented on Sep 5, 2026

    @bpalermo
    OwnerAuthor

    Closing — the premise is gone. After #688 (mesh-dns-ready prober + --debug off) mesh-dns CPU went 0.191 → 0.094 fleet cores (−50.6%), the TryDequeue term collapsed 19× (0.0191 → 0.00099 cores), and the "+11% net" this issue opened on is now a net halving. The first root-cause comment here (fixed 1 Hz SDK allocation) was wrong and is withdrawn; debug records were the driver. The two other findings are recorded for whoever profiles mesh-dns next: the exec probe's runc/setns entry cost is unchanged in absolute terms (inherent to any exec probe; #683's binary shrank the payload, not the entry), and the post-#688 profile shows seccomp.InitSeccomp → bpf_int_jit_compile at 6.3% (3.30 core-s/25min) that was not visible in the pre-window — worth a depth-400 re-read of a pre-#688 window to tell "unmasked" from "new tax" before anyone acts on it. Not worth keeping this issue open for.

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