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(storage, mdbx): set rp augment limit #5614

Merged
merged 3 commits into from
Nov 29, 2023
Merged

Conversation

shekhirin
Copy link
Collaborator

@shekhirin shekhirin commented Nov 28, 2023

Resolves #5228

Explanation

// This parameter sets the maximum size of the "reclaimed list", and the unit of measurement
// is "pages". Reclaimed list is the list of freed pages that's populated during the
// lifetime of DB transaction, and through which MDBX searches when it needs to insert new
// record with overflow pages. The flow is roughly the following:
// 0. We need to insert a record that requires N number of overflow pages (in consecutive
// sequence inside the DB file).
// 1. Get some pages from the freelist, put them into the reclaimed list.
// 2. Search through the reclaimed list for the sequence of size N.
// 3. a. If found, return the sequence.
// 3. b. If not found, repeat steps 1-3. If the reclaimed list size is larger than
// the `rp augment limit`, stop the search and allocate new pages at the end of the file:
// https://github.com/paradigmxyz/reth/blob/2a4c78759178f66e30c8976ec5d243b53102fc9a/crates/storage/libmdbx-rs/mdbx-sys/libmdbx/mdbx.c#L11479-L11480.
//
// Basically, this parameter controls for how long do we search through the freelist before
// trying to allocate new pages. Smaller value will make MDBX to fallback to
// allocation faster, higher value will force MDBX to search through the freelist
// longer until the sequence of pages is found.
//
// The default value of this parameter is set depending on the DB size. The bigger the
// database, the larger is `rp augment limit`.
// https://github.com/paradigmxyz/reth/blob/2a4c78759178f66e30c8976ec5d243b53102fc9a/crates/storage/libmdbx-rs/mdbx-sys/libmdbx/mdbx.c#L10018-L10024.
//
// Previously, MDBX set this value as `256 * 1024` constant. Let's fallback to this,
// because we want to prioritize freelist lookup speed over database growth.
// https://github.com/paradigmxyz/reth/blob/fa2b9b685ed9787636d962f4366caf34a9186e66/crates/storage/libmdbx-rs/mdbx-sys/libmdbx/mdbx.c#L16017.
inner_env.set_rp_augment_limit(256 * 1024);

Results

Before 12:10 – default rp augment limit value (which is around 137 million)
After 12:25 – custom rp augment limit value set to 256 * 1024

image

Note: disregard the drop of the Freelist chart, it's due to node having a slight downtime during the restart and many blocks being inserted at once.

@shekhirin shekhirin added C-bug An unexpected or incorrect behavior A-db Related to the database labels Nov 28, 2023
@shekhirin shekhirin marked this pull request as ready for review November 28, 2023 13:07
Copy link
Member

@rkrasiuk rkrasiuk left a comment

Choose a reason for hiding this comment

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

omfg

@shekhirin shekhirin added C-perf A change motivated by improving speed, memory usage or disk footprint and removed C-bug An unexpected or incorrect behavior labels Nov 28, 2023
@shekhirin shekhirin changed the title fix(storage, mdbx): set rp augment limit perf(storage, mdbx): set rp augment limit Nov 28, 2023
Copy link
Collaborator

@mattsse mattsse left a comment

Choose a reason for hiding this comment

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

hehe

Copy link
Collaborator

@joshieDo joshieDo left a comment

Choose a reason for hiding this comment

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

send it

Copy link
Member

@gakonst gakonst left a comment

Choose a reason for hiding this comment

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

1 loc change, 25 comments, 1 month of effort, gg

this does mean the db will grow faster on heavy freelist-related scenarios?

@shekhirin
Copy link
Collaborator Author

this does mean the db will grow faster on heavy freelist-related scenarios?

Yes, but this effect should be small, because only large insertions will lead to new allocations.

@shekhirin shekhirin added this pull request to the merge queue Nov 29, 2023
Merged via the queue into main with commit 07265d9 Nov 29, 2023
27 checks passed
@shekhirin shekhirin deleted the alexey/bump-augment-limit branch November 29, 2023 08:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-db Related to the database C-perf A change motivated by improving speed, memory usage or disk footprint
Projects
None yet
Development

Successfully merging this pull request may close these issues.

MDBX Freelist Issues
5 participants