aggregated_thread_load.rs

Overview

This file defines the mechanisms to calculate and maintain an aggregated load metric over a sliding window for a particular thread within a concurrent or distributed system. It focuses primarily on tracking and updating load values associated with message queues and account activities across a sequence of blocks, enabling efficient load analysis and decision-making based on recent thread activity.

The core component is the AggregatedLoad structure, which maintains a sliding window of load snapshots and their associated account loads. This aggregated data supports operations such as obtaining the total load over the window, proposing optimized account routing bitmasks, and updating the load metrics when new blocks are appended. The file also includes a utility function snapshot_load to extract the current message queue length from a block state.

Detailed Descriptions

Type Alias

pub(super) type Load = usize;

Struct: AggregatedLoad

pub(super) struct AggregatedLoad {
    window: Vec<(Load, InThreadAccountsLoad)>,
    cursor: usize,
    aggregated_value: (Load, InThreadAccountsLoad),
    is_filled: bool,
    window_size: usize,
}

Implementation: AggregatedLoad

new(window_size: usize) -> Self


is_ready(&self) -> bool


reset(&mut self)


load_value(&self) -> Load


propose_new_bitmask(&self, current_bitmask: &Bitmask<AccountRouting>) -> Option<Bitmask<AccountRouting>>


append_from<TOptimisticState>(&mut self, block: &AckiNackiBlock, block_state: Arc<TOptimisticState>, metrics: &Option<BlockProductionMetrics>) where TOptimisticState: OptimisticState


Function: snapshot_load<T>(block_state: Arc<T>) -> Load where T: OptimisticState


Interaction with Other Parts of the System


Visual Diagram

classDiagram
class AggregatedLoad {
-window: Vec<(Load, InThreadAccountsLoad)>
-cursor: usize
-aggregated_value: (Load, InThreadAccountsLoad)
-is_filled: bool
-window_size: usize
+new()
+is_ready()
+reset()
+load_value()
+propose_new_bitmask()
+append_from()
}
AggregatedLoad o-- "InThreadAccountsLoad" : uses
AggregatedLoad ..> Bitmask : proposes
AggregatedLoad ..> OptimisticState : interacts with
AggregatedLoad ..> AckiNackiBlock : consumes
AggregatedLoad ..> BlockProductionMetrics : reports to

This diagram shows the AggregatedLoad structure with its key properties and methods, and its dependencies and interactions with other types such as InThreadAccountsLoad, Bitmask, OptimisticState, AckiNackiBlock, and BlockProductionMetrics. The arrows indicate the usage or association relationships.