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

Parallel key scraping #16

Closed
liamaharon opened this issue Aug 14, 2023 · 1 comment
Closed

Parallel key scraping #16

liamaharon opened this issue Aug 14, 2023 · 1 comment

Comments

@liamaharon
Copy link
Contributor

Original issue paritytech/polkadot-sdk#174


Motivation

The current key scraping implementation is is quite inefficient, fetching 1k keys at a time, waiting for each batch of 1k keys to be returned before asking for the next one

https://github.com/paritytech/substrate/blob/master/utils/frame/remote-externalities/src/lib.rs#L348-L392

This is not so bad when fetching keys from a local node where latency is not a big factor, but can slow things down very significantly when using a remote node when most of the time spend fetching keys becomes latency rather than the node doing work.

Unfortunately, most nodes seem to have a hard limit imposed preventing more than 1k keys being fetched in a single request.

Suggested solution

Rather than fetching all keys for the prefix in a single rpc_get_keys_paged request here https://github.com/paritytech/substrate/blob/master/utils/frame/remote-externalities/src/lib.rs#L528-L533, split the prefix up into N parts and run the rpc_get_keys_paged tasks in parallel using async/await.

e.g. two parallel tasks:
start_keys: 0x000000 end_keys: 0x777777
start_keys: 0x777777 end_keys: 0xffffff

Bonus (probably for a seperate issue/PR once this one is closed)

Fetch storage values for keys as they're pulled from the node, instead of waiting for all keys to be pulled before fetching values.

@liamaharon liamaharon added enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed labels Aug 14, 2023
@liamaharon liamaharon removed enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed labels Aug 17, 2023
@liamaharon
Copy link
Contributor Author

actually going to leave this in substrate as a remote-externalities issue.

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

No branches or pull requests

1 participant