configurable 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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user