pub struct LeaseConfig {
pub enabled: bool,
pub interval_ms: u64,
pub max_cleanup_duration_ms: u64,
}Expand description
Lease configuration for TTL-based key expiration
When enabled = true:
- Server initializes lease manager at startup
- Background worker periodically cleans expired keys
- Client TTL requests (ttl_secs > 0) are accepted
When enabled = false (default):
- No lease components initialized (zero overhead)
- Client TTL requests (ttl_secs > 0) are rejected with error
- All keys are permanent (ttl_secs = 0 is always allowed)
§Performance
Background cleanup overhead: ~0.001% CPU
- Wakes up every
interval_ms(default 1000ms) - Scans expired keys (limited by
max_cleanup_duration_ms) - Deletes expired entries from storage
§Examples
use d_engine_core::config::LeaseConfig;
// Default: disabled
let config = LeaseConfig::default();
assert!(!config.enabled);
// Enable with defaults
let config = LeaseConfig {
enabled: true,
..Default::default()
};
assert_eq!(config.interval_ms, 1000);Fields§
§enabled: boolEnable TTL feature
true: Initialize lease manager + start background cleanup workerfalse: No TTL support, reject requests with ttl_secs > 0
Default: false (zero overhead when TTL not needed)
interval_ms: u64Background cleanup interval in milliseconds
How often the background worker wakes up to scan and delete expired keys.
Range: 100-3600000 (100ms to 1 hour) Default: 1000 (1 second)
Tuning guide:
- 1000ms (default): Balanced for most workloads
- 100-500ms: Aggressive cleanup for memory-sensitive apps
- 5000-10000ms: Relaxed cleanup for low TTL usage
Only used when enabled = true
max_cleanup_duration_ms: u64Maximum cleanup duration per cycle (milliseconds)
Limits how long a single cleanup cycle can run to prevent excessive CPU usage in the background worker.
Range: 1-100ms Default: 1ms
Tuning guide:
- 1ms (default): Safe for latency-sensitive apps
- 5-10ms: Aggressive cleanup when backlog exists
-
10ms: Not recommended (can impact foreground operations)
Only used when enabled = true
Implementations§
Trait Implementations§
Source§impl Clone for LeaseConfig
impl Clone for LeaseConfig
Source§fn clone(&self) -> LeaseConfig
fn clone(&self) -> LeaseConfig
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for LeaseConfig
impl Debug for LeaseConfig
Source§impl Default for LeaseConfig
impl Default for LeaseConfig
Source§impl<'de> Deserialize<'de> for LeaseConfig
impl<'de> Deserialize<'de> for LeaseConfig
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for LeaseConfig
impl RefUnwindSafe for LeaseConfig
impl Send for LeaseConfig
impl Sync for LeaseConfig
impl Unpin for LeaseConfig
impl UnwindSafe for LeaseConfig
Blanket Implementations§
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::Request