1
0
Fork 0
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:
Roman Zeyde 2018-09-15 21:02:15 +03:00
parent 200ef16ed0
commit 3f51458fee
No known key found for this signature in database
GPG key ID: 87CAE5FA46917CBB
3 changed files with 10 additions and 6 deletions

View file

@ -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(())
}

View file

@ -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

View file

@ -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,
})
}