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

Optimise activation speed #119

Merged

Conversation

vitch
Copy link
Contributor

@vitch vitch commented Jul 4, 2022

What Changed & Why

I noticed that the activation step of our deployments was getting pretty slow. When digging into it I figured out that it's because we have 60,000+ revisions for each app deployed and the activation process uses S3's ListObjects no fewer than 3 times to get that list of revisions. This gets to be pretty slooooow!

This PR includes the first simple changes which don't change existing functionality. In a couple of places the list of all revisions were being loaded just to figure out if the passed revision was valid. Instead we can pass a prefix to ListObjects which is the entire key we are searching for. Rather than downloading them all and searching them clientside we just try to download the one we want.

For one of our apps with a fair amount of history (just over 60,000 deployments) this takes the activation down from 835s to 590s (a 30% reduction on my computer and internet connection - probably a bit better from CI!).

There are still two places in the flow where we download the entire list of deployed items but the fix there is less simple...

Related issues

I discuss potential follow up tasks in #120

PR Checklist

  • Add tests (I didn't add any tests but I verified that tests exist for the specific functionality I tested and that they still pass)
  • Add documentation (I'm not sure this needs to be called out in documentation?)
  • Prefix documentation-only commits with [DOC] (N/A if there is no docs?)

People

All maintainers ;)

Kelvin Luck added 3 commits July 4, 2022 14:47
Prior to this change, when you tried to activate a revision we list *all* revisions to
try and discover if the passed argument is valid. In our case this ends up fetching
tens of thousands of revisions from s3 which is kinda slow...

It turns out that the AWS `listObjects` function takes a prefix (this is already used
in the code to somewhat limit the results). We can pass the entire expected filename
and retrieve exactly one record (which is of course much much faster)
I guess there is the possibility that we could have retrieved
information about a revision with a `Key` which *starts with*
the `Prefix` we passed (rather than the entire filename
being the prefix we passed).

It's pretty easy to guard against this edge case so let's do
so...
We were again grabbing _every_ uploaded revision in order to be
able to check if you were trying to overwrite a revision. This is slow
when you have many revisions uploaded to s3.

Here we prefer our new `findRevision` method which uses the
`Prefix` to load information about _just_ the revision we're interested
in.
Copy link
Contributor

@lukemelia lukemelia left a comment

Choose a reason for hiding this comment

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

Nice improvement!

@lukemelia lukemelia merged commit 0b63c6f into ember-cli-deploy:master Jul 4, 2022
@vitch vitch deleted the optimise-activation-speed branch July 4, 2022 16:26
@vitch
Copy link
Contributor Author

vitch commented Jul 4, 2022

Thanks for the quick merge!

Hopefully the failing build isn't my fault?

The build phase is set to "MSBuild" mode (default), but no Visual Studio project or solution files were found in the root directory. If you are not building Visual Studio project switch build mode to "Script" and provide your custom build command.

@lukemelia
Copy link
Contributor

Hopefully the failing build isn't my fault?

I doubt that is the case. @LevelbossMike any insight into this?

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.

None yet

2 participants