Coalesce concurrent identical fact queries #28

Open
opened 2026-09-13 14:04:19 +10:00 by unkin-agent · 0 comments
Member

Problem

Fact responses are no longer cached. Dropping the fact paths from cacheFor also bypasses s.flights.Do in serveFiltered (the !enabled branch calls build() directly), so single-flight coalescing was lost along with the cache.

Concurrent identical fact queries now each trigger a full two-backend, whole-estate fan-out. Puppetboard's facts overview page (views/facts.py, routes /facts and /<env>/facts) issues a query filtered only by environment, and query=None when "All Environments" is selected. Measured through pdbmux: ~3.4-3.8s and 14.7MB per request. Two simultaneous page loads cost two full fan-outs instead of one.

Proposal

Restore single-flight coalescing for the fact paths, independent of the response cache.

Coalescing merges requests that are identical and concurrently in flight. It stores nothing and serves nothing after completion, so it introduces no staleness and keeps fact caching out of the proxy. It is thundering-herd protection only.

Acceptance

  • N concurrent identical fact requests produce one backend fan-out; all N receive the same response.
  • Nothing is retained once the flight completes: a later identical request fans out again.
  • No X-Cache or Age headers on any fact response.
  • A failed flight is not shared as a success, and one client disconnecting does not cancel the others.
  • Tests cover concurrent requests against /pdb/query/v4/facts, /facts/<name> and /fact-names.
## Problem Fact responses are no longer cached. Dropping the fact paths from `cacheFor` also bypasses `s.flights.Do` in `serveFiltered` (the `!enabled` branch calls `build()` directly), so single-flight coalescing was lost along with the cache. Concurrent identical fact queries now each trigger a full two-backend, whole-estate fan-out. Puppetboard's facts overview page (`views/facts.py`, routes `/facts` and `/<env>/facts`) issues a query filtered only by environment, and `query=None` when "All Environments" is selected. Measured through pdbmux: ~3.4-3.8s and 14.7MB per request. Two simultaneous page loads cost two full fan-outs instead of one. ## Proposal Restore single-flight coalescing for the fact paths, independent of the response cache. Coalescing merges requests that are identical and concurrently in flight. It stores nothing and serves nothing after completion, so it introduces no staleness and keeps fact caching out of the proxy. It is thundering-herd protection only. ## Acceptance - N concurrent identical fact requests produce one backend fan-out; all N receive the same response. - Nothing is retained once the flight completes: a later identical request fans out again. - No `X-Cache` or `Age` headers on any fact response. - A failed flight is not shared as a success, and one client disconnecting does not cancel the others. - Tests cover concurrent requests against `/pdb/query/v4/facts`, `/facts/<name>` and `/fact-names`.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: unkin/pdbmux#28