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

perf: Make ResetBatch accumulate a minimum batch size #729

Merged
merged 5 commits into from
May 10, 2023

Conversation

ValarDragon
Copy link
Contributor

@ValarDragon ValarDragon commented Apr 9, 2023

ResetBatch is an optimization that is used for genesis, for not accumulating huge batches for node writes.

While a performance win, right now it goes to far, with having batch writes of one. Having some minimum size greatly reduces time here.

Here is benchmarks for doing this with a large osmosis import genesis file, where I batched on batch size, for every 512 keys. (In this PR its in 64kb chunks, a little bit annoying for me to test with our osmosis fork due to version differences. I can do it if people really insist, but this feels like a pretty clear speedup, with a sufficiently close test)

Here is pictures of the pprof time diffs (with triggering based on key amount, rather than bytesize as in this PR).
As this is genesis only logic, and it directionally is a significant speedup, I suggest merging it, and leaving to future work to figure out how to tune / configure this batch size.

Before (153 seconds):
image

After (27 seconds -- its only the contribution from SaveBranch thats in the same comparison):
image

This is on top of significant GC pressure being reduced. (I don't have precise numbers for how much of a reduction this change caused, I'd have to re-benchmark)

Note that there is a commit done after this, so theres no concern with a final remnant batch not getting committed: https://github.com/cosmos/iavl/blob/master/mutable_tree.go#L712-L728

@ValarDragon ValarDragon requested a review from a team as a code owner April 9, 2023 20:58
nodedb.go Outdated
Comment on lines 330 to 331
// just don't do an optimization here. keep letting batch size increase.
return nil
Copy link
Contributor

Choose a reason for hiding this comment

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

If GetByteSize fails you fall back to disabling batching. Would it be safer to fall back to the old behaviour, batch size of 1?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I feel like disabling batching is fine, but happy to change to a batch size of 1 (really would just like this PR to get in)

Right now, the only way this function errors in cosmos-DB is if the batch is nil.

Copy link
Member

Choose a reason for hiding this comment

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

lets fallback to old behaviour, then we can merge this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

@ValarDragon ValarDragon enabled auto-merge (squash) May 10, 2023 16:34
@ValarDragon ValarDragon merged commit 747bc12 into cosmos:master May 10, 2023
@tac0turtle tac0turtle deleted the dev/resetbatch_size branch May 10, 2023 16:51
@tac0turtle
Copy link
Member

@Mergifyio backport release/v0.20.x

@mergify
Copy link
Contributor

mergify bot commented May 10, 2023

backport release/v0.20.x

✅ Backports have been created

mergify bot pushed a commit that referenced this pull request May 10, 2023
Co-authored-by: Marko <marbar3778@yahoo.com>
(cherry picked from commit 747bc12)

# Conflicts:
#	CHANGELOG.md
@tac0turtle
Copy link
Member

@Mergifyio backport release/v0.21.x

@mergify
Copy link
Contributor

mergify bot commented May 30, 2023

backport release/v0.21.x

✅ Backports have been created

mergify bot pushed a commit that referenced this pull request May 30, 2023
Co-authored-by: Marko <marbar3778@yahoo.com>
(cherry picked from commit 747bc12)

# Conflicts:
#	CHANGELOG.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants