codex_memory/performance/
mod.rs1pub mod benchmarks;
4pub mod capacity_planning;
5pub mod dashboard;
6pub mod load_testing;
7pub mod metrics;
8pub mod optimization;
9pub mod stress_testing;
10
11use serde::{Deserialize, Serialize};
12use std::time::Duration;
13
14#[derive(Debug, Clone, Serialize, Deserialize, Default)]
16pub struct PerformanceConfig {
17 pub enabled: bool,
19
20 pub load_testing: LoadTestConfig,
22
23 pub stress_testing: StressTestConfig,
25
26 pub sla_thresholds: SlaThresholds,
28
29 pub profiling: ProfilingConfig,
31}
32
33#[derive(Debug, Clone, Serialize, Deserialize)]
35pub struct LoadTestConfig {
36 pub concurrent_users: usize,
38
39 pub test_duration: Duration,
41
42 pub ramp_up_time: Duration,
44
45 pub target_rps: u32,
47}
48
49#[derive(Debug, Clone, Serialize, Deserialize)]
51pub struct StressTestConfig {
52 pub max_connections: usize,
54
55 pub memory_pressure_threshold: u8,
57
58 pub cpu_pressure_threshold: u8,
60
61 pub chaos_testing_enabled: bool,
63}
64
65#[derive(Debug, Clone, Serialize, Deserialize)]
67pub struct SlaThresholds {
68 pub p50_latency_ms: u64,
70
71 pub p95_latency_ms: u64,
73
74 pub p99_latency_ms: u64,
76
77 pub min_throughput_rps: u32,
79
80 pub max_error_rate: f64,
82
83 pub cache_hit_ratio_target: f64,
85}
86
87#[derive(Debug, Clone, Serialize, Deserialize)]
89pub struct ProfilingConfig {
90 pub cpu_profiling: bool,
92
93 pub memory_profiling: bool,
95
96 pub io_profiling: bool,
98
99 pub sampling_rate_hz: u32,
101
102 pub output_directory: String,
104}
105
106impl Default for LoadTestConfig {
107 fn default() -> Self {
108 Self {
109 concurrent_users: 100,
110 test_duration: Duration::from_secs(300), ramp_up_time: Duration::from_secs(60), target_rps: 1000,
113 }
114 }
115}
116
117impl Default for StressTestConfig {
118 fn default() -> Self {
119 Self {
120 max_connections: 10000,
121 memory_pressure_threshold: 80,
122 cpu_pressure_threshold: 90,
123 chaos_testing_enabled: false,
124 }
125 }
126}
127
128impl Default for SlaThresholds {
129 fn default() -> Self {
130 Self {
131 p50_latency_ms: 10,
132 p95_latency_ms: 100,
133 p99_latency_ms: 500,
134 min_throughput_rps: 100,
135 max_error_rate: 1.0,
136 cache_hit_ratio_target: 90.0,
137 }
138 }
139}
140
141impl Default for ProfilingConfig {
142 fn default() -> Self {
143 Self {
144 cpu_profiling: true,
145 memory_profiling: true,
146 io_profiling: true,
147 sampling_rate_hz: 100,
148 output_directory: "./profiles".to_string(),
149 }
150 }
151}
152
153#[derive(Debug, Clone, Serialize, Deserialize)]
155pub struct PerformanceTestResult {
156 pub test_name: String,
157 pub test_type: TestType,
158 pub start_time: chrono::DateTime<chrono::Utc>,
159 pub end_time: chrono::DateTime<chrono::Utc>,
160 pub duration: Duration,
161 pub metrics: PerformanceMetrics,
162 pub sla_violations: Vec<SlaViolation>,
163 pub passed: bool,
164}
165
166#[derive(Debug, Clone, Serialize, Deserialize)]
168pub enum TestType {
169 Load,
170 Stress,
171 Spike,
172 Soak,
173 Capacity,
174}
175
176#[derive(Debug, Clone, Serialize, Deserialize)]
178pub struct PerformanceMetrics {
179 pub total_requests: u64,
180 pub successful_requests: u64,
181 pub failed_requests: u64,
182 pub throughput_rps: f64,
183 pub latency_p50_ms: u64,
184 pub latency_p95_ms: u64,
185 pub latency_p99_ms: u64,
186 pub latency_max_ms: u64,
187 pub error_rate: f64,
188 pub cpu_usage_avg: f64,
189 pub memory_usage_avg: f64,
190 pub cache_hit_ratio: f64,
191 pub db_connections_used: u32,
192 pub network_bytes_sent: u64,
193 pub network_bytes_received: u64,
194}
195
196#[derive(Debug, Clone, Serialize, Deserialize)]
198pub struct SlaViolation {
199 pub metric: String,
200 pub threshold: f64,
201 pub actual_value: f64,
202 pub severity: ViolationSeverity,
203 pub timestamp: chrono::DateTime<chrono::Utc>,
204}
205
206#[derive(Debug, Clone, Serialize, Deserialize)]
208pub enum ViolationSeverity {
209 Warning,
210 Critical,
211}