```text
chore: 新增项目规则文档、构建别名及忽略规则 添加 AGENTS.md 项目规则文件,涵盖语言与工具链、模块设计、 Git 提交规范及验证流程等内容。 变更要点: - .cargo/config.toml 新增 xtask 命令别名 - .gitignore 忽略运行时地图缓存、接收器配置文件、 构建锁文件及本地 docs/ 目录 - 新增 AGENTS.md 定义项目编码、提交与审查规则 ```
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
use realtime_core::Store;
|
||||
use rid_shared::Observation;
|
||||
use std::time::{Instant, SystemTime, UNIX_EPOCH};
|
||||
|
||||
fn main() {
|
||||
let count: usize = std::env::args()
|
||||
.nth(1)
|
||||
.unwrap_or("10000".into())
|
||||
.parse()
|
||||
.expect("target count");
|
||||
assert!((1..=100000).contains(&count));
|
||||
let mut store = Store::new(count, count * 2, 30000, 1);
|
||||
let start = Instant::now();
|
||||
for sequence in 0..100 {
|
||||
for id in 0..count {
|
||||
store.apply(
|
||||
Observation {
|
||||
target_id: format!("SIM-{id}"),
|
||||
receiver_id: "SIM".into(),
|
||||
source_epoch: 1,
|
||||
sequence,
|
||||
longitude: 120.0 + id as f64 * 0.00001,
|
||||
latitude: 30.0,
|
||||
altitude_m: 100.0,
|
||||
heading_deg: 90.0,
|
||||
},
|
||||
sequence,
|
||||
);
|
||||
}
|
||||
}
|
||||
let elapsed = start.elapsed();
|
||||
let now = SystemTime::now()
|
||||
.duration_since(UNIX_EPOCH)
|
||||
.unwrap()
|
||||
.as_millis();
|
||||
println!(
|
||||
"{{\"kind\":\"state-core-only-not-end-to-end\",\"targets\":{count},\"updates\":{},\"seconds\":{},\"updates_per_second\":{},\"measured_at_unix_ms\":{now}}}",
|
||||
count * 100,
|
||||
elapsed.as_secs_f64(),
|
||||
count as f64 * 100.0 / elapsed.as_secs_f64()
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
//! Explicit synthetic input generator for an isolated --simulation-api server.
|
||||
use rid_shared::Observation;
|
||||
use std::{
|
||||
io::{BufRead, BufReader, Read, Write},
|
||||
net::TcpStream,
|
||||
time::{Duration, Instant, SystemTime, UNIX_EPOCH},
|
||||
};
|
||||
|
||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let mut count = 1000usize;
|
||||
let mut interval_ms = 20u64;
|
||||
let mut seconds = 30u64;
|
||||
let mut args = std::env::args().skip(1);
|
||||
while let Some(arg) = args.next() {
|
||||
let value = args.next().ok_or("missing argument value")?;
|
||||
match arg.as_str() {
|
||||
"--targets" => count = value.parse()?,
|
||||
"--interval-ms" => interval_ms = value.parse()?,
|
||||
"--seconds" => seconds = value.parse()?,
|
||||
_ => {
|
||||
return Err(
|
||||
"usage: rid-simulator [--targets 1000] [--interval-ms 20] [--seconds 30]"
|
||||
.into(),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
if !(1..=10000).contains(&count)
|
||||
|| !(1..=1000).contains(&interval_ms)
|
||||
|| !(1..=7200).contains(&seconds)
|
||||
{
|
||||
return Err("invalid load; targets 1..10000, interval 1..1000 ms, seconds 1..7200".into());
|
||||
}
|
||||
eprintln!(
|
||||
"SYNTHETIC DATA ONLY: localhost:8787 must use --simulation-api. Requested interval is not a throughput guarantee."
|
||||
);
|
||||
let epoch = SystemTime::now().duration_since(UNIX_EPOCH)?.as_millis() as u64;
|
||||
let socket = TcpStream::connect_timeout(&"127.0.0.1:8787".parse()?, Duration::from_secs(2))?;
|
||||
socket.set_nodelay(true)?;
|
||||
socket.set_read_timeout(Some(Duration::from_secs(5)))?;
|
||||
socket.set_write_timeout(Some(Duration::from_secs(5)))?;
|
||||
let mut connection = BufReader::new(socket);
|
||||
let start = Instant::now();
|
||||
let mut sequence = 0;
|
||||
let mut overruns = 0;
|
||||
while start.elapsed() < Duration::from_secs(seconds) {
|
||||
sequence += 1;
|
||||
let tick = Instant::now();
|
||||
for offset in (0..count).step_by(1000) {
|
||||
let batch: Vec<_> = (offset..(offset + 1000).min(count))
|
||||
.map(|id| Observation {
|
||||
target_id: format!("SIM-{id:05}"),
|
||||
receiver_id: "SIMULATOR".into(),
|
||||
source_epoch: epoch,
|
||||
sequence,
|
||||
longitude: 120.0
|
||||
+ (id as f64).cos() * 0.1
|
||||
+ ((sequence as f64) * 0.01).sin() * 0.005,
|
||||
latitude: 30.0 + (id as f64).sin() * 0.1,
|
||||
altitude_m: 100.0,
|
||||
heading_deg: (id % 360) as f32,
|
||||
})
|
||||
.collect();
|
||||
let body = postcard::to_allocvec(&batch)?;
|
||||
write!(
|
||||
connection.get_mut(),
|
||||
"POST /api/realtime/ingest HTTP/1.1\r\nHost: 127.0.0.1:8787\r\nContent-Type: application/octet-stream\r\nContent-Length: {}\r\nConnection: keep-alive\r\n\r\n",
|
||||
body.len()
|
||||
)?;
|
||||
connection.get_mut().write_all(&body)?;
|
||||
let mut line = String::new();
|
||||
connection.read_line(&mut line)?;
|
||||
if !line.starts_with("HTTP/1.1 200") {
|
||||
return Err(format!("input rejected: {}", line.trim()).into());
|
||||
}
|
||||
let mut length = None;
|
||||
loop {
|
||||
line.clear();
|
||||
if connection.read_line(&mut line)? == 0 {
|
||||
return Err("server closed response headers".into());
|
||||
}
|
||||
if line.len() > 8192 {
|
||||
return Err("response header exceeds limit".into());
|
||||
}
|
||||
if line == "\r\n" {
|
||||
break;
|
||||
}
|
||||
if let Some((name, value)) = line.split_once(':')
|
||||
&& name.eq_ignore_ascii_case("content-length")
|
||||
{
|
||||
length = Some(value.trim().parse::<usize>()?);
|
||||
}
|
||||
}
|
||||
let length = length
|
||||
.filter(|n| *n <= 4096)
|
||||
.ok_or("invalid response length")?;
|
||||
let mut response = vec![0; length];
|
||||
connection.read_exact(&mut response)?;
|
||||
}
|
||||
if let Some(remaining) = Duration::from_millis(interval_ms).checked_sub(tick.elapsed()) {
|
||||
std::thread::sleep(remaining)
|
||||
} else {
|
||||
overruns += 1;
|
||||
}
|
||||
}
|
||||
println!(
|
||||
"{{\"mode\":\"synthetic-http-postcard\",\"targets\":{count},\"requested_interval_ms\":{interval_ms},\"ticks\":{sequence},\"overruns\":{overruns},\"actual_seconds\":{}}}",
|
||||
start.elapsed().as_secs_f64()
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
Reference in New Issue
Block a user