Skip to content

[benchmarking-cli] Add --keys-limit=Option<usize> and --random-seed=Option<u64>#10884

Merged
bkchr merged 12 commits intoparitytech:masterfrom
moonbeam-foundation:artur/bench-keys-limit
Feb 25, 2026
Merged

[benchmarking-cli] Add --keys-limit=Option<usize> and --random-seed=Option<u64>#10884
bkchr merged 12 commits intoparitytech:masterfrom
moonbeam-foundation:artur/bench-keys-limit

Conversation

@arturgontijo
Copy link
Copy Markdown
Contributor

Description

This PR adds two optional new params to the benchmark cli subcommand:

1 - --keys-limit=N: Limits the number of keys processed during read and write benchmarks.
2 - --random-seed=M: Provides deterministic randomness for benchmark reproducibility by seeding the random number generator used for key shuffling.

The motivation here is that dealing with huge storage (multiple terabytes) the benchmark workflow could easily eat all the target machine resources, making it impossible (or very expensive) to complete.

let first_key = self
.params
.random_seed
.map(|seed| sp_storage::StorageKey(blake2_256(&seed.to_be_bytes()[..]).to_vec()));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If there are not keys_limit keys behind first_key this will "break". We should instead just load all the keys and then do sample_iter.

This can then directly replace the shuffle call below.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

sample_iter seems to create new values (IIUC). What if we use choose_multiple here?

		let mut keys: Vec<_> = client.storage_keys(hash, None, None)?.collect();
		let (mut rng, _) = new_rng(self.params.random_seed);
		keys = keys.choose_multiple(&mut rng, self.params.keys_limit.unwrap_or(keys.len())).cloned().collect();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yeah you can also use choose_multiple.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks @bkchr, after discussing with the team loading all keys is exactly what breaks (OOM) the workflow for our huge storage chains.
But we get your first_key concern...let me try a different approach here and will ping you back.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@bkchr just pushed a new approach to get more keys when it is necessary.
LMK what do you think about it.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@arturgontijo I'm fine with the approach, but can we get this into some shared function? :D

It can probably take two lambdas to abstract the different ways to read the entries.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Add a shared function in 6ed88c4
I tried to simplify it even more but the complexity (mostly trait bounds) was getting too high.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Hey @bkchr if you have time, could you please take another look at this one? Thanks

@bkchr bkchr requested a review from ggwpez February 6, 2026 09:41
@bkchr bkchr added the T1-FRAME This PR/Issue is related to core FRAME, the framework. label Feb 6, 2026
@bkchr
Copy link
Copy Markdown
Member

bkchr commented Feb 6, 2026

@arturgontijo please merge master.

@bkchr bkchr enabled auto-merge February 6, 2026 09:53
…r/bench-keys-limit

# Conflicts:
#	substrate/utils/frame/benchmarking-cli/src/storage/read.rs
#	substrate/utils/frame/benchmarking-cli/src/storage/write.rs
Copy link
Copy Markdown
Member

@ggwpez ggwpez Feb 6, 2026

Choose a reason for hiding this comment

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

You probably dont have OOM issues for child tree, only main trie, or?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah, we don't get OOM for child keys as our chain does not use child tree.
But, for completeness, I'll implement the same logic for them too.

Copy link
Copy Markdown
Member

@ggwpez ggwpez left a comment

Choose a reason for hiding this comment

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

Thanks, just comments :)

auto-merge was automatically disabled February 10, 2026 14:59

Head branch was pushed to by a user without write access

@arturgontijo
Copy link
Copy Markdown
Contributor Author

Hey @bkchr and @ggwpez could you please review this again?
I added the same logic to child storage keys.
I tested it by mocking a local storage and it worked but I definitely need more eyes on this change.

@bkchr
Copy link
Copy Markdown
Member

bkchr commented Feb 25, 2026

@arturgontijo sorry, I have not seen your ping. Could you please add a prdoc to fix CI? Then we can merge it.

@arturgontijo
Copy link
Copy Markdown
Contributor Author

@bkchr done...not sure how to fix the failing checks though =/

@bkchr bkchr added this pull request to the merge queue Feb 25, 2026
Merged via the queue into paritytech:master with commit 5e8782a Feb 25, 2026
243 of 247 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

T1-FRAME This PR/Issue is related to core FRAME, the framework.

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

5 participants