[2/N] [History Server Beta] [Feat] LRU cache #4796
All Vouch review confidence checks passed
Residual risk 0.22 = Change Risk (0.52) × (1 − Review Confidence (0.57)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.52 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.388
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #4796"
general
weight: 0.35
JiangJiaWei1103
Why are these changes needed?
Alpha Problems
Unbounded memory growth: The parsed state lived in the stateful
EventHandler's in-memory maps through the process lifetime.Beta Strategy
In this PR, we use per-call (stateless)
EventHandlerand add a per-replica, count-based LRU cache. So, the memory usage is bounded byO(#cached_sessions x max_session_snapshot_size).Overview
System Architecture
Request Data Flow
Change Summary
1. Per-Call
EventHandler+ LRU CacheThe original
EventHandleris stateful, and its ingestion maps grow unbounded, risking OOM. This PR creates anEventHandlerper call on the cold path, so the raw maps become GC-eligible once the snapshot is built. An LRU cache then bounds the number of processed snapshots kept in memory.Per-call
EventHandlerin a nutshell:2. Separation of Concerns:
eventservervs.historyserver(SessionSnapshotas SSOT)Previously, the history server (router) read directly from the in-memory maps, tightly coupling it to the event server (which had to expose multiple getters). This PR decouples them so each side owns a single concern:
eventserver(ingestion): Parse raw events and build the snapshothistoryserver(presentation): Read the snapshot and format it for the Ray Dashboard APIThe only contract between them is a frozen, read-only
SessionSnapshot, acting as the single source of truth: one*SessionSnapshotis shared across concurrent handlers, and each handler receives its own per-request view.3. Remove Dead Code
This PR removes
GetTaskByID,GetActors,GetActorByID,GetJobByJobID, andGetNodeByNodeIDfor two reasons:1. With the per-call handler, each handler instance lives entirely within
ProcessSession(i.e., there are no external references to it).2. They duplicate five existing unexported getters with identical functionality, making them redundant.
Related issue number
Part of https://github.com/ray-project/kuberay/issues/4709.
How to test
Expected Output
Checks
- [x] Unit tests
- [x] Manual tests
- [ ] This PR is not tested :(