Skip to content

Commit d5b2fd7

Browse files
feat(hermes): configurable cache size (#2547)
* feat: configurable cache size, bump default to 2000 slots * feat: bump ver * fix: include config/cache.rs in docker build * fix: set default to 1600 slots
1 parent d3d4b5c commit d5b2fd7

File tree

6 files changed

+27
-3
lines changed

6 files changed

+27
-3
lines changed

.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@
1616
.git
1717

1818
!apps/hermes/server/src/state/cache.rs
19+
!apps/hermes/server/src/config/cache.rs

apps/hermes/server/Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/hermes/server/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "hermes"
3-
version = "0.8.4"
3+
version = "0.8.5"
44
description = "Hermes is an agent that provides Verified Prices from the Pythnet Pyth Oracle."
55
edition = "2021"
66

apps/hermes/server/src/config.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use clap::{crate_authors, crate_description, crate_name, crate_version, Args, Pa
22

33
mod aggregate;
44
mod benchmarks;
5+
mod cache;
56
mod metrics;
67
mod pythnet;
78
mod rpc;
@@ -24,6 +25,10 @@ pub enum Options {
2425

2526
#[derive(Args, Clone, Debug)]
2627
pub struct RunOptions {
28+
/// Cache Options
29+
#[command(flatten)]
30+
pub cache: cache::Options,
31+
2732
/// Aggregate Options
2833
#[command(flatten)]
2934
pub aggregate: aggregate::Options,
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
use clap::Args;
2+
3+
#[derive(Args, Clone, Debug)]
4+
#[command(next_help_heading = "Cache Options")]
5+
#[group(id = "Cache")]
6+
pub struct Options {
7+
/// The maximum number of slots to cache.
8+
///
9+
/// This controls how many historical price updates are kept in memory.
10+
/// Higher values increase memory usage but allow access to more historical data
11+
/// without falling back to Benchmarks.
12+
///
13+
/// Default is 1600 slots, which gives 640 seconds of cached updates.
14+
#[arg(long = "cache-size-slots")]
15+
#[arg(env = "CACHE_SIZE_SLOTS")]
16+
#[arg(default_value = "1600")]
17+
pub size_slots: u64,
18+
}

apps/hermes/server/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ async fn init() -> Result<()> {
4444
// Initialize a cache store with a 1000 element circular buffer.
4545
let state = state::new(
4646
update_tx.clone(),
47-
1000,
47+
opts.cache.size_slots,
4848
opts.benchmarks.endpoint.clone(),
4949
opts.aggregate.readiness_staleness_threshold.into(),
5050
opts.aggregate.readiness_max_allowed_slot_lag,

0 commit comments

Comments
 (0)