Adjust SPSC read depth based on worst-case pressure across all engines. Called once per tick. Mutates `spsc_read_depth`, `pressure_suspend_reads`, and `pressure_normal_ticks`.
(&mut self)
| 79 | /// Called once per tick. Mutates `spsc_read_depth`, `pressure_suspend_reads`, |
| 80 | /// and `pressure_normal_ticks`. |
| 81 | pub fn apply_spsc_pressure(&mut self) { |
| 82 | let Some(ref governor) = self.governor else { |
| 83 | return; |
| 84 | }; |
| 85 | |
| 86 | // Worst-case pressure across all engines that have a budget. |
| 87 | let worst = governor.worst_engine_pressure(); |
| 88 | |
| 89 | match worst { |
| 90 | PressureLevel::Normal | PressureLevel::Warning => { |
| 91 | self.pressure_normal_ticks = self.pressure_normal_ticks.saturating_add(1); |
| 92 | if self.pressure_suspend_reads |
| 93 | && self.pressure_normal_ticks >= PRESSURE_NORMAL_HYSTERESIS |
| 94 | { |
| 95 | // Emergency cleared — lift suspension first. |
| 96 | self.pressure_suspend_reads = false; |
| 97 | warn!( |
| 98 | core = self.core_id, |
| 99 | "pressure cleared — resuming SPSC reads" |
| 100 | ); |
| 101 | } |
| 102 | if self.spsc_read_depth < SPSC_READ_DEPTH_NORMAL |
| 103 | && self.pressure_normal_ticks >= PRESSURE_NORMAL_HYSTERESIS |
| 104 | { |
| 105 | self.spsc_read_depth = SPSC_READ_DEPTH_NORMAL; |
| 106 | warn!( |
| 107 | core = self.core_id, |
| 108 | read_depth = self.spsc_read_depth, |
| 109 | "pressure normal — restored SPSC read depth" |
| 110 | ); |
| 111 | } |
| 112 | } |
| 113 | PressureLevel::Critical => { |
| 114 | self.pressure_normal_ticks = 0; |
| 115 | if self.pressure_suspend_reads { |
| 116 | // Coming down from Emergency: lift suspension, set throttled depth. |
| 117 | self.pressure_suspend_reads = false; |
| 118 | warn!( |
| 119 | core = self.core_id, |
| 120 | "pressure Critical — lifting SPSC suspension" |
| 121 | ); |
| 122 | } |
| 123 | let new_depth = (self.spsc_read_depth / 2).max(1); |
| 124 | if new_depth != self.spsc_read_depth { |
| 125 | self.spsc_read_depth = new_depth; |
| 126 | warn!( |
| 127 | core = self.core_id, |
| 128 | read_depth = new_depth, |
| 129 | "Critical memory pressure — reduced SPSC read depth" |
| 130 | ); |
| 131 | } |
| 132 | } |
| 133 | PressureLevel::Emergency => { |
| 134 | self.pressure_normal_ticks = 0; |
| 135 | if !self.pressure_suspend_reads { |
| 136 | self.pressure_suspend_reads = true; |
| 137 | self.spsc_read_depth = 1; |
| 138 | warn!( |