Skip to content

feat(indexer): make RPC response caches disableable - #1582

Open
zizou0x wants to merge 4 commits into
mainfrom
zz/rpc-cache-disable
Open

zizou0x wants to merge 4 commits into
mainfrom
zz/rpc-cache-disable

Conversation

@zizou0x

@zizou0x zizou0x commented Oct 9, 2026

Copy link
Copy Markdown
Collaborator

What

DISABLED_RPC_CACHES (--disabled-rpc-caches) turns off any of the four RpcCache response caches in the RPC handler: contract_storage, protocol_state, protocol_components, traced_entry_points. Comma-separated. An unknown name fails startup with the list of valid names; blank entries are ignored, so DISABLED_RPC_CACHES="" keeps everything on. All caches stay on by default, so nothing changes for existing deployments.

A disabled cache runs the fallback on every call and stores nothing, so no placeholder, no in-flight coalescing, no rpc_cache_* metrics for that cache. The index and rpc commands both honour the flag. Startup logs RPC response caches turned off with the list.

Why

To measure in dev whether the response caches still earn their memory now that the entity cache, the storage token cache and the delta windows exist.

Today they are still the only response caching prod has: ENTITY_CACHE_MODE is shadow on every dev chain and unset in prod, and the component index (#1559) is not merged. Prod hit rates over the last 7 days (VictoriaMetrics, rpc_cache_hits / rpc_cache_misses, prod-tycho + prod-tycho-fynd):

Cache Hits Misses Hit rate Resident (max pod) Replaced by
protocol_components 976k 828k 54% 45 MB component index (#1559, open)
contract_storage 6.4k 13.2k 33% 1.1 GB entity cache serve (ids in window)
protocol_state 639k 1.99M 24% 100 MB entity cache serve (ids in window)
traced_entry_points 33k 1.16M 2.7% 151 MB nothing yet

traced_entry_points is the obvious first candidate: under 3% hits while holding 150 MB on the ethereum pods. contract_storage costs about 1 GB per ethereum pod for a one-in-three hit; with ENTITY_CACHE_MODE=serve the same requests are answered from memory anyway, so it can go once serve is on. protocol_components and protocol_state still pay for themselves on base, bsc and the fynd instances (up to 81% hits) and should stay until their replacements land.

Not in this PR: removing any cache. That is the follow-up once dev confirms it.

How to test in dev

Set on a dev chain that already runs ENTITY_CACHE_MODE=shadow or serve:

- name: DISABLED_RPC_CACHES
  value: traced_entry_points,contract_storage

Then compare rpc_request_duration_seconds per endpoint and database load against a chain that keeps the caches on, and check rpc_cache_weighted_size drops for the disabled names.

Tests

  • services::cache: a disabled cache runs the fallback on every get and keeps zero entries.
  • services::rpc: a handler with protocol_components disabled sends two identical requests to the gateway.
  • cli: parses one, two, empty and blank-padded lists; rejects an unknown cache name. Existing arg-parsing fixtures updated. Verified the cli tests also pass with DISABLED_RPC_CACHES= (empty) exported, which a plain clap value enum rejected.

🤖 Generated with Claude Code

Add DISABLED_RPC_CACHES (--disabled-rpc-caches), a comma-separated
list of the RpcCache response caches to turn off: contract_storage,
protocol_state, protocol_components, traced_entry_points. A disabled
cache runs the fallback on every call and stores nothing. All caches
stay on by default. Blank entries are ignored so an empty env value
keeps every cache on; unknown names fail startup.

Lets dev measure whether the response caches still earn their memory
next to the entity cache and the storage token cache before any of
them is removed.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

@tvinagre tvinagre left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

2 participants