Aspire

Diagnosing latency under load from Aspire metrics with an AI agent

Gérald Barré (Meziantou's blog) Gérald Barré
Aspire

Under load a one-millisecond query took 170 ms because ten pooled Npgsql connections were held across a pricing call, and the trace gap hid the cause. Gérald Barré shows how to hand dotnet-counters to an AI agent and read the metrics.

Key points

  • Aspire 13.5.4 exposes no metrics to agents: neither the MCP server nor `aspire otel` has a metrics command.
  • `dotnet-counters` reads `Npgsql` counters from the process, so the agent can compare `db.client.connection.count` with `db.client.connection.max`.
  • Ten used connections out of ten plus an empty thread-pool queue ruled out starvation and pointed at the pool.
  • In 462 of 462 traces both queries shared connection 100 while the 184 ms pricing-api call ran between them.
  • Moving the price lookup before `OpenConnectionAsync()` cut the stock endpoint's p50 from about 170 ms to under 1 ms.
  • The pid from `aspire describe` belongs to `dotnet run`, so collect by name with `-n InventoryApi` instead.

Why it matters

The valuable part is the workflow, not the bug: the agent reached the right conclusion because the traps — the wrapper process, the UpDownCounter deltas — were written into the skill beforehand. Pairing an assistant with dotnet-counters has the same failure mode: attaching to the wrong pid succeeds silently and writes an empty file, so confirm with `dotnet-counters ps` and select by name.

Before you copy the diagnosis: counters describe process state, not per-request causality, so they narrow the suspects only when read next to the trace gap and the connection id. And a saturated pool is usually an arithmetic problem — instance count times pool size against the database's connection limit — rather than a tuning knob.

Real-world use

  • An order pipeline whose reservation handler calls a pricing service while still holding a connection and a `FOR UPDATE` lock
  • Product-page reads that run a trivial query but queue behind write traffic on a shared pool
  • A service deployed as 10 instances against a database that accepts 100 connections in total

This summary was generated by the agent from the original post on Gérald Barré (Meziantou's blog). The full text and all rights belong to its author and publisher. Go to original

Report this story

Is something wrong with the summary, or do you own this content? Your message comes straight to my inbox.

Type of message

Related stories

Feedback

Found a bug or have an idea? Your message lands straight in my inbox.

Type of message