interplane.Get Omega
Read in your language

benchmarks-mv

Measurement harnesses and evidence bundles for AIEN on the NVIDIA DGX Spark GB10. Speed is reported against the machine's physical limit and my own previous run. Attachment of AienOS.

Brought by drakestapleton

branch main Branches Tags History

benchmarks-mv / src / harness / http_bench.rs

178 lines · 5521 bytes Raw Blame History
1// SPDX-License-Identifier: Apache-2.0
2// Copyright 2026 Drake Stapleton (AIEN / aien-dev)
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15
16use std::io::{Read, Write};
17use std::net::TcpStream;
18use std::sync::{Arc, Mutex};
19use std::thread;
20use std::time::{Duration, Instant};
21
22#[derive(Debug, Clone)]
23#[allow(dead_code)]
24pub struct HttpBenchResult {
25 pub endpoint: String,
26 pub total_requests: usize,
27 pub successful: usize,
28 pub failed: usize,
29 pub total_elapsed_secs: f64,
30 pub requests_per_sec: f64,
31 pub p50_ms: f64,
32 pub p95_ms: f64,
33 pub p99_ms: f64,
34 pub min_ms: f64,
35 pub max_ms: f64,
36}
37
38fn send_single_request(
39 host: &str,
40 port: u16,
41 path: &str,
42 auth_token: Option<&str>,
43) -> Result<f64, String> {
44 let start = Instant::now();
45 let addr = format!("{}:{}", host, port);
46 let mut stream = TcpStream::connect(&addr).map_err(|e| format!("Connect failed: {}", e))?;
47 stream
48 .set_read_timeout(Some(Duration::from_secs(5)))
49 .map_err(|e| e.to_string())?;
50 stream
51 .set_write_timeout(Some(Duration::from_secs(5)))
52 .map_err(|e| e.to_string())?;
53
54 let mut req = format!(
55 "GET {} HTTP/1.1\r\nHost: {}:{}\r\nConnection: close\r\nUser-Agent: aien-benchmarks/0.1\r\n",
56 path, host, port
57 );
58 if let Some(tok) = auth_token {
59 req.push_str(&format!("Authorization: Bearer {}\r\n", tok));
60 }
61 req.push_str("\r\n");
62
63 stream
64 .write_all(req.as_bytes())
65 .map_err(|e| format!("Write error: {}", e))?;
66
67 let mut buf = [0u8; 1024];
68 let n = stream
69 .read(&mut buf)
70 .map_err(|e| format!("Read error: {}", e))?;
71 if n == 0 {
72 return Err("Empty response".to_string());
73 }
74
75 let elapsed = start.elapsed().as_secs_f64() * 1000.0;
76 Ok(elapsed)
77}
78
79pub fn run_http_benchmark(
80 host: &str,
81 port: u16,
82 path: &str,
83 auth_token: Option<&str>,
84 concurrency: usize,
85 total_requests: usize,
86 warmup: usize,
87) -> Result<HttpBenchResult, String> {
88 // 1. Warmup
89 for _ in 0..warmup {
90 let _ = send_single_request(host, port, path, auth_token);
91 }
92
93 // 2. Concurrency execution
94 let requests_per_worker = total_requests / concurrency.max(1);
95 let all_latencies = Arc::new(Mutex::new(Vec::with_capacity(total_requests)));
96 let successful_count = Arc::new(Mutex::new(0usize));
97 let failed_count = Arc::new(Mutex::new(0usize));
98
99 let overall_start = Instant::now();
100 let mut handles = Vec::with_capacity(concurrency);
101
102 for _ in 0..concurrency {
103 let host_c = host.to_string();
104 let path_c = path.to_string();
105 let tok_c = auth_token.map(|s| s.to_string());
106 let latencies_arc = Arc::clone(&all_latencies);
107 let success_arc = Arc::clone(&successful_count);
108 let failed_arc = Arc::clone(&failed_count);
109
110 handles.push(thread::spawn(move || {
111 let mut local_samples = Vec::with_capacity(requests_per_worker);
112 let mut local_succ = 0;
113 let mut local_fail = 0;
114
115 for _ in 0..requests_per_worker {
116 match send_single_request(&host_c, port, &path_c, tok_c.as_deref()) {
117 Ok(lat) => {
118 local_samples.push(lat);
119 local_succ += 1;
120 }
121 Err(_) => {
122 local_fail += 1;
123 }
124 }
125 }
126
127 {
128 let mut l = latencies_arc.lock().unwrap();
129 l.extend(local_samples);
130 }
131 {
132 let mut s = success_arc.lock().unwrap();
133 *s += local_succ;
134 }
135 {
136 let mut f = failed_arc.lock().unwrap();
137 *f += local_fail;
138 }
139 }));
140 }
141
142 for h in handles {
143 let _ = h.join();
144 }
145
146 let overall_elapsed = overall_start.elapsed().as_secs_f64();
147 let mut latencies = all_latencies.lock().unwrap().clone();
148 latencies.sort_by(|a, b| a.partial_cmp(b).unwrap_or(std::cmp::Ordering::Equal));
149
150 let successful = *successful_count.lock().unwrap();
151 let failed = *failed_count.lock().unwrap();
152
153 if latencies.is_empty() {
154 return Err("All benchmark requests failed".to_string());
155 }
156
157 let count = latencies.len();
158 let p50 = latencies[count * 50 / 100];
159 let p95 = latencies[count * 95 / 100];
160 let p99 = latencies[(count * 99 / 100).min(count - 1)];
161 let min_val = latencies[0];
162 let max_val = latencies[count - 1];
163 let req_per_sec = (successful as f64) / overall_elapsed.max(0.0001);
164
165 Ok(HttpBenchResult {
166 endpoint: format!("http://{}:{}{}", host, port, path),
167 total_requests: count,
168 successful,
169 failed,
170 total_elapsed_secs: overall_elapsed,
171 requests_per_sec: req_per_sec,
172 p50_ms: p50,
173 p95_ms: p95,
174 p99_ms: p99,
175 min_ms: min_val,
176 max_ms: max_val,
177 })
178}