Repository navigation
Description
Analysis baseline: main @ 3ec3455 — 9 November 2026.
Priority: P3
Context / Current Behavior
Scheduling is deliberately local: serialized/coalesced proxy/CrowdSec applies, one monitoring worker, four serial notification attempts per pass, four concurrent certificate binding jobs, bounded discovery reconciliation and native Rust renewal/DDNS/event workers. Several already skip catch-up storms or use exponential backoff.
Limits are not a complete shared resource policy. In particular, scheduled monitoring shares two Rust diagnostic permits with interactive requests. Database coordination, synchronous snapshot/JSON work and many independent wakeups share Bun's event loop and SQL client with SSR.
Problem Statement
Raising one worker's concurrency can saturate another boundary or starve interactive/critical work. There is no measured combined budget for network probes, DB work, CPU-heavy bookkeeping, timers and shutdown. A single global job framework would introduce complexity without necessarily improving these specific limits.
Proposed Architecture / Solution
Define a small resource-policy table and targeted admission/wakeup mechanisms at existing owners. Compose global ceilings, per-subsystem budgets and reserved critical/interactive capacity; use bounded coalescing and durable state as the source of pending work. Keep existing domain schedulers authoritative.
Distinguish CPU/RSS reductions, higher throughput, lower management latency, fair progress and recovery guarantees. Async network I/O does not inherently require another process or become faster merely by moving languages.
Implementation Scope
- Inventory ceilings at DB connection/transaction, controller route, per-host/provider/channel and appliance levels, including DNS assistant/upstream-health admission separate from monitoring.
- Establish numeric budgets from Introduce Comprehensive Background Worker Observability #396/test(workers): verify remaining recovery and platform evidence #397 measurements and perf(workers): measure remaining SQL, lock and history costs #399 query costs, with interactive management and Caddy traffic protected.
- Reserve/partition or fairly share diagnostic permits between scheduled and interactive callers; propagate busy/deadline/cancel reasons to the producer.
- Define fairness by oldest due work and bounded wait across policies, owners/channels and subsystem classes. Critical renewal/recovery must progress during incident/discovery storms.
- Coalesce event wakes, use next-due sleeps/adaptive idle backoff and bounded jitter where beneficial. Preserve monitoring interval semantics; jitter/backoff cannot silently erase a requested cadence.
- Bound running work, local queues and pending markers. Use admission before expensive hydration/network work; avoid holding leases while waiting in an unbounded queue.
- Budget incremental retention/cleanup and realtime sampling so housekeeping cannot monopolize the event loop or database.
- Define overload behavior and observable resource usage; no automatic tuning that oscillates or hides sustained insufficient capacity.
- Keep policy definitions small and local where practical; a new service, central dispatcher or generic job framework requires separate evidence.
Security and Reliability Considerations
Priority never bypasses permission checks, configured-host validation, per-host exclusion, lease/revision fences or restore maintenance. Preserve ACME/provider rate-limit/cooldown semantics and bounded certificate work. Valkey/local invalidations remain lossy hints with a durable recovery path. Backpressure must not become an unbounded retry/log storm or a Caddy data-plane dependency on management responsiveness.
Acceptance Criteria
- A reviewed table defines global and per-class limits, reserved capacity, maximum pending work and numeric fairness/latency targets for the measured appliance envelope.
- Under simultaneous monitoring timeouts, notification backlog, discovery bursts and interactive traffic, configured limits hold and each required class meets its declared progress bound.
- Saturation is reported with bounded rejection/defer/age metrics; producers reduce admission and recover after pressure drops without catch-up storms.
- No unbounded timer/callback/queue accumulation occurs; idle disabled subsystems demonstrate fewer wakeups/reads than the measured baseline.
- Interactive p95/p99 latency, Caddy traffic errors and critical renewal/recovery progress remain within explicitly tested budgets.
- Resource-policy changes preserve observable schedules and are verified against CPU, RSS, connections, FDs and event-loop delay separately.
- The implementation remains targeted; any shared primitive demonstrates reduced duplication or a specific fairness guarantee.
Testing Requirements
Use deterministic fake clocks for due ordering/jitter/backoff/coalescing and tests for per-class/global admission, lost wakes, starvation, stop and lease expiry. Add short mixed-load contention scenarios in #397, plus explicit larger capacity runs for the monitoring target. Verify busy interactive requests, provider cooldowns, cleanup pressure and restoration do not produce stale writes or unauthorized side effects.
Dependencies / Related Issues
Begin policy design with #401, #396, #397 and incremental cost findings from #399. #392 owns monitoring's local pipeline/throughput target, #393 channel delivery fairness and #394 discovery invalidation; coordinate shared limits without making those issues wait for a complete framework. #395 owns cancellation/lifecycle, and #403 owns process restarts. This issue composes resource policy, not domain ownership or process extraction.
Relevant Source Files
- web/src/config/host-monitoring.config.ts
- web/src/config/notifications.config.ts
- web/src/config/certificate-jobs.config.ts
- web/src/config/docker-discovery.config.ts
- web/src/server/Foundation/runtime-reconciler.server.ts
- web/src/server/HostMonitoring/host-monitoring.worker.ts
- web/src/server/Notifications/notification-worker.ts
- web/src/server/Admin/DockerDiscovery/discovery-worker.ts
- web/src/server/WebSockets/realtimeSubscriptions.ts
- web/src/db/index.ts
- core/src/runtime/mod.rs
- core/src/runtime/domain_diagnostics.rs
- core/src/runtime/renewal.rs
- core/src/runtime/ddns/worker.rs
- scripts/runtime-reliability/control.config.ts
Activity
RentnerKev commentedon Nov 12, 2026
The remaining idle-wakeup baseline comparison is now measured on the original fixed-poll worker and the exact reviewed #419 worker, independently of the active mixed-load run.
The same deterministic scheduler drives 90 virtual seconds with no due policies. Original source
d7ffd98183a9eb997b2a28627407e9d5615fe89bperforms 360 timer wakeups and 361 claim-adapter calls, including the immediate startup call. Reviewed sourcebff8667588b51a39dfbeb4332f194193f85a6fcd(treeca30bf5dc875d926821d469e6685796b18c26edf) performs three timer wakeups, four claim-adapter calls and four next-due-adapter calls. Both sources admit immediately, preserve the due-time behavior and clear their timers on stop. Current invalidation restores the 250 ms polling interval and unsubscribes on stop.This is 360 → 3 timer wakeups and 361 → 8 combined logical read-adapter calls over the identical idle timeline. It measures scheduler behavior with injected adapters; it does not measure SQL statements, physical database I/O, CPU, RSS or sustained capacity. The shared lifecycle dependency is a no-work stub, so this comparison is not an additional drain/recovery proof. Existing tests were unchanged.
Bun 1.4.4, exit 0; ignored diagnostic helper SHA-256
38c28a8c50c5b69d693056f34be188768c53ad5bc033e1e37caa5fe0367f4041; original output SHA-256dcb0a45ee20410f606470646c7b8ff42857161271621ba62eac7ee2b26d0a464. Baseline/current input hashes are1cf2ec3814c3923dc448c0450d56b99dd064ba2b2386a55ba0e0ccea128905ffanda4f027ae02d996a49d64f90ca1079535e2282baabe5d8611c4c6be443d93ef35.The separate actual 1,000-policy mixed-contention evidence and its resource/latency limits remain in #419. Main
e260c1f8d28c6d2437411164fe49e9a4377b9465is exactly the reviewed #419 source tree and all ten push workflows have succeeded. A release soak remains outside this normal PR's scope.