remote-ext: fix state download stall on slow connections and reduce memory usage - #1295
Merged
Conversation
bkchr
reviewed
Aug 30, 2023
…/remote-ext-target-request-time
…tytech/polkadot-sdk into liam/remote-ext-target-request-time
liamaharon
marked this pull request as draft
September 21, 2023 14:43
…/remote-ext-target-request-time
…tytech/polkadot-sdk into liam/remote-ext-target-request-time
…tytech/polkadot-sdk into liam/remote-ext-target-request-time
liamaharon
marked this pull request as ready for review
September 25, 2023 15:02
Contributor
Author
|
@bkchr thanks for your suggestions. I've refactored the recursive function to be iterative and implemented your suggestions, and the memory usage is orders of magnitude lower now. |
niklasad1
reviewed
Sep 27, 2023
| retries = 0; | ||
| batch_response | ||
| }, | ||
| Err(e) => { |
Contributor
There was a problem hiding this comment.
Ideally you should check the kind of error you get back here...
If it' just Errror::Transport(Transport::RequestTooBig) or Error::RequestTimeout then it shouldn't be a problem to continue but unfortunately it's not a concrete type you would need to downcast which is PITA... https://docs.rs/jsonrpsee-http-client/0.20.1/src/jsonrpsee_http_client/transport.rs.html#212
niklasad1
approved these changes
Sep 27, 2023
bkchr
approved these changes
Sep 29, 2023
…/remote-ext-target-request-time
bkchr
pushed a commit
that referenced
this pull request
Apr 10, 2024
This was referenced Jun 5, 2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Original PR paritytech/substrate#14746
Fixing stall
Introduction
I experienced an apparent stall downloading state from
https://rococo-try-runtime-node.parity-chains.parity.io:443which was having networking difficulties only responding to my JSONRPC requests with 50-200KB/s of bandwidth.This PR fixes the issue causing the stall, and generally improves performance remote-ext when it downloads state by greatly reducing the chances of a timeout occuring.
Description
Introduces a new
REQUEST_DURATION_TARGETconstant and modifiesget_storage_data_dynamic_batch_sizetoThis fixes an issue on slow connections that can otherwise cause multiple timeouts and a stalled download when:
After this PR, the request size will
Reducing memory
As suggested by @bkchr, I adjusted
get_storage_data_dynamic_batch_sizefrom being recursive to a loop which allows removing a bunch of clones that were chewing through a lot of memory. I noticed actually it was using up to 50GB swap previously when downloading Polkadot keys on a slow connection, because it needed to recurse and clone a lot.After this change it uses only ~1.5GB memory.