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

feat(lib-storage): improve performance by reducing expensive buffer concat operations #1955

Closed
wants to merge 1 commit into from

Conversation

monken
Copy link

@monken monken commented Jan 24, 2021

Issue #1841

Description of changes:

The for await syntax reads chunks from a readable stream and is in my opinion more concise and less error prone as NodeJS will take care of event handlers, exception handling, etc.

In addition, Buffer.concat will only be called once per chunk which greatly improves performance (uploading a 1GB file would take 23 seconds previously, down to 10 seconds with this patch). The use of Buffer.slice is intentional as it does not copy or create a new buffer. Instead, it's basically a view into the buffer it slices over.

I ran a few profiling runs over the code and I think there is more room for improvement. V2 of the SDK still seems to be ~20 percent faster. For example, v3 calls update from internal/crypto/hash.js twice as many times as v2.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@samsullivan
Copy link
Contributor

I don't have to dig deeper (yet), but replacing this with my last build (that I tested #1841 with) gave me the following error:

Invalid client type

Happened with both S3 and S3Client objects from @aws-sdk/client-s3. My last build was on 3.0.1, though.

@monken
Copy link
Author

monken commented Jan 25, 2021

@samsullivan yeah make sure you update everything to 3.3.0. I had the same issue...

@samsullivan
Copy link
Contributor

samsullivan commented Jan 26, 2021

Ah, should've been able to figure that out on my own. Looks like it's working now. Thanks!

I didn't have any more robust performance testing; however, this seems to be more thought out of a fix than my "bolt it on" approach in #1841 so I'm fine with this one being merged instead. Bummer that v2 SDK still had better performance here, but...the current v3 implementation is unusable.

@monken
Copy link
Author

monken commented Jan 26, 2021

I have prepared another PR that will improve upload speeds further, even beating v2. It's a little more invasive by allowing passing Buffer arrays all the way down to the http-client and signer. I'll submit it if this PR gets merged.

@monken monken changed the title Improve lib/storage performance by reducing expensive buffer concat operations refactor(lib-storage): improve performance by reducing expensive buffer concat operations Jan 26, 2021
@codecov-io
Copy link

Codecov Report

Merging #1955 (5b0abc7) into master (f2a47e8) will increase coverage by 0.54%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1955      +/-   ##
==========================================
+ Coverage   79.30%   79.85%   +0.54%     
==========================================
  Files         368      368              
  Lines       15132    15544     +412     
  Branches     3222     3367     +145     
==========================================
+ Hits        12001    12412     +411     
- Misses       3131     3132       +1     
Impacted Files Coverage Δ
packages/util-waiter/src/utils/validate.ts 81.81% <0.00%> (-18.19%) ⬇️
packages/s3-request-presigner/src/getSignedUrl.ts 92.85% <0.00%> (-2.98%) ⬇️
packages/util-dynamodb/src/convertToAttr.ts 98.70% <0.00%> (-1.30%) ⬇️
packages/util-waiter/src/poller.ts 100.00% <0.00%> (ø)
packages/util-waiter/src/waiter.ts 100.00% <0.00%> (ø)
protocol_tests/aws-ec2/endpoints.ts 81.48% <0.00%> (ø)
protocol_tests/aws-json/endpoints.ts 81.48% <0.00%> (ø)
protocol_tests/aws-query/endpoints.ts 81.48% <0.00%> (ø)
packages/util-dynamodb/src/marshall.ts 100.00% <0.00%> (ø)
protocol_tests/aws-ec2/runtimeConfig.ts 100.00% <0.00%> (ø)
... and 156 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 63ad215...5b0abc7. Read the comment docs.

@AllanZhengYP AllanZhengYP changed the title refactor(lib-storage): improve performance by reducing expensive buffer concat operations feat(lib-storage): improve performance by reducing expensive buffer concat operations Jan 28, 2021
Copy link
Contributor

@AllanZhengYP AllanZhengYP left a comment

Choose a reason for hiding this comment

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

@monken

👍👍 Huge thanks to this optimization and the test case. It looks good to me!

The formating of the code is a little off. The Prettier should've formatted it but for some reason it doesn't seem the case. Can you try format the code?

@monken
Copy link
Author

monken commented Jan 28, 2021

@AllanZhengYP for some reason the pre-commit hook didn't run. Should be fixed now.

@aws-sdk-js-automation
Copy link

AWS CodeBuild CI Report

  • CodeBuild project: sdk-staging-test
  • Commit ID: e685a21
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@alexforsyth
Copy link
Contributor

alexforsyth commented Feb 17, 2021

This PR #2039 to rewrite Upload should incorporate these ideas. @monken please let me know if something is missing there.

@github-actions
Copy link

github-actions bot commented Mar 6, 2021

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 6, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants