MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / update

Method update

nodedb-bridge/src/backpressure.rs:101–149  ·  view source on GitHub ↗

Update the backpressure state based on current queue utilization. Returns the new state if a transition occurred, or `None` if unchanged. The caller SHOULD emit a tracing event on transitions.

(&self, utilization_percent: u8)

Source from the content-addressed store, hash-verified

99 /// Returns the new state if a transition occurred, or `None` if unchanged.
100 /// The caller SHOULD emit a tracing event on transitions.
101 pub fn update(&self, utilization_percent: u8) -> Option<PressureState> {
102 let current = PressureState::from_u8(self.state.load(Ordering::Relaxed));
103
104 let new_state = match current {
105 PressureState::Normal => {
106 if utilization_percent >= self.config.suspend_enter {
107 PressureState::Suspended
108 } else if utilization_percent >= self.config.throttle_enter {
109 PressureState::Throttled
110 } else {
111 return None;
112 }
113 }
114 PressureState::Throttled => {
115 if utilization_percent >= self.config.suspend_enter {
116 PressureState::Suspended
117 } else if utilization_percent < self.config.throttle_exit {
118 PressureState::Normal
119 } else {
120 return None;
121 }
122 }
123 PressureState::Suspended => {
124 if utilization_percent < self.config.suspend_exit {
125 if utilization_percent < self.config.throttle_exit {
126 PressureState::Normal
127 } else {
128 PressureState::Throttled
129 }
130 } else {
131 return None;
132 }
133 }
134 };
135
136 self.state.store(new_state as u8, Ordering::Release);
137
138 match new_state {
139 PressureState::Throttled => {
140 self.throttle_count.fetch_add(1, Ordering::Relaxed);
141 }
142 PressureState::Suspended => {
143 self.suspend_count.fetch_add(1, Ordering::Relaxed);
144 }
145 PressureState::Normal => {}
146 }
147
148 Some(new_state)
149 }
150
151 /// Current backpressure state.
152 pub fn state(&self) -> PressureState {

Calls 2

loadMethod · 0.45
storeMethod · 0.45