Repository navigation
engine: prune DAGQL cache by metadata size - #13846
Conversation
Signed-off-by: Erik Sipsma <[email protected]>
Signed-off-by: Erik Sipsma <[email protected]>
Signed-off-by: Erik Sipsma <[email protected]>
Signed-off-by: Erik Sipsma <[email protected]>
Signed-off-by: Erik Sipsma <[email protected]>
Signed-off-by: Erik Sipsma <[email protected]>
Signed-off-by: Erik Sipsma <[email protected]>
Signed-off-by: Erik Sipsma <[email protected]>
Signed-off-by: Erik Sipsma <[email protected]>
Signed-off-by: Erik Sipsma <[email protected]>
Signed-off-by: Erik Sipsma <[email protected]>
Signed-off-by: Erik Sipsma <[email protected]>
Lower the class-slot coefficient to 768 bytes after the required 200k churn benchmark measured the 1024-byte hypothesis at a 2.199 estimate-to-post-GC-heap ratio. The calibrated coefficient measures 1.649 while preserving the approved structural formula and keeping a common one-million-entry graph above the 4 GiB trigger. Signed-off-by: Erik Sipsma <[email protected]>
Signed-off-by: Erik Sipsma <[email protected]>
Signed-off-by: Erik Sipsma <[email protected]>
Signed-off-by: Erik Sipsma <[email protected]>
Signed-off-by: Erik Sipsma <[email protected]>
Signed-off-by: Erik Sipsma <[email protected]>
Signed-off-by: Erik Sipsma <[email protected]>
505daef to
06c452b
Compare
Signed-off-by: Erik Sipsma <[email protected]>
There was a problem hiding this comment.
While testing this branch I think I might have found a small race in pruning. It may be a known trade-off, so genuine question at the end, AND, as it's best effort, approving to unblock. LGTMm after the linting issues get fixed ✅
The scenario:
- Pruning starts by taking a snapshot of the results that active sessions are using, and builds its plan from that.
- Right after that, a new session gets a cache hit on a persisted result.
- Pruning applies the plan and deletes that result's persisted edge. Before deleting, it re-checks the
unpruneableflag, but not whether a session started using the result in the meantime.
Nothing crashes: the session keeps its reference and finishes fine. But when the session closes, the result is dropped from the cache, so the next run has to rebuild it. This matters more with this PR, because metadata pruning now runs in the background whenever the estimate goes over the limit: exactly when sessions are live and getting hits.
I've tried checking the docs you made on the subject, it seems to read both ways: "ownership may have changed... The implementation accepts that", but also "prune will not cut it while it is still in that active closure".
I guess it's an accepted trade-off, just questioning wether it's worth closing?
In case it's the latter, I've made a small repro and a possible fix:
grouville/dagger@repro-dagql-prune-active-session-race
That scenario was present before the changes here and while it's a legit possibility it is indeed something we just accept as a tradeoff. The problem is that rechecking adds quite a bit of overhead (i.e. the fix you linked to has to re-scan a potentially large map while holding an contended lock and repeats that work for each edge being considered for removal). We don't want pruning to be a "stop-the-world" type GC and accept that what gets pruned and what gets retained is intrinsically timing and heuristic based anyways, which is okay since it's managing a cache (as opposed to a database or something). |
dagger 0.21.9 Created-by: HarmonybrewBot Commit-by: HarmonybrewBot Merged-by: HarmonybrewBot Description: Created by `brew bump` --- Created with `brew bump-formula-pr`.<details> <summary>release notes</summary> <pre>## v0.21.9 - 2026-08-25 ### Added - Added SSHFS-backed volumes, allowing remote filesystems to be mounted into containers without copying their contents into Dagger's content store by @sipsma in dagger/dagger#13462 ### Fixed - `Container.withDirectory` and `Directory.withDirectory` no longer restore by @sipsma in dagger/dagger#13848 \ deleted nested files after execs remove and recreate an ancestor directory. - Engine client enumeration no longer blocks behind another session's by @sipsma in dagger/dagger#13542 \ initialization or teardown, preventing Cloud keeper heartbeats from stalling and live engines from being suspended. - Session teardown now runs in the background after the main client disconnects, by @sipsma in dagger/dagger#13681 \ preventing shutdown responses from timing out while the engine releases session-owned cache results. - The engine now bounds retained DAGQL cache metadata independently of disk by @sipsma in dagger/dagger#13846 \ usage by pruning cold persisted results when the structural estimate exceeds its configured limit. This may mitigate metadata growth at scale while preserving active and engine-lifetime cache roots. - Registry protocol probes no longer appear as scary errors in progress output by @vito in dagger/dagger#13410 \ when image pulls or publishes succeed, while genuine registry failures remain visible. - Registry authentication no longer invalidates downstream container cache reuse across sessions when applied before or after `Container.from` by @sipsma in dagger/dagger#13901 ### What to do next? - Read the [documentation](https://docs.dagger.io) - Join our [Discord server](https://discord.gg/dagger-io) - Follow us on [Twitter](https://twitter.com/dagger_io) </pre> <p>View the full release notes at <a href="https://github.com/dagger/dagger/releases/tag/v0.21.9">https://github.com/dagger/dagger/releases/tag/v0.21.9</a>.</p> </details> <hr> See merge request: Harmonybrew/homebrew-core!17786
Summary
Persisted DAGQL cache roots can retain substantial in-memory result, e-graph, module, and schema state while consuming little or no physical cache space. Existing automatic pruning is triggered by disk usage, so those roots can remain indefinitely when disk thresholds are not crossed.
This change adds a coarse structural estimate for DAGQL cache metadata:
Reading the estimate is O(1) and allocation-free because these counts already exist in the cache. When the estimate exceeds the provisional 4 GiB maximum, the engine uses the existing pruning candidate order and ownership simulation to prune toward 3 GiB. This makes zero- and tiny-disk persisted roots eligible without weakening active-session or unpruneable-root protection.
Disk GC remains independent. Disk-stat failures do not suppress structural pruning, and structural no-progress suppression does not suppress disk policies. The persistence schema remains version 17; an oversized graph may still create an import peak before the scheduled startup trim.
The change also adds:
gc.dagqlCache.maxEstimatedBytesandtargetEstimatedBytesconfiguration;dagger_dagql_cache_metadata_estimated_bytes;The 4 GiB/3 GiB defaults are provisional rollout values. The estimate deliberately approximates cache-owned memory rather than attributing exact retained heap.
Performance
At one million results on the benchmark host:
Testing
On the rebased head:
The metadata-pressure E2E passed with trace
b22591406cd051b4de63502a8d7ae884; the metrics E2E passed with trace9146773cba455b106d9255c81edf24e8.After the lint-only follow-up commit, the affected server race suite and repository lint check also passed: