Skip to content

Commit 6eb1513

Browse files
Configurable diff buffer cache size (sigp#4420)
1 parent d56cec8 commit 6eb1513

File tree

4 files changed

+20
-6
lines changed

4 files changed

+20
-6
lines changed

beacon_node/src/cli.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,14 @@ pub fn cli_app<'a, 'b>() -> App<'a, 'b> {
665665
.help("Specifies how many states the database should cache in memory [default: 128]")
666666
.takes_value(true)
667667
)
668+
.arg(
669+
Arg::with_name("diff-buffer-cache-size")
670+
.long("diff-buffer-cache-size")
671+
.value_name("SIZE")
672+
.help("The maximum number of diff buffers to hold in memory. This cache is used \
673+
when fetching historic states [default: 16]")
674+
.takes_value(true)
675+
)
668676
.arg(
669677
Arg::with_name("compression-level")
670678
.long("compression-level")

beacon_node/src/config.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,11 @@ pub fn get_config<E: EthSpec>(
390390
if let Some(state_cache_size) = clap_utils::parse_optional(cli_args, "state-cache-size")? {
391391
client_config.store.state_cache_size = state_cache_size;
392392
}
393+
if let Some(diff_buffer_cache_size) =
394+
clap_utils::parse_optional(cli_args, "diff-buffer-cache-size")?
395+
{
396+
client_config.store.diff_buffer_cache_size = diff_buffer_cache_size;
397+
}
393398
if let Some(compression_level) = clap_utils::parse_optional(cli_args, "compression-level")? {
394399
client_config.store.compression_level = compression_level;
395400
}

beacon_node/store/src/config.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ pub const DEFAULT_EPOCHS_PER_STATE_DIFF: u64 = 4;
1010
pub const DEFAULT_BLOCK_CACHE_SIZE: usize = 64;
1111
pub const DEFAULT_STATE_CACHE_SIZE: usize = 128;
1212
pub const DEFAULT_COMPRESSION_LEVEL: i32 = 1;
13+
pub const DEFAULT_DIFF_BUFFER_CACHE_SIZE: usize = 16;
1314
const EST_COMPRESSION_FACTOR: usize = 2;
1415
pub const DEFAULT_HISTORIC_STATE_CACHE_SIZE: usize = 1;
1516

@@ -22,8 +23,10 @@ pub struct StoreConfig {
2223
pub block_cache_size: usize,
2324
/// Maximum number of states to store in the in-memory state cache.
2425
pub state_cache_size: usize,
25-
/// Compression level for `BeaconStateDiff`s.
26+
/// Compression level for blocks, state diffs and other compressed values.
2627
pub compression_level: i32,
28+
/// Maximum number of `HDiffBuffer`s to store in memory.
29+
pub diff_buffer_cache_size: usize,
2730
/// Maximum number of states from freezer database to store in the in-memory state cache.
2831
pub historic_state_cache_size: usize,
2932
/// Whether to compact the database on initialization.
@@ -60,6 +63,7 @@ impl Default for StoreConfig {
6063
epochs_per_state_diff: DEFAULT_EPOCHS_PER_STATE_DIFF,
6164
block_cache_size: DEFAULT_BLOCK_CACHE_SIZE,
6265
state_cache_size: DEFAULT_STATE_CACHE_SIZE,
66+
diff_buffer_cache_size: DEFAULT_DIFF_BUFFER_CACHE_SIZE,
6367
compression_level: DEFAULT_COMPRESSION_LEVEL,
6468
historic_state_cache_size: DEFAULT_HISTORIC_STATE_CACHE_SIZE,
6569
compact_on_init: false,

beacon_node/store/src/hot_cold_store.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,6 @@ use types::EthSpec;
4444
use types::*;
4545
use zstd::{Decoder, Encoder};
4646

47-
// FIXME(sproul): configurable
48-
const DIFF_BUFFER_CACHE_SIZE: usize = 16;
49-
5047
pub const MAX_PARENT_STATES_TO_CACHE: u64 = 1;
5148

5249
/// On-disk database that stores finalized states efficiently.
@@ -155,7 +152,7 @@ impl<E: EthSpec> HotColdDB<E, MemoryStore<E>, MemoryStore<E>> {
155152
let historic_state_cache_size =
156153
NonZeroUsize::new(config.historic_state_cache_size).ok_or(Error::ZeroCacheSize)?;
157154
let diff_buffer_cache_size =
158-
NonZeroUsize::new(DIFF_BUFFER_CACHE_SIZE).ok_or(Error::ZeroCacheSize)?;
155+
NonZeroUsize::new(config.diff_buffer_cache_size).ok_or(Error::ZeroCacheSize)?;
159156

160157
let db = HotColdDB {
161158
split: RwLock::new(Split::default()),
@@ -202,7 +199,7 @@ impl<E: EthSpec> HotColdDB<E, LevelDB<E>, LevelDB<E>> {
202199
let historic_state_cache_size =
203200
NonZeroUsize::new(config.historic_state_cache_size).ok_or(Error::ZeroCacheSize)?;
204201
let diff_buffer_cache_size =
205-
NonZeroUsize::new(DIFF_BUFFER_CACHE_SIZE).ok_or(Error::ZeroCacheSize)?;
202+
NonZeroUsize::new(config.diff_buffer_cache_size).ok_or(Error::ZeroCacheSize)?;
206203

207204
let db = HotColdDB {
208205
split: RwLock::new(Split::default()),

0 commit comments

Comments
 (0)