Expand description
§Task Budget Enforcement
Implements task budget enforcement to ensure Ring 0 latency guarantees are met. Each operation has a time budget, and exceeding it triggers metrics/alerts. Ring 1 background tasks cooperatively yield when Ring 0 has pending work or when their budget is exhausted.
§Budget Constants
| Ring | Operation | Budget | Notes |
|---|---|---|---|
| 0 | Single event | 500ns | p99 latency target |
| 0 | Event batch | 5μs | Up to 10 events |
| 0 | State lookup | 200ns | Fast path |
| 0 | Window trigger | 10μs | Aggregation emission |
| 1 | Background chunk | 1ms | Cooperative yielding |
| 1 | Checkpoint prep | 10ms | Async operation |
| 1 | WAL flush | 100μs | Group commit |
§Usage
ⓘ
use laminar_core::budget::TaskBudget;
// Ring 0: Track single event processing
fn process_event(event: &Event) {
let _budget = TaskBudget::ring0_event();
// Process event - metrics recorded automatically on drop
process(event);
}
// Ring 1: Cooperative yielding
fn process_background_work(&mut self) -> YieldReason {
let budget = TaskBudget::ring1_chunk();
while !budget.exceeded() {
if self.ring0_has_pending() {
return YieldReason::Ring0Priority;
}
// Process work...
}
YieldReason::BudgetExceeded
}§Metrics
The module tracks:
- Task duration histograms (per task type, per ring)
- Budget violation counts
- Amount exceeded (for capacity planning)
Access budget status via TaskBudget methods.
Structs§
- Task
Budget - Tracks execution time budget for a task.
Enums§
- Yield
Reason - Reason Ring 1 yielded control.