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

Optimize RocksDB DB open options #3316

Merged
merged 1 commit into from
Feb 13, 2025
Merged

Conversation

ndr-ds
Copy link
Contributor

@ndr-ds ndr-ds commented Feb 12, 2025

Motivation

RocksDB is implemented as an SST. So it has some in memory buffer, that gets flushed to disk when certain criteria is met.
What was happening was that we weren't flushing data to disk frequently enough, and the implementation we're using to get an iterator in find_keys_by_prefix flushes some tombstones to disk, if necessary. And since we weren't flushing data to disk frequently enough, it often was.
This was causing an increase in those reads of a few tens of ms, which when trying to make the client achieve high TPS makes a big difference.

Proposal

Reduce the size of the write buffer in general, so that we flush to disk more often. This overall seems to improve performance.
Based on this https://github.com/facebook/rocksdb/wiki/RocksDB-Tuning-Guide#flushing-options
We had at most 2 write buffers before of 64 mb each, which is the default settings. Now we have at most 16 write buffers with 8 mb each. Memory usage should stay the same, but disk flushing will be more frequent.
I also changed the compression type to Lz4, which should be slightly faster than the default, Snappy.

Test Plan

Ran benchmark locally, time it takes to reach a certain BPS isn't increasing with time anymore. Ran it for almost 4 hours, it stays within the same range of 400-700ms

Release Plan

  • Nothing to do / These changes follow the usual release cycle.

@@ -47,6 +47,9 @@ const MAX_VALUE_SIZE: usize = 3221225072;
// 8388608 and so for offset reason we decrease by 400
const MAX_KEY_SIZE: usize = 8388208;

const DB_CACHE_SIZE: usize = 8 * 1024 * 1024; // 8 mb
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
const DB_CACHE_SIZE: usize = 8 * 1024 * 1024; // 8 mb
const DB_CACHE_SIZE: usize = 8 * 1024 * 1024; // 8 MiB

@@ -288,6 +291,12 @@ impl RocksDbStoreInternal {
}
let mut options = rocksdb::Options::default();
options.create_if_missing(true);
options.create_missing_column_families(true);
// Flush in memory buffer to disk more often
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// Flush in memory buffer to disk more often
// Flush in-memory buffer to disk more often.

@ndr-ds ndr-ds force-pushed the 02-11-_benchmark_respect_current_epoch_and_committee_on_block_proposal_creation branch from 265f3cb to 8493870 Compare February 13, 2025 17:24
@ndr-ds ndr-ds force-pushed the 02-12-optimize_rocksdb_db_open_options branch from 1cef33d to 4296c29 Compare February 13, 2025 17:24
Copy link
Contributor Author

ndr-ds commented Feb 13, 2025

Merge activity

  • Feb 13, 1:05 PM EST: A user started a stack merge that includes this pull request via Graphite.
  • Feb 13, 1:09 PM EST: Graphite rebased this pull request as part of a merge.
  • Feb 13, 1:11 PM EST: A user merged this pull request with Graphite.

@ndr-ds ndr-ds changed the base branch from 02-11-_benchmark_respect_current_epoch_and_committee_on_block_proposal_creation to graphite-base/3316 February 13, 2025 18:06
@ndr-ds ndr-ds changed the base branch from graphite-base/3316 to main February 13, 2025 18:08
@ndr-ds ndr-ds force-pushed the 02-12-optimize_rocksdb_db_open_options branch from 4296c29 to d1a5062 Compare February 13, 2025 18:09
@ndr-ds ndr-ds merged commit a39a38f into main Feb 13, 2025
24 checks passed
@ndr-ds ndr-ds deleted the 02-12-optimize_rocksdb_db_open_options branch February 13, 2025 18:11
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

Successfully merging this pull request may close these issues.

2 participants