torvyn_types/constants.rs
1//! Project-wide constants for the Torvyn runtime.
2//!
3//! Includes version information, default capacity values, and performance
4//! budget constants.
5
6/// The current Torvyn runtime version (semver).
7pub const TORVYN_VERSION: &str = "0.1.0";
8
9/// The minimum compatible Torvyn version for artifacts.
10/// Artifacts produced by versions older than this cannot be loaded.
11pub const MIN_COMPATIBLE_VERSION: &str = "0.1.0";
12
13/// Default stream queue depth.
14///
15/// Per consolidated review (C02-2): changed from 1024 to 64.
16/// This is the number of stream elements a queue can hold before
17/// backpressure activates.
18pub const DEFAULT_QUEUE_DEPTH: usize = 64;
19
20/// Default buffer pool size per tier (number of buffers).
21pub const DEFAULT_BUFFER_POOL_SIZE: usize = 256;
22
23/// Maximum allowed per-element host-side overhead in nanoseconds.
24///
25/// Per Doc 04, Section 11.1: the reactor targets < 5us overhead.
26/// This constant represents the total budget across all subsystems.
27pub const MAX_HOT_PATH_NS: u64 = 5_000;
28
29/// Maximum allowed observability overhead at Production level, in nanoseconds.
30///
31/// Per Doc 05, Section 8.1: < 500ns per element at Production level.
32pub const MAX_OBSERVABILITY_PRODUCTION_NS: u64 = 500;
33
34/// Maximum allowed observability overhead at Diagnostic level, in nanoseconds.
35///
36/// Per Doc 05, Section 8.1: < 2us per element at Diagnostic level.
37pub const MAX_OBSERVABILITY_DIAGNOSTIC_NS: u64 = 2_000;
38
39/// Default low watermark ratio for backpressure recovery.
40///
41/// When a queue's depth drops below `capacity * LOW_WATERMARK_RATIO`,
42/// backpressure is deactivated.
43pub const DEFAULT_LOW_WATERMARK_RATIO: f64 = 0.5;
44
45/// Maximum buffer size in bytes (global cap).
46///
47/// Per Doc 03, Section 4.3: 16 MiB global maximum.
48pub const MAX_BUFFER_SIZE_BYTES: u32 = 16 * 1024 * 1024;
49
50/// Default component invocation timeout in milliseconds.
51///
52/// Per Doc 04, Section 6.5: 5 seconds.
53pub const DEFAULT_COMPONENT_TIMEOUT_MS: u64 = 5_000;
54
55/// Default drain timeout in milliseconds.
56///
57/// Per Doc 04, Section 6.5: 5 seconds.
58pub const DEFAULT_DRAIN_TIMEOUT_MS: u64 = 5_000;
59
60/// Default cooperative cancellation timeout in milliseconds.
61///
62/// Per Doc 04, Section 6.5: 1 second.
63pub const DEFAULT_COOPERATIVE_CANCEL_TIMEOUT_MS: u64 = 1_000;
64
65/// Default maximum consecutive elements before a flow driver must yield.
66///
67/// Per Doc 04, Section 7.3: 256 elements hard ceiling.
68pub const MAX_CONSECUTIVE_ELEMENTS_BEFORE_YIELD: u64 = 256;
69
70/// Default elements per yield at Normal priority.
71///
72/// Per Doc 04, Section 7.2: 32 elements.
73pub const DEFAULT_ELEMENTS_PER_YIELD: u64 = 32;
74
75#[cfg(test)]
76mod tests {
77 use super::*;
78
79 #[test]
80 fn test_version_is_semver() {
81 let parts: Vec<&str> = TORVYN_VERSION.split('.').collect();
82 assert_eq!(parts.len(), 3, "version must be semver (major.minor.patch)");
83 for part in parts {
84 part.parse::<u32>()
85 .expect("each version component must be a number");
86 }
87 }
88
89 #[test]
90 fn test_default_queue_depth_is_power_of_two_minus_one_or_reasonable() {
91 const _: () = {
92 assert!(DEFAULT_QUEUE_DEPTH > 0);
93 assert!(DEFAULT_QUEUE_DEPTH <= 1024);
94 };
95 }
96
97 #[test]
98 fn test_max_buffer_size_is_16_mib() {
99 let size = MAX_BUFFER_SIZE_BYTES;
100 assert_eq!(size, 16 * 1024 * 1024);
101 }
102
103 #[test]
104 fn test_hot_path_budget_is_5_microseconds() {
105 let budget = MAX_HOT_PATH_NS;
106 assert_eq!(budget, 5_000);
107 }
108
109 #[test]
110 fn test_low_watermark_ratio_is_valid() {
111 let ratio = DEFAULT_LOW_WATERMARK_RATIO;
112 assert!(ratio > 0.0);
113 assert!(ratio < 1.0);
114 }
115}