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

Speed up pack action registration through the /v1/packs/register API endpoint #4342

Merged
merged 5 commits into from
Sep 24, 2018

Conversation

Kami
Copy link
Member

@Kami Kami commented Sep 14, 2018

This pull request speeds up registering pack actions through the /v1/packs/register API endpoint (e.g. when using st2 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 database N times where N is number of actions in a pack and now it's only retrieved M times where M is number of unique runners referenced by actions in a particular pack (in aws pack that's 1 - Python runner).

Some hard data.

Before this change:

2018-09-14 10:29:23,180 INFO [-] 8f73eafd-f38c-432e-9156-ca7f1d8f67ae - 200 194 114645.359ms (content_length=194,request_id='8f73eafd-f38c-432e-9156-ca7f1d8f67ae',runtime=114645.359,remote_addr='127.0.0.1',status=200,method='POST',path='/packs/register')

After this change:

2018-09-14 10:31:51,825 INFO [-] 2860c91e-f93e-48df-ba1a-465d5bf3f4ed - 200 194 96030.742ms (content_length=194,request_id='2860c91e-f93e-48df-ba1a-465d5bf3f4ed',runtime=96030.742,remote_addr='127.0.0.1',status=200,method='POST',path='/packs/register')

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).

Previously we retrieved runner object N times where N times was number
of actions inside the pack. Now we retrieved it M times where M is
nummber of unique runners actions in a particular pack reference.

In packs with a lot of actions which use the same runner (e.g. AWS)
this speeds pack registration by 10-20 seconds.
@Kami Kami added this to the 2.9.0 milestone Sep 14, 2018
@Kami Kami modified the milestones: 2.9.0, 3.0.0 Sep 24, 2018
@Kami Kami merged commit 10fdbb0 into master Sep 24, 2018
@Kami Kami deleted the action_registration_speed_up branch September 24, 2018 10:10
@Kami Kami modified the milestones: 3.0.0, 2.9.1 Sep 28, 2018
@Kami Kami mentioned this pull request Sep 28, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants