Speed up pack action registration through the /v1/packs/register API endpoint #4342
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.
This pull request speeds up registering pack actions through the
/v1/packs/register
API endpoint (e.g. when usingst2 pack install
command).We do that by caching
RunnerTypeDB
objects in memory for each "register session" (aka each time user hits/v1/packs/register
API endpoint). Since we re-initialize the cache on each API request, this means there are no issues with potential stale cache, but we still see benefits when registering packs with a lot of resources.This helps in situations where pack has a lot of actions such as the
aws
pack. Previously RunnerTypeDB was retrieved from the databaseN
times whereN
is number of actions in a pack and now it's only retrievedM
times whereM
is number of unique runners referenced by actions in a particular pack (inaws
pack that's 1 - Python runner).Some hard data.
Before this change:
After this change:
So around ~18 seconds improvement.
96 seconds is still a very long time, but the whole platform was not designed around "packs with many actions" in mind. Just reading and validating all the action metadata from disk takes around ~60 seconds (not taking into account saving this metadata to the database).