optimise use of inv queries; tighten hpa watch predicate - #190
Merged
Conversation
tillrohrmann
approved these changes
Aug 14, 2026
tillrohrmann
left a comment
Contributor
There was a problem hiding this comment.
Thanks for implementing this optimization @lukebond. LGTM. +1 for merging :-)
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
we have observed in production when the HPA feature is used that excessive invocation status query load is placed on the restate server. on investigation, two issues were turned up, that this PR addresses:
sys_invocation_statustable, was being executed unnecessarily on each one of these reconciles. i've optimised this to only be called when necessarytogether these changes mean that the expensive query runs far less often. in the common case it's currently called every 15s and that has been removed. it still re-reconciles after 30s on error, but that should be exceptional.
i'll explain the optimisation, because it might not be obvious from the diff. the expensive
/querywas being called from withinlist_deployments()and passed toplan_registrationandcleanup_old_replicasets(). the former usage does not require the full query unless there is a version to register or promote, or a foreign takeover; in the simple case of a single version we can get the info from a cheaper source:GET /services. in the case ofcleanup_old_replicasets, the invocation counts are needed, so the costly query needs to run. my optimisation is to avoid callinglist_deploymentsin the simple case.note that there will still be scenarios where the query is being called a lot, and if we find that it's an issue we can consider some of the other options that have been explored, such as rate limiting and caching. the fix in this PR cuts out the call entirely when it is not necessary, so is the right place to start. given the query is currently firing every 15s, i expect this PR to make a big difference.