Merge pull request #1348 from ethcore/db-cache-size
Configurable rocksdb cache size
This commit is contained in:
@@ -253,12 +253,22 @@ impl BlockChain {
|
||||
// open extras db
|
||||
let mut extras_path = path.to_path_buf();
|
||||
extras_path.push("extras");
|
||||
let extras_db = Database::open_default(extras_path.to_str().unwrap()).unwrap();
|
||||
let extras_db = match config.db_cache_size {
|
||||
None => Database::open_default(extras_path.to_str().unwrap()).unwrap(),
|
||||
Some(cache_size) => Database::open(
|
||||
&DatabaseConfig::with_cache(cache_size/2),
|
||||
extras_path.to_str().unwrap()).unwrap(),
|
||||
};
|
||||
|
||||
// open blocks db
|
||||
let mut blocks_path = path.to_path_buf();
|
||||
blocks_path.push("blocks");
|
||||
let blocks_db = Database::open_default(blocks_path.to_str().unwrap()).unwrap();
|
||||
let blocks_db = match config.db_cache_size {
|
||||
None => Database::open_default(blocks_path.to_str().unwrap()).unwrap(),
|
||||
Some(cache_size) => Database::open(
|
||||
&DatabaseConfig::with_cache(cache_size/2),
|
||||
blocks_path.to_str().unwrap()).unwrap(),
|
||||
};
|
||||
|
||||
let mut cache_man = CacheManager{cache_usage: VecDeque::new(), in_use: HashSet::new()};
|
||||
(0..COLLECTION_QUEUE_SIZE).foreach(|_| cache_man.cache_usage.push_back(HashSet::new()));
|
||||
|
||||
@@ -23,6 +23,8 @@ pub struct Config {
|
||||
pub pref_cache_size: usize,
|
||||
/// Maximum cache size in bytes.
|
||||
pub max_cache_size: usize,
|
||||
/// Backing db cache_size
|
||||
pub db_cache_size: Option<usize>,
|
||||
}
|
||||
|
||||
impl Default for Config {
|
||||
@@ -30,6 +32,7 @@ impl Default for Config {
|
||||
Config {
|
||||
pref_cache_size: 1 << 14,
|
||||
max_cache_size: 1 << 20,
|
||||
db_cache_size: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -141,7 +141,10 @@ impl<V> Client<V> where V: Verifier {
|
||||
let chain = Arc::new(BlockChain::new(config.blockchain, &gb, &path));
|
||||
let tracedb = Arc::new(try!(TraceDB::new(config.tracing, &path, chain.clone())));
|
||||
|
||||
let mut state_db = journaldb::new(&append_path(&path, "state"), config.pruning);
|
||||
let mut state_db = journaldb::new(
|
||||
&append_path(&path, "state"),
|
||||
config.pruning,
|
||||
config.db_cache_size);
|
||||
|
||||
if state_db.is_empty() && spec.ensure_db_good(state_db.as_hashdb_mut()) {
|
||||
state_db.commit(0, &spec.genesis_header().hash(), None).expect("Error commiting genesis state to state DB");
|
||||
|
||||
@@ -35,4 +35,6 @@ pub struct ClientConfig {
|
||||
pub pruning: journaldb::Algorithm,
|
||||
/// The name of the client instance.
|
||||
pub name: String,
|
||||
/// State db cache-size if not default
|
||||
pub db_cache_size: Option<usize>,
|
||||
}
|
||||
|
||||
@@ -302,7 +302,7 @@ pub fn generate_dummy_empty_blockchain() -> GuardedTempResult<BlockChain> {
|
||||
|
||||
pub fn get_temp_journal_db() -> GuardedTempResult<Box<JournalDB>> {
|
||||
let temp = RandomTempPath::new();
|
||||
let journal_db = journaldb::new(temp.as_str(), journaldb::Algorithm::EarlyMerge);
|
||||
let journal_db = journaldb::new(temp.as_str(), journaldb::Algorithm::EarlyMerge, None);
|
||||
GuardedTempResult {
|
||||
_temp: temp,
|
||||
result: Some(journal_db)
|
||||
@@ -319,7 +319,7 @@ pub fn get_temp_state() -> GuardedTempResult<State> {
|
||||
}
|
||||
|
||||
pub fn get_temp_journal_db_in(path: &Path) -> Box<JournalDB> {
|
||||
journaldb::new(path.to_str().unwrap(), journaldb::Algorithm::EarlyMerge)
|
||||
journaldb::new(path.to_str().unwrap(), journaldb::Algorithm::EarlyMerge, None)
|
||||
}
|
||||
|
||||
pub fn get_temp_state_in(path: &Path) -> State {
|
||||
|
||||
@@ -48,6 +48,8 @@ pub struct Config {
|
||||
pub enabled: Switch,
|
||||
/// Traces blooms configuration.
|
||||
pub blooms: BloomConfig,
|
||||
/// Database cache-size if not default
|
||||
pub db_cache_size: Option<usize>,
|
||||
}
|
||||
|
||||
impl Default for Config {
|
||||
@@ -57,7 +59,8 @@ impl Default for Config {
|
||||
blooms: BloomConfig {
|
||||
levels: 3,
|
||||
elements_per_index: 16,
|
||||
}
|
||||
},
|
||||
db_cache_size: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ use std::sync::{RwLock, Arc};
|
||||
use std::path::Path;
|
||||
use bloomchain::{Number, Config as BloomConfig};
|
||||
use bloomchain::group::{BloomGroupDatabase, BloomGroupChain, GroupPosition, BloomGroup};
|
||||
use util::{H256, H264, Database, DBTransaction};
|
||||
use util::{H256, H264, Database, DatabaseConfig, DBTransaction};
|
||||
use header::BlockNumber;
|
||||
use trace::{BlockTraces, LocalizedTrace, Config, Switch, Filter, Database as TraceDatabase, ImportRequest,
|
||||
DatabaseExtras, Error};
|
||||
@@ -118,7 +118,12 @@ impl<T> TraceDB<T> where T: DatabaseExtras {
|
||||
pub fn new(config: Config, path: &Path, extras: Arc<T>) -> Result<Self, Error> {
|
||||
let mut tracedb_path = path.to_path_buf();
|
||||
tracedb_path.push("tracedb");
|
||||
let tracesdb = Database::open_default(tracedb_path.to_str().unwrap()).unwrap();
|
||||
let tracesdb = match config.db_cache_size {
|
||||
None => Database::open_default(tracedb_path.to_str().unwrap()).unwrap(),
|
||||
Some(db_cache) => Database::open(
|
||||
&DatabaseConfig::with_cache(db_cache),
|
||||
tracedb_path.to_str().unwrap()).unwrap(),
|
||||
};
|
||||
|
||||
// check if in previously tracing was enabled
|
||||
let old_tracing = match tracesdb.get(b"enabled").unwrap() {
|
||||
|
||||
Reference in New Issue
Block a user