pub struct BlockCompressionAdvisor {
pub profiles: HashMap<String, BlockProfile>,
pub config: AdvisorConfig,
}Expand description
Analyses block access patterns and sizes to recommend optimal compression codecs and tracks achieved compression ratios.
Fields§
§profiles: HashMap<String, BlockProfile>Per-block profiles keyed by CID.
config: AdvisorConfigConfiguration thresholds used by the recommendation logic.
Implementations§
Source§impl BlockCompressionAdvisor
impl BlockCompressionAdvisor
Sourcepub fn new(config: AdvisorConfig) -> Self
pub fn new(config: AdvisorConfig) -> Self
Creates a new advisor with the supplied configuration.
Sourcepub fn register_block(
&mut self,
cid: String,
raw_size_bytes: u64,
access_count: u64,
)
pub fn register_block( &mut self, cid: String, raw_size_bytes: u64, access_count: u64, )
Registers a block (or updates its raw_size_bytes and access_count
if it already exists).
Sourcepub fn record_compression(
&mut self,
cid: &str,
compressed_size_bytes: u64,
codec: CompressionCodec,
)
pub fn record_compression( &mut self, cid: &str, compressed_size_bytes: u64, codec: CompressionCodec, )
Records the outcome of a compression operation for an existing block.
Has no effect when the CID is unknown.
Sourcepub fn recommend(&self, cid: &str) -> Option<AdvisorRecommendation>
pub fn recommend(&self, cid: &str) -> Option<AdvisorRecommendation>
Returns a codec recommendation for the block identified by cid.
Returns None when:
- the block is not registered, or
- the block’s raw size is below
AdvisorConfig::min_size_for_compression.
Sourcepub fn recommend_all(&self) -> Vec<AdvisorRecommendation>
pub fn recommend_all(&self) -> Vec<AdvisorRecommendation>
Returns recommendations for every registered block that qualifies for
compression, sorted by estimated_savings_bytes in descending order.
Sourcepub fn total_space_savings(&self) -> u64
pub fn total_space_savings(&self) -> u64
Returns the total bytes saved across all profiles that have been compressed.
Sourcepub fn stats_for(&self, cid: &str) -> Option<&BlockProfile>
pub fn stats_for(&self, cid: &str) -> Option<&BlockProfile>
Returns an immutable reference to the profile for cid, if it exists.
Auto Trait Implementations§
impl Freeze for BlockCompressionAdvisor
impl RefUnwindSafe for BlockCompressionAdvisor
impl Send for BlockCompressionAdvisor
impl Sync for BlockCompressionAdvisor
impl Unpin for BlockCompressionAdvisor
impl UnsafeUnpin for BlockCompressionAdvisor
impl UnwindSafe for BlockCompressionAdvisor
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