Repository navigation
Reuse fleet offer queries in preset previews - #4542
Open
pinggaozhanshi wants to merge 2 commits into
Open
pinggaozhanshi wants to merge 2 commits into
pinggaozhanshi wants to merge 2 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #4531
When a preset leaves
fleetsunset, the preview requests offers across all active fleets. The planner could query the same backend project repeatedly with identical constraints, then deduplicate each full result on the server event loop.Reuse results per job plan for fleets with the same backend project, effective profile, requirements, and cluster placement constraints. Deduplicate and merge the offers in a worker thread. The response still contains the exact total and maximum price before the displayed list is truncated, including for
dstack offer --fleet.Reproduction
Use a project with several active fleets that share the same backend and constraints. Run
dstack apply -f preset.dstack.ymlwith a valid preset configuration that omitsfleets. Inspect the offer preview before confirming creation. On the base revision, the planner runs a backend offer query for each fleet while the preview shows at most ten offers. The test and benchmark below reproduce the query count without provisioning cloud instances.Validation
Test Buildworkflow runs lint, Pyright, and the Python suite for PRs targetingmaster.Run the regressions on Linux or macOS with the standard test runner. The PostgreSQL variant uses Docker.
uv sync --all-extras uv run pytest src/tests/_internal/server/services/runs/test_plan.py -k "reuses_identical_queries or deduplicates_offers_off_the_event_loop" --runpostgresLocal benchmark
The benchmark ran the preset preview code against a simulated backend on Windows with Python 3.13.2. Both cases used 40 fleets and a total of 2,000 distinct offers. Each revision was measured three times, with
d79b426as the base and6c85b19as the patch. The final column is the median of each trial’s maximum delay for a 10 ms event-loop heartbeat.Both revisions returned the same first 10 offers, total of 2,000, and maximum price of $20.00 per hour in every trial.
Reproduce the benchmark
Save the script as
benchmark_preset_offers.py. In each checkout, runuv sync --all-extrasfollowed byuv run python /path/to/benchmark_preset_offers.py. The script uses the real preview and planner with a synthetic catalog and checks the output in each trial.