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

Performance fixes #207

Merged
merged 2 commits into from
Nov 30, 2023
Merged

Performance fixes #207

merged 2 commits into from
Nov 30, 2023

Conversation

kravets-levko
Copy link
Contributor

@kravets-levko kravets-levko commented Nov 29, 2023

This PR is related to #204. After changes made in that PR, downloading CloudFetch results sometimes started to fail with ECONNRESET: socket hang up error. After debugging, I've found a root cause. Even though all the library code is Promise-based, since Promises are microtasks, enqueueing a lot of promises may block macrotasks execution for a while. Usually, there are no much microtasks scheduled. However, when fetching a CloudFetch results, after first set of files are downloaded and being processed immediately one by one (and chunk by chunk), event loop easily gets clogged for enough time to break connection pool. http.Agent stops receiving socket events, and marks all sockets invalid on the next attempt to use them. The fix allows to clean up a microtasks queue and allow Node to process macrotasks as well, allowing the normal operation of other code.

This change has almost no effect prior to #204 changes, but after #204 the difference is really noticeable (see screenshots under the spoilers). Memory consumption and sockets usage remains basically the same, but event loop now is executed much more evenly, without long delays (which is also reflected on CPU graph):

Before

image

After

image

Also, another (smaller) improvement is increasing connection pool when CloudFetch is enabled, which allows to download data a bit faster.

Signed-off-by: Levko Kravets <levko.ne@gmail.com>
Signed-off-by: Levko Kravets <levko.ne@gmail.com>
Copy link
Contributor

@nithinkdb nithinkdb left a comment

Choose a reason for hiding this comment

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

LGTM

@nithinkdb nithinkdb merged commit 69d88b8 into main Nov 30, 2023
5 checks passed
@kravets-levko kravets-levko deleted the performance-fixes branch November 30, 2023 20:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants