codex_memory/performance/
mod.rs1pub mod benchmarks;
4pub mod capacity_planning;
5pub mod load_testing;
6pub mod metrics;
7pub mod optimization;
8pub mod stress_testing;
9
10use serde::{Deserialize, Serialize};
11use std::time::Duration;
12
13#[derive(Debug, Clone, Serialize, Deserialize, Default)]
15pub struct PerformanceConfig {
16 pub enabled: bool,
18
19 pub load_testing: LoadTestConfig,
21
22 pub stress_testing: StressTestConfig,
24
25 pub sla_thresholds: SlaThresholds,
27
28 pub profiling: ProfilingConfig,
30}
31
32#[derive(Debug, Clone, Serialize, Deserialize)]
34pub struct LoadTestConfig {
35 pub concurrent_users: usize,
37
38 pub test_duration: Duration,
40
41 pub ramp_up_time: Duration,
43
44 pub target_rps: u32,
46}
47
48#[derive(Debug, Clone, Serialize, Deserialize)]
50pub struct StressTestConfig {
51 pub max_connections: usize,
53
54 pub memory_pressure_threshold: u8,
56
57 pub cpu_pressure_threshold: u8,
59
60 pub chaos_testing_enabled: bool,
62}
63
64#[derive(Debug, Clone, Serialize, Deserialize)]
66pub struct SlaThresholds {
67 pub p50_latency_ms: u64,
69
70 pub p95_latency_ms: u64,
72
73 pub p99_latency_ms: u64,
75
76 pub min_throughput_rps: u32,
78
79 pub max_error_rate: f64,
81
82 pub cache_hit_ratio_target: f64,
84}
85
86#[derive(Debug, Clone, Serialize, Deserialize)]
88pub struct ProfilingConfig {
89 pub cpu_profiling: bool,
91
92 pub memory_profiling: bool,
94
95 pub io_profiling: bool,
97
98 pub sampling_rate_hz: u32,
100
101 pub output_directory: String,
103}
104
105impl Default for LoadTestConfig {
106 fn default() -> Self {
107 Self {
108 concurrent_users: 100,
109 test_duration: Duration::from_secs(300), ramp_up_time: Duration::from_secs(60), target_rps: 1000,
112 }
113 }
114}
115
116impl Default for StressTestConfig {
117 fn default() -> Self {
118 Self {
119 max_connections: 10000,
120 memory_pressure_threshold: 80,
121 cpu_pressure_threshold: 90,
122 chaos_testing_enabled: false,
123 }
124 }
125}
126
127impl Default for SlaThresholds {
128 fn default() -> Self {
129 Self {
130 p50_latency_ms: 10,
131 p95_latency_ms: 100,
132 p99_latency_ms: 500,
133 min_throughput_rps: 100,
134 max_error_rate: 1.0,
135 cache_hit_ratio_target: 90.0,
136 }
137 }
138}
139
140impl Default for ProfilingConfig {
141 fn default() -> Self {
142 Self {
143 cpu_profiling: true,
144 memory_profiling: true,
145 io_profiling: true,
146 sampling_rate_hz: 100,
147 output_directory: "./profiles".to_string(),
148 }
149 }
150}
151
152#[derive(Debug, Clone, Serialize, Deserialize)]
154pub struct PerformanceTestResult {
155 pub test_name: String,
156 pub test_type: TestType,
157 pub start_time: chrono::DateTime<chrono::Utc>,
158 pub end_time: chrono::DateTime<chrono::Utc>,
159 pub duration: Duration,
160 pub metrics: PerformanceMetrics,
161 pub sla_violations: Vec<SlaViolation>,
162 pub passed: bool,
163}
164
165#[derive(Debug, Clone, Serialize, Deserialize)]
167pub enum TestType {
168 Load,
169 Stress,
170 Spike,
171 Soak,
172 Capacity,
173}
174
175#[derive(Debug, Clone, Serialize, Deserialize)]
177pub struct PerformanceMetrics {
178 pub total_requests: u64,
179 pub successful_requests: u64,
180 pub failed_requests: u64,
181 pub throughput_rps: f64,
182 pub latency_p50_ms: u64,
183 pub latency_p95_ms: u64,
184 pub latency_p99_ms: u64,
185 pub latency_max_ms: u64,
186 pub error_rate: f64,
187 pub cpu_usage_avg: f64,
188 pub memory_usage_avg: f64,
189 pub cache_hit_ratio: f64,
190 pub db_connections_used: u32,
191 pub network_bytes_sent: u64,
192 pub network_bytes_received: u64,
193}
194
195#[derive(Debug, Clone, Serialize, Deserialize)]
197pub struct SlaViolation {
198 pub metric: String,
199 pub threshold: f64,
200 pub actual_value: f64,
201 pub severity: ViolationSeverity,
202 pub timestamp: chrono::DateTime<chrono::Utc>,
203}
204
205#[derive(Debug, Clone, Serialize, Deserialize)]
207pub enum ViolationSeverity {
208 Warning,
209 Critical,
210}