tracing_cache/config.rs
1//! Tunable knobs for the cache + driver.
2
3/// Default number of in-flight slab shards (must be a power of two).
4pub const DEFAULT_LANE_COUNT: usize = 16;
5
6/// Optional knobs for the cache + driver. Pass to
7/// [`crate::SpanCache::with_config`] /
8/// [`crate::SpanCache::with_predicate_and_config`]; the no-config
9/// constructors use [`CacheConfig::default`].
10#[derive(Debug, Clone)]
11pub struct CacheConfig {
12 /// Number of in-flight slab shards. Silently clamped to `[1, 256]` and
13 /// rounded up to the next power of two (so `3` becomes `4`, `200`
14 /// becomes `256`, `1000` is capped at `256`). More lanes = more
15 /// concurrent writers without contention; each lane adds a
16 /// `Mutex<Slab<SpanRecord>>` plus consumes one more bit of the encoded
17 /// `tracing::span::Id` for shard selection.
18 /// Default: [`DEFAULT_LANE_COUNT`].
19 pub lane_count: usize,
20 /// Flush the thread-local PENDING buffer to the spillway after this many
21 /// span closures on a single thread. Smaller = lower visibility latency
22 /// for low-traffic threads at the cost of more spillway sends. Default: 8.
23 pub pending_batch: usize,
24 /// Flush the driver's accumulated batch into the shared map after this
25 /// many spans have been received. Smaller = lower visibility latency at
26 /// the cost of more map write-lock acquisitions. Default: 600.
27 pub driver_batch: usize,
28 /// Upper bound on how long the driver will wait before flushing whatever
29 /// it has, even if `driver_batch` hasn't been reached. Default: 1 second.
30 pub driver_interval: std::time::Duration,
31 /// Soft upper bound on each spillway channel (span + event) that moves
32 /// closed records from producer threads to the driver. When producers
33 /// outrun the driver (e.g. many cores + few async workers), this caps
34 /// spillway's internal buffers so the producer can't grow process
35 /// memory unboundedly. `send_many` rejects whole batches when the
36 /// limit is hit and `flush_pending` drops the rejected drain (logging
37 /// at DEBUG). Decoupled from the user-facing `capacity` (the
38 /// BTreeMap bound): the channel is intermediate buffering and only
39 /// needs enough headroom for normal bursts. Default: 65536.
40 pub channel_capacity: u64,
41}
42
43impl Default for CacheConfig {
44 fn default() -> Self {
45 Self {
46 lane_count: DEFAULT_LANE_COUNT,
47 pending_batch: 8,
48 driver_batch: 600,
49 driver_interval: std::time::Duration::from_secs(1),
50 channel_capacity: 65536,
51 }
52 }
53}