From 74e78225dc43c77598a96f56e924a8ec8a624610 Mon Sep 17 00:00:00 2001 From: hanabi1224 Date: Mon, 8 Jun 2026 22:45:17 +0800 Subject: [PATCH] chore: adjust cache sizes for better RPC performance --- docs/docs/users/reference/env_variables.md | 4 ++-- src/chain/store/chain_store.rs | 2 +- src/db/car/mod.rs | 4 ++-- src/state_manager/mod.rs | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/docs/docs/users/reference/env_variables.md b/docs/docs/users/reference/env_variables.md index a6e327c20bd..37ef2241f72 100644 --- a/docs/docs/users/reference/env_variables.md +++ b/docs/docs/users/reference/env_variables.md @@ -48,13 +48,13 @@ process. | `FOREST_DRAND_INCENTINET_CONFIG` | string | empty | refer to Drand config format section | Override `DRAND_INCENTINET` config | | `FOREST_TRACE_FILTER_MAX_RESULT` | positive integer | 500 | 1000 | Sets the maximum results returned per request by `trace_filter` | | `FOREST_CHAIN_INDEXER_ENABLED` | 1 or true | false | 1 | Whether or not to index the chain to support the Ethereum RPC API | -| `FOREST_MESSAGES_IN_TIPSET_CACHE_SIZE` | positive integer | 100 | 42 | The size of an internal cache of tipsets to messages | +| `FOREST_MESSAGES_IN_TIPSET_CACHE_SIZE` | positive integer | 8192 | 42 | The size of an internal cache of tipsets to messages | | `FOREST_STATE_MIGRATION_DB_WRITE_BUFFER` | non-negative integer | 10000 | 100000 | The size of db write buffer for state migration (`~10MB` RAM per `10k` buffer) | | `FOREST_SNAPSHOT_GC_INTERVAL_EPOCHS` | non-negative integer | 20160 | 8000 | The interval in epochs for scheduling snapshot GC | | `FOREST_SNAPSHOT_GC_CHECK_INTERVAL_SECONDS` | non-negative integer | 300 | 60 | The interval in seconds for checking if snapshot GC should run | | `FOREST_SNAPSHOT_GC_KEEP_STATE_TREE_EPOCHS` | non-negative integer | 2000 | 20160 | The number of most recent epochs of state trees to keep after GC | | `FOREST_DISABLE_BAD_BLOCK_CACHE` | 1 or true | empty | 1 | Whether or not to disable bad block cache | -| `FOREST_ZSTD_FRAME_CACHE_DEFAULT_MAX_SIZE` | positive integer | 268435456 | 536870912 | The default zstd frame cache max size in bytes | +| `FOREST_ZSTD_FRAME_CACHE_DEFAULT_MAX_SIZE` | positive integer | 536870912 | 536870912 | The default zstd frame cache max size in bytes | | `FOREST_JWT_DISABLE_EXP_VALIDATION` | 1 or true | empty | 1 | Whether or not to disable JWT expiration validation | | `FOREST_ETH_BLOCK_CACHE_SIZE` | positive integer | 500 | 1 | The size of Eth block cache | | `FOREST_RPC_BACKFILL_FULL_TIPSET_FROM_NETWORK` | 1 or true | false | 1 | Whether or not to backfill full tipsets from the p2p network | diff --git a/src/chain/store/chain_store.rs b/src/chain/store/chain_store.rs index 6323e39b0a4..4d7df72dc81 100644 --- a/src/chain/store/chain_store.rs +++ b/src/chain/store/chain_store.rs @@ -638,7 +638,7 @@ impl MessagesInTipsetCache { /// Reads the intended cache size for this process from the environment or uses the default. fn read_cache_size() -> NonZeroUsize { // Arbitrary number, can be adjusted - const DEFAULT: NonZeroUsize = nonzero!(1024usize); + const DEFAULT: NonZeroUsize = nonzero!(8192usize); // maximum ~40MiB on mainnet std::env::var("FOREST_MESSAGES_IN_TIPSET_CACHE_SIZE") .ok() .and_then(|s| s.parse().ok()) diff --git a/src/db/car/mod.rs b/src/db/car/mod.rs index 940a394113b..c68b8d6d874 100644 --- a/src/db/car/mod.rs +++ b/src/db/car/mod.rs @@ -44,8 +44,8 @@ pub static ZSTD_FRAME_CACHE_DEFAULT_MAX_SIZE: LazyLock = LazyLock::new(|| ); } } - // 256 MiB - 256 * 1024 * 1024 + // 512 MiB + 512 * 1024 * 1024 }); /// One decompressed zstd frame's index, shared via [`Arc`] so cache lookups diff --git a/src/state_manager/mod.rs b/src/state_manager/mod.rs index e1169b00631..e2629494699 100644 --- a/src/state_manager/mod.rs +++ b/src/state_manager/mod.rs @@ -59,8 +59,8 @@ use serde::{Deserialize, Serialize}; use std::num::NonZeroUsize; use tracing::warn; -const DEFAULT_TIPSET_CACHE_SIZE: NonZeroUsize = nonzero!(1024usize); -const DEFAULT_ID_TO_DETERMINISTIC_ADDRESS_CACHE_SIZE: NonZeroUsize = nonzero!(1024usize); +const DEFAULT_TIPSET_CACHE_SIZE: NonZeroUsize = nonzero!(8192usize); // maximum ~150MiB on mainnet +const DEFAULT_ID_TO_DETERMINISTIC_ADDRESS_CACHE_SIZE: NonZeroUsize = nonzero!(8192usize); // maximum ~0.7MiB on mainnet const DEFAULT_TRACE_CACHE_SIZE: NonZeroUsize = nonzero!(16usize); // maximum ~70MiB on mainnet pub const EVENTS_AMT_BITWIDTH: u32 = 5; pub type IdToAddressCache = SizeTrackingCache;