pub struct StorageHotspotDetector {
pub records: HashMap<u64, BlockAccessRecord>,
pub config: DetectorConfig,
pub total_events: u64,
}Expand description
Detects storage hotspots using sliding-window access counting and exponential decay scoring.
§Algorithm
Each block maintains a floating-point score that grows whenever an access is
recorded (weighted by AccessType) and shrinks exponentially as logical
time elapses (score *= decay_factor^ticks_elapsed). Events older than
window_ticks are purged to bound memory usage. A block is classified as a
hotspot when its decay-adjusted score equals or exceeds hotspot_threshold.
Fields§
§records: HashMap<u64, BlockAccessRecord>Per-block access records, keyed by block identifier.
config: DetectorConfigDetector configuration.
total_events: u64Total number of access events recorded since creation.
Implementations§
Source§impl StorageHotspotDetector
impl StorageHotspotDetector
Sourcepub fn new(config: DetectorConfig) -> Self
pub fn new(config: DetectorConfig) -> Self
Create a new detector with the supplied configuration.
Sourcepub fn record_access(&mut self, event: AccessEvent)
pub fn record_access(&mut self, event: AccessEvent)
Record a block access event.
The record for event.block_id is created on first access. Decay is
applied for every tick that has elapsed since the last recorded event,
events older than the window are evicted, and the event weight is added
to the score.
Sourcepub fn hotspot_score(
&self,
block_id: u64,
current_tick: u64,
) -> Option<HotspotScore>
pub fn hotspot_score( &self, block_id: u64, current_tick: u64, ) -> Option<HotspotScore>
Return the decay-adjusted HotspotScore for block_id as of current_tick.
Returns None if the block has never been tracked.
Sourcepub fn hotspots(&self, current_tick: u64) -> Vec<HotspotScore>
pub fn hotspots(&self, current_tick: u64) -> Vec<HotspotScore>
Return all blocks currently classified as hotspots, sorted by score descending.
Sourcepub fn top_n(&self, n: usize, current_tick: u64) -> Vec<HotspotScore>
pub fn top_n(&self, n: usize, current_tick: u64) -> Vec<HotspotScore>
Return the top n blocks ordered by decay-adjusted score descending.
Non-hotspot blocks are included; the caller must check is_hotspot if
only confirmed hotspots are required.
Sourcepub fn evict_cold(&mut self, current_tick: u64) -> usize
pub fn evict_cold(&mut self, current_tick: u64) -> usize
Remove all block records whose decay-adjusted score has fallen below 0.001.
Returns the number of records that were removed.
Sourcepub fn stats(&self, current_tick: u64) -> HotspotDetectorStats
pub fn stats(&self, current_tick: u64) -> HotspotDetectorStats
Return aggregate statistics for the current state of the detector.
Auto Trait Implementations§
impl Freeze for StorageHotspotDetector
impl RefUnwindSafe for StorageHotspotDetector
impl Send for StorageHotspotDetector
impl Sync for StorageHotspotDetector
impl Unpin for StorageHotspotDetector
impl UnsafeUnpin for StorageHotspotDetector
impl UnwindSafe for StorageHotspotDetector
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