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 generate ec2 #4199

Merged
merged 2 commits into from
Aug 16, 2021
Merged

Conversation

aidy
Copy link
Contributor

@aidy aidy commented Jul 15, 2021

The pricing json for us-east-1 is currently 129MB. Currently fetching
this into memory and parsing results in a large memory footprint on
startup, and can lead to the autoscaler being OOMKilled.

Change the ReadAll/Unmarshal logic to a stream decoder to significantly
reduce the memory use.

Should hopefully address #3506

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Jul 15, 2021
@k8s-ci-robot
Copy link
Contributor

Welcome @aidy!

It looks like this is your first PR to kubernetes/autoscaler 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes/autoscaler has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot k8s-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Jul 15, 2021
@gjtempleton
Copy link
Member

/assign @gjtempleton

@gjtempleton
Copy link
Member

Thanks for the PR!

I don't suppose you have any metrics on what the memory improvements when using this approach are?

Comment on lines +142 to +143
func TestUnmarshalProductsResponse(t *testing.T) {
body := `
Copy link
Member

Choose a reason for hiding this comment

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

Can we add a test for an invalid json response as well as valid?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll see what I can knock up

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've added some tests for invalid json (and fixed a bug in the process). Shout if you'd like me to rebase them down.

@aidy
Copy link
Contributor Author

aidy commented Jul 19, 2021

I don't suppose you have any metrics on what the memory improvements when using this approach are?

It's pretty hacky, but I used https://gist.github.com/aidy/52ba395599be28bcdd04d4469d6f958a

Using ReadAll/Unmarshal had a final output footprint of:
Alloc = 396 MiB TotalAlloc = 530 MiB Sys = 600 MiB NumGC = 12

Proposed mechanism results in:
Alloc = 8 MiB TotalAlloc = 17 MiB Sys = 71 MiB NumGC = 7

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 22, 2021
@aidy aidy force-pushed the optimise_generate_ec2 branch from 8a36c5a to 504ecb4 Compare July 23, 2021 08:33
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 23, 2021
@gjtempleton
Copy link
Member

Thanks for the tests.
If you could rebase down to 1 commit now, that would be great!

@mwielgus could you kick off the pending GH workflows please just to be sure? Docs for that are here.

Refactor to allow for optimisation
@aidy aidy force-pushed the optimise_generate_ec2 branch from 504ecb4 to e1dc0af Compare August 9, 2021 09:47
@aidy
Copy link
Contributor Author

aidy commented Aug 9, 2021

If you could rebase down to 1 commit now, that would be great!

I'd intended this as two commits, to demonstrate that there was no functional change involved with this optimisation.
I've rebased as such - if you'd still prefer a single commit, I'm happy to squash :)

@gjtempleton
Copy link
Member

Yup, that makes good sense!

Lets keep it as is.

"github.com/aws/aws-sdk-go/aws/ec2metadata"
"github.com/aws/aws-sdk-go/aws/endpoints"
"github.com/aws/aws-sdk-go/aws/session"
"io"
"io/ioutil"
Copy link
Member

Choose a reason for hiding this comment

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

Looks like we no longer use this import, can you please remove it as it'll cause tests to fail otherwise.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, must have changed between rebasing. Otherwise goimports would have fixed it for me. I'll sort that now.

The pricing json for us-east-1 is currently 129MB. Currently fetching
this into memory and parsing results in a large memory footprint on
startup, and can lead to the autoscaler being OOMKilled.

Change the ReadAll/Unmarshal logic to a stream decoder to significantly
reduce the memory use.
@aidy aidy force-pushed the optimise_generate_ec2 branch from e1dc0af to 1177ee0 Compare August 16, 2021 10:13
@gjtempleton
Copy link
Member

Thanks for that.

I've done a manual run of the Github test-and-verify action's steps on my local machine, and all passes now. As I'm keen to get this into the next batch of patch releases:

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Aug 16, 2021
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: aidy, gjtempleton

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 16, 2021
@k8s-ci-robot k8s-ci-robot merged commit b01f84c into kubernetes:master Aug 16, 2021
k8s-ci-robot added a commit that referenced this pull request Aug 16, 2021
…999-#4199-upstream-cluster-autoscaler-release-1.22

Automated cherry pick of #3999 #4199 upstream cluster autoscaler release 1.22
k8s-ci-robot added a commit that referenced this pull request Aug 16, 2021
…999-#4199-upstream-cluster-autoscaler-release-1.20

Automated cherry pick of #3999 #4127 #4199 upstream cluster autoscaler release 1.20
k8s-ci-robot added a commit that referenced this pull request Aug 16, 2021
…999-#4199-upstream-cluster-autoscaler-release-1.19

Automated cherry pick of #3999 #4127 #4199 upstream cluster autoscaler release 1.19
k8s-ci-robot added a commit that referenced this pull request Aug 17, 2021
…999-#4199-upstream-cluster-autoscaler-release-1.21

Automated cherry pick of #3999 #4127 #4199 upstream cluster autoscaler release 1.21
aidy added a commit to cookpad/terraform-aws-eks that referenced this pull request Nov 10, 2021
cluster-autoscaler v1.21.1 includes:
kubernetes/autoscaler#4199

This should mean we can revert to the default memory requirements.
aidy added a commit to cookpad/terraform-aws-eks that referenced this pull request Nov 16, 2021
cluster-autoscaler v1.21.1 includes:
kubernetes/autoscaler#4199

This should mean we can revert to the default memory requirements.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. area/cluster-autoscaler cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants