Set default database file size large enough (#1363)

* make default 100mb file size

* update again

* fix type

* little less extreme file sizes
This commit is contained in:
Nikolay Volf 2016-06-21 14:57:06 +03:00 committed by Gav Wood
parent 951512f9c9
commit c5f6250668
2 changed files with 9 additions and 4 deletions

4
Cargo.lock generated
View File

@ -1103,7 +1103,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]] [[package]]
name = "rocksdb" name = "rocksdb"
version = "0.4.5" version = "0.4.5"
source = "git+https://github.com/ethcore/rust-rocksdb#9140e37ce0fdb748097f85653c01b0f7e3736ea9" source = "git+https://github.com/ethcore/rust-rocksdb#e0e6c099d8cd156fe446009fce241d57b00cd8f4"
dependencies = [ dependencies = [
"libc 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)",
"rocksdb-sys 0.3.0 (git+https://github.com/ethcore/rust-rocksdb)", "rocksdb-sys 0.3.0 (git+https://github.com/ethcore/rust-rocksdb)",
@ -1112,7 +1112,7 @@ dependencies = [
[[package]] [[package]]
name = "rocksdb-sys" name = "rocksdb-sys"
version = "0.3.0" version = "0.3.0"
source = "git+https://github.com/ethcore/rust-rocksdb#9140e37ce0fdb748097f85653c01b0f7e3736ea9" source = "git+https://github.com/ethcore/rust-rocksdb#e0e6c099d8cd156fe446009fce241d57b00cd8f4"
dependencies = [ dependencies = [
"gcc 0.3.28 (registry+https://github.com/rust-lang/crates.io-index)", "gcc 0.3.28 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.12 (registry+https://github.com/rust-lang/crates.io-index)",

View File

@ -20,6 +20,9 @@ use std::default::Default;
use rocksdb::{DB, Writable, WriteBatch, IteratorMode, DBVector, DBIterator, use rocksdb::{DB, Writable, WriteBatch, IteratorMode, DBVector, DBIterator,
IndexType, Options, DBCompactionStyle, BlockBasedOptions, Direction}; IndexType, Options, DBCompactionStyle, BlockBasedOptions, Direction};
const DB_FILE_SIZE_BASE: u64 = 10 * 1024 * 1024;
const DB_FILE_SIZE_MULTIPLIER: i32 = 5;
/// Write transaction. Batches a sequence of put/delete operations for efficiency. /// Write transaction. Batches a sequence of put/delete operations for efficiency.
pub struct DBTransaction { pub struct DBTransaction {
batch: WriteBatch, batch: WriteBatch,
@ -64,7 +67,7 @@ impl DatabaseConfig {
DatabaseConfig { DatabaseConfig {
cache_size: Some(cache_size), cache_size: Some(cache_size),
prefix_size: None, prefix_size: None,
max_open_files: 256 max_open_files: -1,
} }
} }
} }
@ -74,7 +77,7 @@ impl Default for DatabaseConfig {
DatabaseConfig { DatabaseConfig {
cache_size: None, cache_size: None,
prefix_size: None, prefix_size: None,
max_open_files: 256 max_open_files: -1,
} }
} }
} }
@ -110,6 +113,8 @@ impl Database {
opts.create_if_missing(true); opts.create_if_missing(true);
opts.set_use_fsync(false); opts.set_use_fsync(false);
opts.set_compaction_style(DBCompactionStyle::DBUniversalCompaction); opts.set_compaction_style(DBCompactionStyle::DBUniversalCompaction);
opts.set_target_file_size_base(DB_FILE_SIZE_BASE);
opts.set_target_file_size_multiplier(DB_FILE_SIZE_MULTIPLIER);
if let Some(cache_size) = config.cache_size { if let Some(cache_size) = config.cache_size {
// half goes to read cache // half goes to read cache
opts.set_block_cache_size_mb(cache_size as u64 / 2); opts.set_block_cache_size_mb(cache_size as u64 / 2);