Skip to content

Commit

Permalink
Make the tx cache size configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
RCasatta committed Sep 19, 2024
1 parent 7dee400 commit 1a680b0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ pub struct Config {
pub electrum_banner: String,
pub electrum_rpc_logging: Option<RpcLogging>,

/// Tx cache size in megabytes
pub tx_cache_size: usize,

#[cfg(feature = "liquid")]
pub parent_network: BNetwork,
#[cfg(feature = "liquid")]
Expand Down Expand Up @@ -191,6 +194,11 @@ impl Config {
.long("electrum-rpc-logging")
.help(&rpc_logging_help)
.takes_value(true),
).arg(
Arg::with_name("tx_cache_size")
.long("tx-cache-size")
.help("The amount of MB for a in-memory cache for transactions.")
.default_value("1000")
);

#[cfg(unix)]
Expand Down Expand Up @@ -403,6 +411,7 @@ impl Config {
index_unspendables: m.is_present("index_unspendables"),
cors: m.value_of("cors").map(|s| s.to_string()),
precache_scripts: m.value_of("precache_scripts").map(|s| s.to_string()),
tx_cache_size: value_t_or_exit!(m, "tx_cache_size", usize),

#[cfg(feature = "liquid")]
parent_network,
Expand Down
2 changes: 1 addition & 1 deletion src/new_index/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ impl ChainQuery {
HistogramOpts::new("query_duration", "Index query duration (in seconds)"),
&["name"],
),
txs_cache: Mutex::new(SliceCache::new(1_000_000_000)),
txs_cache: Mutex::new(SliceCache::new(config.tx_cache_size << 20)),
cache_hit: metrics.counter(MetricOpts::new("tx_cache_hit", "Tx cache Hit")),
cache_miss: metrics.counter(MetricOpts::new("tx_cache_miss", "Tx cache Miss")),
}
Expand Down

0 comments on commit 1a680b0

Please sign in to comment.