Skip to content

Replace the account recency LRU with lock-free S3-FIFO #204

Open

Description

@Dodecahedr0x

Goal

Keep frequently read non-authoritative accounts resident under churn by replacing the scc::HashCache LRU in keeper::cache::AccountCache with a lock-free S3-FIFO cache, and let callers record read hits without acquiring an account lease.

Why

Every recency eviction makes the validator unsubscribe the account and delete it from the bank. The next read fetches it upstream again (getMultipleAccounts) and resubscribes. On nodes where RPC middleware fans requests out to many distinct pubkeys, this dominates upstream RPC spend.

The current LRU has three problems for this workload:

  • Recency is promoted only when an account is materialized or a request is satisfied; plain reads are invisible to the cache.
  • LRU has no frequency signal, so a burst of one-off pubkeys flushes the hot set.
  • HashCache rounds capacity up to a power of two (minimum 256) and may evict early under bucket pressure, so lru-capacity is not the real resident bound.

S3-FIFO (Yang et al., SOSP '23) sends new keys through a small probationary FIFO, promotes keys that are hit again into a main FIFO, and readmits recently evicted keys through a ghost queue. Hits only bump a 2-bit atomic counter, so the read path stays lock-free.

Scope

Changes:

  • Replace the recency HashCache in AccountCache with an S3-FIFO cache: scc::HashIndex index (lock-free reads), bounded crossbeam_queue::ArrayQueue small/main/ghost queues, atomic per-entry frequency.
  • Add AccountsAccessor::touch(&Pubkey), a lock-free hit recorder for already-resident accounts.
  • Make lru_capacity an exact resident bound and update its documentation.
  • Keep keeper_account_cache_entries / keeper_account_cache_evictions accurate.

Unchanged:

  • The eviction notification contract: pubkeys still go out on the subscribe_evictions channel, and cached_eviction_applies still re-checks residency under the lease.
  • Lease semantics, and authoritative accounts never entering recency.
  • The lru-capacity config key name.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions