Skip to content
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

Allow disabling PQ-based QP cache rewarm when reloading schemas #5990

Merged
merged 1 commit into from
Sep 11, 2024

Conversation

glasser
Copy link
Member

@glasser glasser commented Sep 10, 2024

In #3829 we taught router to use the PQ list to prewarm the query planner cache when reloading its schema.

In #5340 we gave it the experimental option to do the same thing at startup.

Now we are allowing you to turn off the on-reload prewarm.

Because the PQ list does not have metadata to tell the Router which PQs have been used recently, if you have a large PQ list then the on-reload prewarm can slow down schema updates noticeably, and it may not provide much value over prewarming based on the contents of the in-memory QP cache itself.

We keep the same defaults, but let you turn off the on-reload prewarm with:

persisted_queries:
  experimental_prewarm_query_plan_cache:
    on_reload: false

Previously, persisted_queries.experimental_prewarm_query_plan_cache was a boolean; a migration moves this boolean to
persisted_queries.experimental_prewarm_query_plan_cache.on_startup. (on_startup defaults to false and on_reload defaults to true.)

This migration uses a type: change action. No such actions existed in the codebase and the implementation appeared to be buggy: there is no top-level == operator (or top-level operators at all) in JSONPath. This PR fixes the implementation of type: change to use the [?(@.x == y)] filter syntax which does appear to work (as tested by the migration tests for the new migration).

This also renames a migration file added in #5957 that used a non-standard filename.


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

I'm not sure where to put tests of the prewarming functionality; neither #3829 nor #5340 appear to have tests. (The migration is tested.)

Exceptions

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.

@glasser glasser requested review from a team as code owners September 10, 2024 22:32

This comment has been minimized.

@router-perf
Copy link

router-perf bot commented Sep 10, 2024

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

@glasser glasser force-pushed the glasser/qp-cache-prewarm-on-reload branch 2 times, most recently from 9ea2b7c to d279aab Compare September 10, 2024 22:50
(experimental_pql_prewarm && previous_cache.is_none()) || previous_cache.is_some();
let should_warm_with_pqs = (experimental_pql_prewarm.on_startup
&& previous_cache.is_none())
|| (experimental_pql_prewarm.on_reload && previous_cache.is_some());
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is the heart of the PR.

]),
))
.persisted_query(
PersistedQueries::builder()
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Switching to using the builder seemed more legible if I had to update this anyway.

Copy link
Contributor

@lleadbet lleadbet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks great, thanks for tackling this so quickly!

In #3829 we taught router to use the PQ list to prewarm the query
planner cache when reloading its schema.

In #5340 we gave it the experimental option to do the same thing at
startup.

Now we are allowing you to turn off the on-reload prewarm.

Because the PQ list does not have metadata to tell the Router which PQs
have been used recently, if you have a large PQ list then the on-reload
prewarm can slow down schema updates noticeably, and it may not provide
much value over prewarming based on the contents of the in-memory QP
cache itself.

We keep the same defaults, but let you turn off the on-reload prewarm
with:

```
persisted_queries:
  experimental_prewarm_query_plan_cache:
    on_reload: false
```

Previously, `persisted_queries.experimental_prewarm_query_plan_cache`
was a boolean; a migration moves this boolean to
`persisted_queries.experimental_prewarm_query_plan_cache.on_startup`.
(`on_startup` defaults to false and `on_reload` defaults to true.)

This migration uses a `type: change` action. No such actions existed in
the codebase and the implementation appeared to be buggy: there is no
top-level `==` operator (or top-level operators at all) in JSONPath.
This PR fixes the implementation of `type: change` to use the
`[?(@.x == y)]` filter syntax which does appear to work (as tested by
the migration tests for the new migration).

This also renames a migration file added in #5957 that used a
non-standard filename.
@glasser glasser force-pushed the glasser/qp-cache-prewarm-on-reload branch from d279aab to f175271 Compare September 10, 2024 22:58
@@ -144,7 +144,7 @@ fn apply_migration(config: &Value, migration: &Migration) -> Result<Value, Confi
}
}
Action::Change { path, from, to } => {
if !jsonpath_lib::select(config, &format!("$.{path} == {from}"))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW this syntax just seemed to be wrong (and the library ignored everything after the space without an error?)

https://freestrings.github.io/jsonpath/ can be used to test this jsonpath_lib implementation.

@@ -63,6 +61,8 @@ supergraph:
warmed_up_queries: 100
```

(In addition, the router can use the contents of the [persisted query list](./persisted-queries) to prewarm the cache. By default, it does this when loading a new schema but not on startup; you can [configure](./persisted-queries#persisted-queries#experimental_prewarm_query_plan_cache) it to change either of these defaults.)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I might have gotten this wrong from the slack convo, but aren't we changing the default to be "warm PQs at startup" with an additional option to "warm PQs at schema reload"?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're changing it so that you can disable pre-warming on schema change which is a default behavior at the moment. Warming PQs on startup is an option that remains unchanged.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(although the option's name is changing, with migration)

@glasser glasser merged commit 7e7e05f into dev Sep 11, 2024
13 of 14 checks passed
@glasser glasser deleted the glasser/qp-cache-prewarm-on-reload branch September 11, 2024 15:11
@abernix abernix mentioned this pull request Sep 24, 2024
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.

6 participants