Skip to content

Improve performance for large requests - #1066

Merged
arthurschreiber merged 1 commit into
masterfrom
arthur/request-performance-feat
Mar 7, 2020
Merged

arthurschreiber merged 1 commit into
masterfrom
arthur/request-performance-feat

Conversation

@arthurschreiber

@arthurschreiber arthurschreiber commented Mar 7, 2020 •

Copy link
Copy Markdown
Collaborator

The code that handles the generation of request payloads was rewritten to make use of JavaScript generators to build payload data in a just-in-time fashion, instead of generating the whole payload upfront. This new approach to payload generation greatly reduces memory usage and the number of garbage collection runs, and indirectly also improves performance.

#1037, #1044, #1049 and #1063 contained the actual changes.

To show the improvements, we tracked memory usage while running the benchmarks/query/insert-varbinary.js benchmark with size=104857600 n=10 (100MB of data) using process.memoryUsage(), at an interval of 500ms:

Here is the same data collected with the new payload generation code:

As can be seen pretty clearly, the external memory value (which is tracking Buffer memory usage, amongst other things), was greatly reduced. This is mostly due to the fact that we don't build the whole request payload upfront anymore.

This reduction in memory usage can also lead to performance improvements - e.g. by reducing memory pressure, we also reduce the number of garbage collection runs, which should also improve overall application performance.

These improvements are very much dependent on the size of the request data, requests that send large data to the server should see big improvements, while smaller requests might only see minimal or no improvements at all.

Fixes: #971
Fixes: #475
Fixes: #879

The code that handles the generation of request payloads was rewritten
to make use of JavaScript generators to build payload data in a
just-in-time fashion, instead of generating the whole payload upfront.
This new approach to payload generation greatly reduces memory usage and
the number of garbage collection runs, and indirectly also improves
performance.
@arthurschreiber
arthurschreiber force-pushed the arthur/request-performance-feat branch from 2aff173 to 6b1d2e4 Compare March 7, 2020 20:10
@codecov

codecov Bot commented Mar 7, 2020 •

Copy link
Copy Markdown

Codecov Report

Merging #1066 into master will increase coverage by 0.93%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1066      +/-   ##
==========================================
+ Coverage   79.74%   80.68%   +0.93%     
==========================================
  Files          86       86              
  Lines        4374     4374              
  Branches      789      789              
==========================================
+ Hits         3488     3529      +41     
+ Misses        629      586      -43     
- Partials      257      259       +2     
Impacted Files Coverage Δ
src/connection.ts 63.98% <0.00%> (+3.73%) ⬆️
src/incoming-message-stream.ts 97.43% <0.00%> (+5.12%) ⬆️

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 16b9cc9...6b1d2e4. Read the comment docs.

@arthurschreiber
arthurschreiber marked this pull request as ready for review March 7, 2020 21:58
@arthurschreiber
arthurschreiber merged commit 0952817 into master Mar 7, 2020
@arthurschreiber
arthurschreiber deleted the arthur/request-performance-feat branch March 7, 2020 22:16
@arthurschreiber

Copy link
Copy Markdown
Collaborator Author

🎉 This PR is included in version 8.1.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

2 participants