This repository has been archived by the owner on Nov 6, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Couple of rocksdb optimizations #1614
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,8 +17,8 @@ | |
//! Key-Value store abstraction with `RocksDB` backend. | ||
|
||
use std::default::Default; | ||
use rocksdb::{DB, Writable, WriteBatch, IteratorMode, DBVector, DBIterator, | ||
IndexType, Options, DBCompactionStyle, BlockBasedOptions, Direction}; | ||
use rocksdb::{DB, Writable, WriteBatch, WriteOptions, IteratorMode, DBVector, DBIterator, | ||
IndexType, Options, DBCompactionStyle, BlockBasedOptions, Direction, Cache}; | ||
|
||
const DB_BACKGROUND_FLUSHES: i32 = 2; | ||
const DB_BACKGROUND_COMPACTIONS: i32 = 2; | ||
|
@@ -144,6 +144,7 @@ impl<'a> Iterator for DatabaseIterator { | |
/// Key-Value database. | ||
pub struct Database { | ||
db: DB, | ||
write_opts: WriteOptions, | ||
} | ||
|
||
impl Database { | ||
|
@@ -169,36 +170,28 @@ impl Database { | |
|
||
opts.set_max_background_flushes(DB_BACKGROUND_FLUSHES); | ||
opts.set_max_background_compactions(DB_BACKGROUND_COMPACTIONS); | ||
if let Some(cache_size) = config.cache_size { | ||
// half goes to read cache | ||
opts.set_block_cache_size_mb(cache_size as u64 / 2); | ||
// quarter goes to each of the two write buffers | ||
opts.set_write_buffer_size(cache_size * 1024 * 256); | ||
} | ||
/* | ||
opts.set_bytes_per_sync(8388608); | ||
opts.set_disable_data_sync(false); | ||
opts.set_block_cache_size_mb(1024); | ||
opts.set_table_cache_num_shard_bits(6); | ||
opts.set_max_write_buffer_number(32); | ||
opts.set_write_buffer_size(536870912); | ||
opts.set_target_file_size_base(1073741824); | ||
opts.set_min_write_buffer_number_to_merge(4); | ||
opts.set_level_zero_stop_writes_trigger(2000); | ||
opts.set_level_zero_slowdown_writes_trigger(0); | ||
opts.set_compaction_style(DBUniversalCompaction); | ||
opts.set_max_background_compactions(4); | ||
opts.set_max_background_flushes(4); | ||
opts.set_filter_deletes(false); | ||
opts.set_disable_auto_compactions(false); | ||
*/ | ||
|
||
if let Some(size) = config.prefix_size { | ||
let mut block_opts = BlockBasedOptions::new(); | ||
block_opts.set_index_type(IndexType::HashSearch); | ||
opts.set_block_based_table_factory(&block_opts); | ||
opts.set_prefix_extractor_fixed_size(size); | ||
if let Some(cache_size) = config.cache_size { | ||
block_opts.set_cache(Cache::new(cache_size * 1024 * 256)); | ||
opts.set_write_buffer_size(cache_size * 1024 * 256); | ||
} | ||
} else if let Some(cache_size) = config.cache_size { | ||
let mut block_opts = BlockBasedOptions::new(); | ||
// half goes to read cache | ||
block_opts.set_cache(Cache::new(cache_size * 1024 * 256)); | ||
opts.set_block_based_table_factory(&block_opts); | ||
// quarter goes to each of the two write buffers | ||
opts.set_write_buffer_size(cache_size * 1024 * 256); | ||
} | ||
|
||
let mut write_opts = WriteOptions::new(); | ||
write_opts.disable_wal(true); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this should put less i/o stress on compaction |
||
|
||
let db = match DB::open(&opts, path) { | ||
Ok(db) => db, | ||
Err(ref s) if s.starts_with("Corruption:") => { | ||
|
@@ -209,7 +202,7 @@ impl Database { | |
}, | ||
Err(s) => { return Err(s); } | ||
}; | ||
Ok(Database { db: db }) | ||
Ok(Database { db: db, write_opts: write_opts, }) | ||
} | ||
|
||
/// Insert a key-value pair in the transaction. Any existing value value will be overwritten. | ||
|
@@ -224,7 +217,7 @@ impl Database { | |
|
||
/// Commit transaction to database. | ||
pub fn write(&self, tr: DBTransaction) -> Result<(), String> { | ||
self.db.write(tr.batch) | ||
self.db.write_opt(tr.batch, &self.write_opts) | ||
} | ||
|
||
/// Get value by key. | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this causes inadequate ram consumption