pub struct WatchConfig {
pub event_queue_size: usize,
pub watcher_buffer_size: usize,
pub enable_metrics: bool,
}Expand description
Configuration for the Watch mechanism that monitors key changes
The watch system allows clients to monitor specific keys for changes with minimal overhead on the write path. It uses a lock-free event queue and configurable buffer sizes to balance performance and memory usage.
§Performance Characteristics
- Write path overhead: < 0.01% with 100+ watchers
- Event notification latency: typically < 100μs end-to-end
- Memory per watcher: ~2.4KB with default buffer size
§Configuration Example
[raft.watch]
event_queue_size = 1000
watcher_buffer_size = 10
enable_metrics = falseFields§
§event_queue_size: usizeBuffer size for the global event queue shared across all watchers
This queue sits between the write path and the dispatcher thread. A larger queue reduces the chance of dropped events under burst load, but increases memory usage.
Performance Impact:
- Memory: ~24 bytes per slot (key + value pointers + event type)
- Default 1000 slots ≈ 24KB memory
Tuning Guidelines:
- Low traffic (< 1K writes/sec): 500-1000
- Medium traffic (1K-10K writes/sec): 1000-2000
- High traffic (> 10K writes/sec): 2000-5000
Default: 1000
watcher_buffer_size: usizeBuffer size for each individual watcher’s channel
Each registered watcher gets its own channel to receive events. Smaller buffers reduce memory usage but increase the risk of dropping events for slow consumers.
Performance Impact:
- Memory: ~240 bytes per slot per watcher
- 10 slots × 100 watchers = ~240KB total
Tuning Guidelines:
- Fast consumers (< 1ms processing): 5-10
- Normal consumers (1-10ms processing): 10-20
- Slow consumers (> 10ms processing): 20-50
Default: 10
enable_metrics: boolEnable detailed metrics and logging for watch operations
When enabled, logs warnings for dropped events and tracks watch performance metrics. Adds minimal overhead (~0.001%) but useful for debugging and monitoring.
Default: false (minimal overhead in production)
Implementations§
Trait Implementations§
Source§impl Clone for WatchConfig
impl Clone for WatchConfig
Source§fn clone(&self) -> WatchConfig
fn clone(&self) -> WatchConfig
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for WatchConfig
impl Debug for WatchConfig
Source§impl Default for WatchConfig
impl Default for WatchConfig
Source§impl<'de> Deserialize<'de> for WatchConfig
impl<'de> Deserialize<'de> for WatchConfig
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 WatchConfig
impl RefUnwindSafe for WatchConfig
impl Send for WatchConfig
impl Sync for WatchConfig
impl Unpin for WatchConfig
impl UnwindSafe for WatchConfig
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