Skip to content

De-prioritize query parsing and planning during warmup process #7223

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 23 commits into from
Jun 3, 2025

Conversation

carodewig
Copy link
Contributor

@carodewig carodewig commented Apr 10, 2025

This PR lowers the priority of query parsing and planning during the warmup process. This will help reduce the impact of warmup on serving requests.

Open considerations:

  • I only changed the priority of parsing (not planning). This was for a few reasons - (1) changing the priority of planning will be much more complicated, and (2) I was worried that lowering the planning priority would excessively throttle the warmup and it would take way too long to complete. I'm happy to work on the planning side as well if desired.
    I received feedback that it would be better to have query planning also be deprioritized, so added that in 95caaa11.
  • I noticed that parsing was happening twice, so I removed the second instance. The downside of doing that is that if the parsing fails with a SpecError, that error will not be inserted into the cache. My suspicion is that skipping the second parsing for all cached queries will outperform the benefit of having the SpecError cached, but I'm happy to revert that if desired.

Fixes #3771


Checklist

Complete the checklist (and note appropriate exceptions) before the PR is marked ready-for-review.

  • Changes are compatible1
  • Documentation2 completed
  • Performance impact assessed and acceptable
  • Tests added and passing3
    • Unit Tests
    • Integration Tests
    • Manual Tests

Exceptions

Note any exceptions here

Notes

Footnotes

  1. It may be appropriate to bring upcoming changes to the attention of other (impacted) groups. Please endeavour to do this before seeking PR approval. The mechanism for doing this will vary considerably, so use your judgement as to how and when to do this.

  2. Configuration is an important part of many changes. Where applicable please try to document configuration examples.

  3. Tick whichever testing boxes are applicable. If you are adding Manual Tests, please document the manual testing (extensively) in the Exceptions.

@carodewig carodewig requested a review from a team as a code owner April 10, 2025 17:33
@svc-apollo-docs
Copy link
Collaborator

svc-apollo-docs commented Apr 10, 2025

✅ Docs preview has no changes

The preview was not built because there were no changes.

Build ID: c3657d448b01a47a013051bb

This comment has been minimized.

@router-perf
Copy link

router-perf bot commented Apr 10, 2025

CI performance tests

  • connectors-const - Connectors stress test that runs with a constant number of users
  • const - Basic stress test that runs with a constant number of users
  • demand-control-instrumented - A copy of the step test, but with demand control monitoring and metrics enabled
  • demand-control-uninstrumented - A copy of the step test, but with demand control monitoring enabled
  • enhanced-signature - Enhanced signature enabled
  • events - Stress test for events with a lot of users and deduplication ENABLED
  • events_big_cap_high_rate - Stress test for events with a lot of users, deduplication enabled and high rate event with a big queue capacity
  • events_big_cap_high_rate_callback - Stress test for events with a lot of users, deduplication enabled and high rate event with a big queue capacity using callback mode
  • events_callback - Stress test for events with a lot of users and deduplication ENABLED in callback mode
  • events_without_dedup - Stress test for events with a lot of users and deduplication DISABLED
  • events_without_dedup_callback - Stress test for events with a lot of users and deduplication DISABLED using callback mode
  • extended-reference-mode - Extended reference mode enabled
  • large-request - Stress test with a 1 MB request payload
  • no-tracing - Basic stress test, no tracing
  • reload - Reload test over a long period of time at a constant rate of users
  • step-jemalloc-tuning - Clone of the basic stress test for jemalloc tuning
  • step-local-metrics - Field stats that are generated from the router rather than FTV1
  • step-with-prometheus - A copy of the step test with the Prometheus metrics exporter enabled
  • step - Basic stress test that steps up the number of users over time
  • xlarge-request - Stress test with 10 MB request payload
  • xxlarge-request - Stress test with 100 MB request payload

@carodewig carodewig added the backport-1.x Backport this PR to 1.x label Apr 10, 2025
@goto-bus-stop
Copy link
Member

As a general comment (and not an immediate action item on this PR), it's worth noting that warmup currently happens sequentially, so if there's more than 1 worker it can already not saturate the pool. If parsing is deprioritised, planning will in effect also be deprioritised because everything is in sequence.

If we did make warmup work in parallel (which would probably be a good thing), i think it could be better to deprioritise both, but have planning one level more important than parsing in warmup.

@carodewig carodewig changed the title De-prioritize query parsing during warmup process De-prioritize query parsing and planning during warmup process Apr 15, 2025
@carodewig
Copy link
Contributor Author

NB: I don't love that I added compute_job_type to a bunch of functions, but wasn't sure how else to get it to the compute pool without a major refactor. I did consider adding it to PlanOptions, but seems more directly plan-specific and is included in the cache key.

@carodewig carodewig requested a review from a team as a code owner April 15, 2025 17:21
@BrynCooke
Copy link
Contributor

As a general comment (and not an immediate action item on this PR), it's worth noting that warmup currently happens sequentially, so if there's more than 1 worker it can already not saturate the pool. If parsing is deprioritised, planning will in effect also be deprioritised because everything is in sequence.

Query planning has to be scheduled at some time even if parsing has to happen first. When a user has set their compute job threads very low we need the planning during warmup to not interfere with serving requests.

@BrynCooke
Copy link
Contributor

Generally looks great, do we have any existing tests for the query plan warmup that we can extend?

@carodewig
Copy link
Contributor Author

Generally looks great, do we have any existing tests for the query plan warmup that we can extend?

@BrynCooke I added two tests - one to check that the relative priorities of the compute queue job types are respected, and one to make sure the query plan warm up process works. Let me know if you'd like any additional coverage!

@carodewig carodewig requested a review from SimonSapin April 17, 2025 14:18
@BrynCooke BrynCooke removed the backport-1.x Backport this PR to 1.x label Apr 23, 2025
@carodewig carodewig requested a review from a team April 29, 2025 14:52
@goto-bus-stop goto-bus-stop self-requested a review May 23, 2025 09:12
@SimonSapin
Copy link
Contributor

I noticed that parsing was happening twice, so I removed the second instance. The downside of doing that is that if the parsing fails with a SpecError, that error will not be inserted into the cache.

Was this reverted? I don’t see it happening in the diff

@goto-bus-stop goto-bus-stop removed their request for review May 27, 2025 07:01
@carodewig
Copy link
Contributor Author

I noticed that parsing was happening twice, so I removed the second instance. The downside of doing that is that if the parsing fails with a SpecError, that error will not be inserted into the cache.

Was this reverted? I don’t see it happening in the diff

@SimonSapin The second parse that I removed is here - this was being called after the first parse here.

@carodewig carodewig merged commit f391f2f into dev Jun 3, 2025
15 checks passed
@carodewig carodewig deleted the caroline/low-priority-warmup branch June 3, 2025 15:01
@abernix abernix mentioned this pull request Jul 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a priority queue to query planning
5 participants