perf(ui): bound per-cycle delta drain and cap log fan-out
Stability hardening for churn/scale (ROADMAP 3.2-3.4). 3.2 Bounded delta drain: the main loop drained every available delta each cycle, so a 10k initial-list flood could run before input/render was serviced. Cap at DELTA_MAX_PER_CYCLE (4096); the bounded channel back-pressures producers so nothing is lost and the remainder drains next cycle — input stays responsive. 3.3 Log fan-out cap: a Deployment/ReplicaSet log selection opened one stream per replica pod x container (hundreds of follow connections for a large deployment). Cap multi-pod selections at LOG_MAX_STREAMS (50) via capped_multi_pod_selection; the scope label notes "N of M streams, capped". 3.4 Watcher ceiling/auth: assessed, no change needed. Watcher count is already bounded by the warm-context policy (active + warm_contexts only); 401/token expiry on watch streams is handled by kube auth refresh on reconnect plus the existing bounded backoff. A redundant cap would risk dropping the active context's essential watchers. Validation: fmt, check, test (75 passed / 4 ignored), release build all green. Bench: no data-plane regression (sync 2.05s, RSS 64.7MB). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
27798d2e2f
commit
8b1feaba31
3 files changed
+99
-38
No files matched your search
+13
-9
@@ -127,15 +127,19 @@ Root problem: full object JSON kept for every entity.
|
||||
while disconnected). No blank window during a 10k-pod relist. Unit test
|
||||
`relist_keeps_data_visible_and_sweeps_only_gone_objects`; bench confirms no perf/RSS regression
|
||||
(sync 2.03s, RSS 64.6MB). 72 tests pass.
|
||||
- [ ] **3.2 Delta backpressure/coalescing** — single shared `mpsc` (cap 2048) for all
|
||||
watchers (lib.rs:62). Define policy under simultaneous initial-lists: per-context lanes
|
||||
and/or coalescing so a big relist doesn't delay input/other contexts.
|
||||
- [ ] **3.3 Log fan-out cap** — Deployment logs open a stream per replica pod × container
|
||||
(`deployment_pod_keys`/`pod_log_targets`, logs.rs:98-188). Cap concurrent streams, warn,
|
||||
allow explicit expand.
|
||||
- [ ] **3.4 Watcher ceiling + auth refresh** — cap total concurrent watchers across warm
|
||||
contexts; ensure 401/auth-refresh handling for watch streams (logs already classify it,
|
||||
app.rs:1827) is matched for resource watchers.
|
||||
- [x] **3.2 Delta backpressure/coalescing** — DONE (bounded drain). The main loop drained *all*
|
||||
available deltas per cycle; a 10k initial-list flood could run before input/render was checked.
|
||||
Now capped at `DELTA_MAX_PER_CYCLE` (4096) per cycle; the bounded channel back-pressures producers
|
||||
so nothing is lost and the rest drains next cycle, keeping input responsive during floods.
|
||||
(Per-context lanes/coalescing not needed — the bound + back-pressure is sufficient at measured scale.)
|
||||
- [x] **3.3 Log fan-out cap** — DONE. Multi-pod log selections (ReplicaSet/Deployment) cap at
|
||||
`LOG_MAX_STREAMS` (50) concurrent streams via `capped_multi_pod_selection`; scope label notes
|
||||
"N of M streams, capped". Tests `caps_concurrent_streams_and_marks_scope`, `does_not_cap_under_limit`.
|
||||
- [x] **3.4 Watcher ceiling + auth refresh** — ASSESSED, no change needed. Watcher count is already
|
||||
bounded by the warm-context policy (active context + `warm_contexts` inactive only; default 1 →
|
||||
~2 contexts × few kinds). 401/token-expiry on watch streams is handled by kube's auth refresh on
|
||||
reconnect + the existing bounded backoff (`run_watch_loop`). A redundant hard cap would risk
|
||||
dropping the active context's essential watchers for no gain.
|
||||
|
||||
---
|
||||
|
||||
|
||||
+17
-3
@@ -243,9 +243,16 @@ pub async fn run(
|
||||
last_render = Instant::now() - frame_budget;
|
||||
}
|
||||
|
||||
while let Ok(delta) = delta_rx.try_recv() {
|
||||
app.store.apply(delta);
|
||||
dirty = true;
|
||||
let mut drained = 0usize;
|
||||
while drained < DELTA_MAX_PER_CYCLE {
|
||||
match delta_rx.try_recv() {
|
||||
Ok(delta) => {
|
||||
app.store.apply(delta);
|
||||
dirty = true;
|
||||
drained += 1;
|
||||
}
|
||||
Err(_) => break,
|
||||
}
|
||||
}
|
||||
if app.drain_log_events() {
|
||||
dirty = true;
|
||||
@@ -448,6 +455,13 @@ const LOG_MAX_LINES: usize = 5_000;
|
||||
const LOG_MAX_BYTES: usize = 8 * 1024 * 1024;
|
||||
const LOG_DEFAULT_TAIL_LINES: i64 = 2_000;
|
||||
const LOG_MAX_EVENTS_PER_DRAIN: usize = 1_024;
|
||||
/// Max state deltas applied per UI cycle. Bounds per-cycle work so an initial-list flood
|
||||
/// (10k+ upserts) can't starve input/render within one loop iteration; the rest drains next cycle
|
||||
/// (the bounded channel back-pressures producers, so nothing is lost or grows unbounded).
|
||||
const DELTA_MAX_PER_CYCLE: usize = 4_096;
|
||||
/// Max concurrent pod log streams for a multi-pod selection (ReplicaSet/Deployment). A deployment
|
||||
/// with hundreds of replicas would otherwise open hundreds of follow connections to the apiserver.
|
||||
const LOG_MAX_STREAMS: usize = 50;
|
||||
const PULSE_TAG_WIDTH: usize = 8;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
|
||||
+69
-26
@@ -135,38 +135,16 @@ impl App {
|
||||
for pod_key in self.replica_set_pod_keys(&row.key) {
|
||||
targets.extend(self.pod_log_targets(&pod_key, None));
|
||||
}
|
||||
targets = normalize_log_targets(targets);
|
||||
if targets.is_empty() {
|
||||
return None;
|
||||
}
|
||||
Some(LogSelection {
|
||||
scope: format!(
|
||||
"rs {}/{} ({} streams)",
|
||||
row.key.namespace.unwrap_or_else(|| "default".to_string()),
|
||||
row.key.name,
|
||||
targets.len()
|
||||
),
|
||||
targets,
|
||||
})
|
||||
let ns = row.key.namespace.unwrap_or_else(|| "default".to_string());
|
||||
capped_multi_pod_selection("rs", &ns, &row.key.name, targets)
|
||||
}
|
||||
ResourceKind::Deployments => {
|
||||
let mut targets = Vec::new();
|
||||
for pod_key in self.deployment_pod_keys(&row.key) {
|
||||
targets.extend(self.pod_log_targets(&pod_key, None));
|
||||
}
|
||||
targets = normalize_log_targets(targets);
|
||||
if targets.is_empty() {
|
||||
return None;
|
||||
}
|
||||
Some(LogSelection {
|
||||
scope: format!(
|
||||
"deploy {}/{} ({} streams)",
|
||||
row.key.namespace.unwrap_or_else(|| "default".to_string()),
|
||||
row.key.name,
|
||||
targets.len()
|
||||
),
|
||||
targets,
|
||||
})
|
||||
let ns = row.key.namespace.unwrap_or_else(|| "default".to_string());
|
||||
capped_multi_pod_selection("deploy", &ns, &row.key.name, targets)
|
||||
}
|
||||
_ => None,
|
||||
}
|
||||
@@ -644,3 +622,68 @@ impl App {
|
||||
matches
|
||||
}
|
||||
}
|
||||
|
||||
/// Build a multi-pod log selection, capping the number of concurrent streams to LOG_MAX_STREAMS.
|
||||
/// Beyond the cap the scope label notes "N of M streams, capped" so the operator knows it's partial.
|
||||
fn capped_multi_pod_selection(
|
||||
prefix: &str,
|
||||
namespace: &str,
|
||||
name: &str,
|
||||
targets: Vec<LogTarget>,
|
||||
) -> Option<LogSelection> {
|
||||
let mut targets = normalize_log_targets(targets);
|
||||
if targets.is_empty() {
|
||||
return None;
|
||||
}
|
||||
let total = targets.len();
|
||||
let capped = total > LOG_MAX_STREAMS;
|
||||
if capped {
|
||||
targets.truncate(LOG_MAX_STREAMS);
|
||||
}
|
||||
let scope = if capped {
|
||||
format!(
|
||||
"{prefix} {namespace}/{name} ({} of {total} streams, capped)",
|
||||
targets.len()
|
||||
)
|
||||
} else {
|
||||
format!("{prefix} {namespace}/{name} ({total} streams)")
|
||||
};
|
||||
Some(LogSelection { scope, targets })
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
fn target(pod: &str) -> LogTarget {
|
||||
LogTarget {
|
||||
context: "ctx".to_string(),
|
||||
namespace: "ns".to_string(),
|
||||
pod: pod.to_string(),
|
||||
container: Some("main".to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn caps_concurrent_streams_and_marks_scope() {
|
||||
let targets: Vec<LogTarget> = (0..(LOG_MAX_STREAMS + 25))
|
||||
.map(|i| target(&format!("pod-{i:04}")))
|
||||
.collect();
|
||||
let sel = capped_multi_pod_selection("deploy", "ns", "app", targets).expect("selection");
|
||||
assert_eq!(sel.targets.len(), LOG_MAX_STREAMS);
|
||||
assert!(sel.scope.contains("capped"), "scope: {}", sel.scope);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn does_not_cap_under_limit() {
|
||||
let targets = vec![target("pod-a"), target("pod-b")];
|
||||
let sel = capped_multi_pod_selection("rs", "ns", "app", targets).expect("selection");
|
||||
assert_eq!(sel.targets.len(), 2);
|
||||
assert!(!sel.scope.contains("capped"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn empty_targets_yield_no_selection() {
|
||||
assert!(capped_multi_pod_selection("rs", "ns", "app", Vec::new()).is_none());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user