mirror of
https://github.com/romanz/electrs.git
synced 2025-02-23 22:56:55 +01:00
Optimize for low-memory systems by using different RocksDB settings
- Keep less open files (to preserve memory) - Don't use compaction readahead - Use smaller SSTable block size
This commit is contained in:
parent
200ef16ed0
commit
3f51458fee
3 changed files with 10 additions and 6 deletions
|
@ -17,7 +17,7 @@ fn run(config: Config) -> Result<()> {
|
|||
config.db_path
|
||||
);
|
||||
}
|
||||
let store = DBStore::open(&config.db_path);
|
||||
let store = DBStore::open(&config.db_path, /*low_memory=*/ true);
|
||||
store.compact();
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@ fn run_server(config: &Config) -> Result<()> {
|
|||
&metrics,
|
||||
)?;
|
||||
// Perform initial indexing from local blk*.dat block files.
|
||||
let store = DBStore::open(&config.db_path);
|
||||
let store = DBStore::open(&config.db_path, /*low_memory=*/ config.jsonrpc_import);
|
||||
let index = Index::load(&store, &daemon, &metrics, config.index_batch_size)?;
|
||||
let store = if config.jsonrpc_import {
|
||||
index.update(&store, &signal)?; // slower: uses JSONRPC for fetching blocks
|
||||
|
|
12
src/store.rs
12
src/store.rs
|
@ -30,6 +30,7 @@ pub trait WriteStore: Sync {
|
|||
struct Options {
|
||||
path: PathBuf,
|
||||
bulk_import: bool,
|
||||
low_memory: bool,
|
||||
}
|
||||
|
||||
pub struct DBStore {
|
||||
|
@ -43,17 +44,19 @@ impl DBStore {
|
|||
let mut db_opts = rocksdb::Options::default();
|
||||
db_opts.create_if_missing(true);
|
||||
// db_opts.set_keep_log_file_num(10);
|
||||
db_opts.set_max_open_files(256);
|
||||
db_opts.set_compaction_readahead_size(1 << 20);
|
||||
db_opts.set_max_open_files(if opts.bulk_import { 16 } else { 256 });
|
||||
db_opts.set_compaction_style(rocksdb::DBCompactionStyle::Level);
|
||||
db_opts.set_compression_type(rocksdb::DBCompressionType::Snappy);
|
||||
db_opts.set_target_file_size_base(256 << 20);
|
||||
db_opts.set_write_buffer_size(256 << 20);
|
||||
db_opts.set_disable_auto_compactions(opts.bulk_import); // for initial bulk load
|
||||
db_opts.set_advise_random_on_open(!opts.bulk_import); // bulk load uses sequential I/O
|
||||
if opts.low_memory == false {
|
||||
db_opts.set_compaction_readahead_size(1 << 20);
|
||||
}
|
||||
|
||||
let mut block_opts = rocksdb::BlockBasedOptions::default();
|
||||
block_opts.set_block_size(1 << 20);
|
||||
block_opts.set_block_size(if opts.low_memory { 256 << 10 } else { 1 << 20 });
|
||||
DBStore {
|
||||
db: rocksdb::DB::open(&db_opts, &opts.path).unwrap(),
|
||||
opts,
|
||||
|
@ -61,10 +64,11 @@ impl DBStore {
|
|||
}
|
||||
|
||||
/// Opens a new RocksDB at the specified location.
|
||||
pub fn open(path: &Path) -> Self {
|
||||
pub fn open(path: &Path, low_memory: bool) -> Self {
|
||||
DBStore::open_opts(Options {
|
||||
path: path.to_path_buf(),
|
||||
bulk_import: true,
|
||||
low_memory,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue