pub struct BlockAccessOptimizer {
pub config: OptimizerConfig,
pub recent_window: VecDeque<AccessEvent>,
pub patterns: HashMap<String, AccessPattern>,
pub co_access: HashMap<String, HashMap<String, CoAccessPair>>,
pub total_events: u64,
pub cache_hit_count: u64,
}Expand description
Access-pattern optimizer that learns block co-access patterns, predicts future accesses, and generates prefetch recommendations.
Fields§
§config: OptimizerConfigConfiguration parameters.
recent_window: VecDeque<AccessEvent>Sliding window of recent access events (bounded by config.window_size).
patterns: HashMap<String, AccessPattern>Per-block access statistics.
co_access: HashMap<String, HashMap<String, CoAccessPair>>Co-access statistics: co_access[cid_a][cid_b].
total_events: u64Total number of events ever recorded.
cache_hit_count: u64Number of events that were cache hits.
Implementations§
Source§impl BlockAccessOptimizer
impl BlockAccessOptimizer
Sourcepub fn new(config: OptimizerConfig) -> Self
pub fn new(config: OptimizerConfig) -> Self
Create a new optimizer with the given configuration.
Sourcepub fn with_defaults() -> Self
pub fn with_defaults() -> Self
Create a new optimizer with default configuration.
Sourcepub fn record_access(&mut self, event: AccessEvent)
pub fn record_access(&mut self, event: AccessEvent)
Record a block access event.
This method:
- Updates the sliding window (evicting the oldest event if necessary).
- Updates the per-block
AccessPatternusing EWMA smoothing (α = 0.3). - Records co-access pairs with the last 5 events in the window.
Sourcepub fn recommend_prefetch(&self, trigger_cid: &str) -> PrefetchRecommendation
pub fn recommend_prefetch(&self, trigger_cid: &str) -> PrefetchRecommendation
Generate a prefetch recommendation for a given trigger CID.
Returns a PrefetchRecommendation even when no candidates meet the
threshold (in that case prefetch_cids will be empty and confidence = 0).
Sourcepub fn predict_next_access(&self, cid: &str) -> Option<u64>
pub fn predict_next_access(&self, cid: &str) -> Option<u64>
Predict the next access timestamp (ms) for the given CID.
Sourcepub fn hot_blocks(&self, k: usize) -> Vec<&AccessPattern>
pub fn hot_blocks(&self, k: usize) -> Vec<&AccessPattern>
Return the top-k hottest blocks by total access count.
Sourcepub fn top_co_access_pairs(&self, k: usize) -> Vec<&CoAccessPair>
pub fn top_co_access_pairs(&self, k: usize) -> Vec<&CoAccessPair>
Return the top-k co-access pairs by co-access count across all CIDs.
Sourcepub fn apply_decay(&mut self)
pub fn apply_decay(&mut self)
Apply exponential decay to all co-access counts.
Counts are multiplied by pattern_decay_factor and rounded.
Pairs whose count drops below 1 are removed.
Sourcepub fn cache_hit_rate(&self) -> f64
pub fn cache_hit_rate(&self) -> f64
Overall cache-hit rate across all recorded events.
Sourcepub fn optimizer_stats(&self) -> OptimizerStats
pub fn optimizer_stats(&self) -> OptimizerStats
Return a snapshot of high-level optimizer statistics.
Auto Trait Implementations§
impl Freeze for BlockAccessOptimizer
impl RefUnwindSafe for BlockAccessOptimizer
impl Send for BlockAccessOptimizer
impl Sync for BlockAccessOptimizer
impl Unpin for BlockAccessOptimizer
impl UnsafeUnpin for BlockAccessOptimizer
impl UnwindSafe for BlockAccessOptimizer
Blanket Implementations§
impl<T> Allocation for T
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more