Enhance substrate ingest limits and optimize simulator stream reuse
This commit is contained in:
@@ -25,6 +25,8 @@ use super::resources::{DiagnosticsState, ExportSampleState, SensorRegistry};
|
||||
/// T1 batch limit per tick. Anything beyond this stays in the channel and
|
||||
/// either drains next tick or gets dropped on full (T1's contract is lossy).
|
||||
const T1_INGEST_BATCH: usize = 1024;
|
||||
const T2_INGEST_BATCH: usize = 512;
|
||||
const T3_INGEST_BATCH: usize = 256;
|
||||
|
||||
/// Drain the three tier channels into ECS state.
|
||||
///
|
||||
@@ -56,10 +58,15 @@ pub(super) fn ingest_system(
|
||||
// T2 — uni streams.
|
||||
{
|
||||
let mut t2 = bridge.t2.lock().unwrap();
|
||||
while let Ok(msg) = t2.try_recv() {
|
||||
histogram!("substrate_latency_us", "tier" => "t2")
|
||||
.record(now.saturating_sub(msg.timestamp_us) as f64);
|
||||
upsert_reading(&mut registry, &mut commands, &mut q, msg);
|
||||
for _ in 0..T2_INGEST_BATCH {
|
||||
match t2.try_recv() {
|
||||
Ok(msg) => {
|
||||
histogram!("substrate_latency_us", "tier" => "t2")
|
||||
.record(now.saturating_sub(msg.timestamp_us) as f64);
|
||||
upsert_reading(&mut registry, &mut commands, &mut q, msg);
|
||||
}
|
||||
Err(_) => break,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,27 +74,32 @@ pub(super) fn ingest_system(
|
||||
// sensor value (NaN if we've never seen this (device, sensor) before).
|
||||
{
|
||||
let mut t3 = bridge.t3.lock().unwrap();
|
||||
while let Ok(inbound) = t3.try_recv() {
|
||||
histogram!("substrate_latency_us", "tier" => "t3")
|
||||
.record(now.saturating_sub(inbound.command.timestamp_us) as f64);
|
||||
let key = (inbound.command.device_id, inbound.command.sensor_id);
|
||||
let current_value = registry
|
||||
.map
|
||||
.get(&key)
|
||||
.and_then(|&e| q.get(e).ok())
|
||||
.map(|d| d.raw_value)
|
||||
.unwrap_or(f64::NAN);
|
||||
let ack = QuicMessage {
|
||||
device_id: inbound.command.device_id,
|
||||
sensor_id: inbound.command.sensor_id,
|
||||
raw_value: current_value,
|
||||
timestamp_us: now_us(),
|
||||
sequence_number: inbound.command.sequence_number,
|
||||
sensor_type: inbound.command.sensor_type,
|
||||
};
|
||||
// Ignore send errors: the demux task may have given up if the
|
||||
// connection died while we were processing.
|
||||
let _ = inbound.reply.send(ack);
|
||||
for _ in 0..T3_INGEST_BATCH {
|
||||
match t3.try_recv() {
|
||||
Ok(inbound) => {
|
||||
histogram!("substrate_latency_us", "tier" => "t3")
|
||||
.record(now.saturating_sub(inbound.command.timestamp_us) as f64);
|
||||
let key = (inbound.command.device_id, inbound.command.sensor_id);
|
||||
let current_value = registry
|
||||
.map
|
||||
.get(&key)
|
||||
.and_then(|&e| q.get(e).ok())
|
||||
.map(|d| d.raw_value)
|
||||
.unwrap_or(f64::NAN);
|
||||
let ack = QuicMessage {
|
||||
device_id: inbound.command.device_id,
|
||||
sensor_id: inbound.command.sensor_id,
|
||||
raw_value: current_value,
|
||||
timestamp_us: now_us(),
|
||||
sequence_number: inbound.command.sequence_number,
|
||||
sensor_type: inbound.command.sensor_type,
|
||||
};
|
||||
// Ignore send errors: the demux task may have given up if the
|
||||
// connection died while we were processing.
|
||||
let _ = inbound.reply.send(ack);
|
||||
}
|
||||
Err(_) => break,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user