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 / standalone.rs

121 lines · 4081 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::{TcpListener, TcpStream};
18use std::sync::atomic::{AtomicBool, Ordering};
19use std::sync::Arc;
20use std::thread;
21use std::time::{Duration, Instant};
22
23pub struct RustStandaloneServer {
24 pub port: u16,
25 running: Arc<AtomicBool>,
26}
27
28impl RustStandaloneServer {
29 pub fn start() -> Result<Self, String> {
30 let listener = TcpListener::bind("127.0.0.1:0")
31 .map_err(|e| format!("Failed to bind ephemeral port: {}", e))?;
32 let port = listener.local_addr().map_err(|e| e.to_string())?.port();
33 listener.set_nonblocking(true).map_err(|e| e.to_string())?;
34
35 let running = Arc::new(AtomicBool::new(true));
36 let running_clone = Arc::clone(&running);
37
38 thread::spawn(move || {
39 while running_clone.load(Ordering::Relaxed) {
40 match listener.accept() {
41 Ok((stream, _)) => {
42 thread::spawn(move || {
43 handle_client(stream);
44 });
45 }
46 Err(ref e) if e.kind() == std::io::ErrorKind::WouldBlock => {
47 thread::sleep(Duration::from_millis(1));
48 }
49 Err(_) => break,
50 }
51 }
52 });
53
54 // Verify listener responds
55 let start = Instant::now();
56 let mut ready = false;
57 while start.elapsed() < Duration::from_secs(3) {
58 if TcpStream::connect(format!("127.0.0.1:{}", port)).is_ok() {
59 ready = true;
60 break;
61 }
62 thread::sleep(Duration::from_millis(10));
63 }
64
65 if !ready {
66 return Err("Rust standalone server failed to respond on port".to_string());
67 }
68
69 Ok(Self { port, running })
70 }
71}
72
73impl Drop for RustStandaloneServer {
74 fn drop(&mut self) {
75 self.running.store(false, Ordering::Relaxed);
76 }
77}
78
79fn handle_client(mut stream: TcpStream) {
80 let _ = stream.set_read_timeout(Some(Duration::from_secs(2)));
81 let _ = stream.set_write_timeout(Some(Duration::from_secs(2)));
82
83 let mut buf = [0u8; 1024];
84 let n = match stream.read(&mut buf) {
85 Ok(n) if n > 0 => n,
86 _ => return,
87 };
88
89 let req = String::from_utf8_lossy(&buf[..n]);
90
91 let (status, body) = if req.starts_with("GET /api/status") || req.starts_with("GET /health") {
92 (
93 "200 OK",
94 r#"{"status":"ok","engine":"rust-standalone","version":"0.1"}"#.to_string(),
95 )
96 } else if req.starts_with("GET /api/query") {
97 (
98 "200 OK",
99 r#"{"id":1,"canonical_name":"benchmark_reference_entity","content":"Verified cryptographic token record for baseline testing"}"#.to_string(),
100 )
101 } else if req.starts_with("GET /api/vector") {
102 let v1 = [0.035f32; 768];
103 let v2 = [0.042f32; 768];
104 let dot: f32 = v1.iter().zip(v2.iter()).map(|(a, b)| a * b).sum();
105 (
106 "200 OK",
107 format!(r#"{{"similarity":{:.5},"dimensions":768}}"#, dot),
108 )
109 } else {
110 ("404 Not Found", r#"{"error":"not found"}"#.to_string())
111 };
112
113 let resp = format!(
114 "HTTP/1.1 {}\r\nContent-Type: application/json\r\nContent-Length: {}\r\nConnection: close\r\n\r\n{}",
115 status,
116 body.len(),
117 body
118 );
119
120 let _ = stream.write_all(resp.as_bytes());
121}