pub struct LeaseConfig {
pub enabled: bool,
pub cleanup_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
cleanup_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.cleanup_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)
cleanup_interval_ms: u64How often the background worker wakes up to scan and delete expired keys (milliseconds).
This setting controls MEMORY EFFICIENCY only, not TTL correctness.
Expired keys are always rejected at read time via is_expired() regardless of cleanup
timing. Cleanup only reclaims the memory occupied by stale DashMap entries.
Range: 100–60000 (100ms to 60 seconds) Default: 1000 (1 second)
Upper bound rationale: at 60s, a workload of 10K TTL writes/s with TTL=1s accumulates ~600K stale entries (~30MB) between cleanups — acceptable for most deployments. Beyond 60s, memory growth becomes unbounded in high-throughput short-TTL workloads.
Tuning guide:
- 1000ms (default): Good for most workloads
- 100-500ms: High-throughput short-TTL workloads (e.g., rate limiting, sessions)
- 5000-60000ms: Low-frequency TTL usage where memory pressure is not a concern
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
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
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>,
Auto Trait Implementations§
impl Freeze for LeaseConfig
impl RefUnwindSafe for LeaseConfig
impl Send for LeaseConfig
impl Sync for LeaseConfig
impl Unpin for LeaseConfig
impl UnsafeUnpin 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
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>
T in a tonic::Request