Skip to content

Commit

Permalink
Configurable diff buffer cache size (sigp#4420)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelsproul authored Jun 20, 2023
1 parent d56cec8 commit 6eb1513
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
8 changes: 8 additions & 0 deletions beacon_node/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,14 @@ pub fn cli_app<'a, 'b>() -> App<'a, 'b> {
.help("Specifies how many states the database should cache in memory [default: 128]")
.takes_value(true)
)
.arg(
Arg::with_name("diff-buffer-cache-size")
.long("diff-buffer-cache-size")
.value_name("SIZE")
.help("The maximum number of diff buffers to hold in memory. This cache is used \
when fetching historic states [default: 16]")
.takes_value(true)
)
.arg(
Arg::with_name("compression-level")
.long("compression-level")
Expand Down
5 changes: 5 additions & 0 deletions beacon_node/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,11 @@ pub fn get_config<E: EthSpec>(
if let Some(state_cache_size) = clap_utils::parse_optional(cli_args, "state-cache-size")? {
client_config.store.state_cache_size = state_cache_size;
}
if let Some(diff_buffer_cache_size) =
clap_utils::parse_optional(cli_args, "diff-buffer-cache-size")?
{
client_config.store.diff_buffer_cache_size = diff_buffer_cache_size;
}
if let Some(compression_level) = clap_utils::parse_optional(cli_args, "compression-level")? {
client_config.store.compression_level = compression_level;
}
Expand Down
6 changes: 5 additions & 1 deletion beacon_node/store/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub const DEFAULT_EPOCHS_PER_STATE_DIFF: u64 = 4;
pub const DEFAULT_BLOCK_CACHE_SIZE: usize = 64;
pub const DEFAULT_STATE_CACHE_SIZE: usize = 128;
pub const DEFAULT_COMPRESSION_LEVEL: i32 = 1;
pub const DEFAULT_DIFF_BUFFER_CACHE_SIZE: usize = 16;
const EST_COMPRESSION_FACTOR: usize = 2;
pub const DEFAULT_HISTORIC_STATE_CACHE_SIZE: usize = 1;

Expand All @@ -22,8 +23,10 @@ pub struct StoreConfig {
pub block_cache_size: usize,
/// Maximum number of states to store in the in-memory state cache.
pub state_cache_size: usize,
/// Compression level for `BeaconStateDiff`s.
/// Compression level for blocks, state diffs and other compressed values.
pub compression_level: i32,
/// Maximum number of `HDiffBuffer`s to store in memory.
pub diff_buffer_cache_size: usize,
/// Maximum number of states from freezer database to store in the in-memory state cache.
pub historic_state_cache_size: usize,
/// Whether to compact the database on initialization.
Expand Down Expand Up @@ -60,6 +63,7 @@ impl Default for StoreConfig {
epochs_per_state_diff: DEFAULT_EPOCHS_PER_STATE_DIFF,
block_cache_size: DEFAULT_BLOCK_CACHE_SIZE,
state_cache_size: DEFAULT_STATE_CACHE_SIZE,
diff_buffer_cache_size: DEFAULT_DIFF_BUFFER_CACHE_SIZE,
compression_level: DEFAULT_COMPRESSION_LEVEL,
historic_state_cache_size: DEFAULT_HISTORIC_STATE_CACHE_SIZE,
compact_on_init: false,
Expand Down
7 changes: 2 additions & 5 deletions beacon_node/store/src/hot_cold_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,6 @@ use types::EthSpec;
use types::*;
use zstd::{Decoder, Encoder};

// FIXME(sproul): configurable
const DIFF_BUFFER_CACHE_SIZE: usize = 16;

pub const MAX_PARENT_STATES_TO_CACHE: u64 = 1;

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

let db = HotColdDB {
split: RwLock::new(Split::default()),
Expand Down Expand Up @@ -202,7 +199,7 @@ impl<E: EthSpec> HotColdDB<E, LevelDB<E>, LevelDB<E>> {
let historic_state_cache_size =
NonZeroUsize::new(config.historic_state_cache_size).ok_or(Error::ZeroCacheSize)?;
let diff_buffer_cache_size =
NonZeroUsize::new(DIFF_BUFFER_CACHE_SIZE).ok_or(Error::ZeroCacheSize)?;
NonZeroUsize::new(config.diff_buffer_cache_size).ok_or(Error::ZeroCacheSize)?;

let db = HotColdDB {
split: RwLock::new(Split::default()),
Expand Down

0 comments on commit 6eb1513

Please sign in to comment.