-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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 memory allocation for s3 sending #1098
Comments
If you'd like to open a PR, happy to look at it. I think that if the unit tests are based on an assumption that would be changing, it would be okay to modify them (and then we can look at the change as a whole). |
(Accidental close.) |
+1 for this. We're seeing big memory spikes since upgrading a load of gems the last week (including AWS to v2) and I've spent most the day tracking down the culprit! |
We've been playing with this today and have found a small correction required to the above code:
|
I went ahead and added a pair of utility methods to the SDK: The sigv4 signer and S3 MD5 plugin both use these methods. This should improve memory usage in these scenarios. There are a couple of outstanding issues:
Please feel-free to re-open to discuss alternatives or also feel free to send a PR. |
Hello. In one of the processes used in my application we send a lot of data to s3 using this gem, and I noticed 2 methods are allocating a significant amount of memory, specifically these 2 methods:
https://github.com/aws/aws-sdk-ruby/blob/master/aws-sdk-core/lib/aws-sdk-core/plugins/s3_md5s.rb#L36
https://github.com/aws/aws-sdk-ruby/blob/master/aws-sdk-core/lib/aws-sdk-core/signers/v4.rb#L219
I experimented with them and came up with such implementation:
Which reduces the memory foorprint significantly. I wrote a small script to gather rss, and prepared this graph:
Both lines represent memory usage at given time, through the whole time of process. Orange line represents case when 2.2.16 version is used, red represents the process with my changes. Notice significant reduction of memory usage at the end. This is where s3 sending takes place. I also checked this with ruby-prof and memory_profiler, and the reduction is shown by alll of those tools. I was going to send PR, but some tests are not passing, and I also do realize this is probably not a change that can be done in a single file, since the
OpenSSL::Digest
seems to be used globally. However, the memory problem is real. How can we solve this?EDIT:
Most of the not passing tests check that input is being processed in one megabyte chunks. I think I can provide a PR with backwards compatible changes, where just files will be processed more efficiently.
The text was updated successfully, but these errors were encountered: