You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The old manager-count logic required both the slope to be below MANAGER_SLOPE and the window average CPU usage to exceed CPU_USAGE_MAX for a window to count as "up". The unified get_up_windows only performs the threshold comparison and never uses the computed avg, so the CPU_USAGE_MAX check is silently dropped for the manager path. This changes behavior: manager windows with low CPU usage now qualify, which can inflate slope_vector and alter the computed mgr_power. The unused avg variable also indicates the CPU check was meant to be carried over.
Inside get_up_windows, avg is computed on every iteration of the inner loop (including slicing and summing avg_cpu_usage) but is never read, since the CPU_USAGE_MAX check was removed. This is dead work per window element and will produce an unused-variable compiler warning; either restore the CPU-usage check or remove the computation and the sm_counter bookkeeping.
current_windows.clear() at the end of the loop body is dead code: current_windows is unconditionally reassigned via .to_vec() at the top of the next iteration, so clearing it has no effect. Harmless, but misleading.
Restore dropped CPU usage check in unified window logic
The avg CPU usage is computed but never used, which means the manager path lost its if avg > CPU_USAGE_MAX check that existed before the refactor. As a result, get_flow_manager_count no longer verifies that managers are busy enough before collecting a window, silently changing the manager computation logic. Add an optional CPU threshold parameter to get_up_windows (e.g. cpu_threshold: Option), pass None from the recycler path and Some(CPU_USAGE_MAX) from the manager path, and apply the check after the slope check.
for current_window in ¤t_windows {
let avg: f32 = avg_cpu_usage[(sm_counter * (avg_cpu_usage.len()/WINDOWS as usize)) ..
((sm_counter + 1) * (avg_cpu_usage.len()/WINDOWS as usize))]
.iter().sum::<f32>() / (avg_cpu_usage.len()/WINDOWS as usize) as f32;
sm_counter+=1;
if (above && current_window > &threshold) || (!above && current_window < &threshold) {
tmp_slope_vector.push(*current_window);
up &= true;
}
else {
up &= false;
break;
}
++ if let Some(cpu_max) = cpu_threshold {+ if avg > cpu_max {+ up &= true;+ }+ else {+ up &= false;+ break;+ }+ }
}
Suggestion importance[1-10]: 8
__
Why: Correct and important: the refactor into get_up_windows silently dropped the if avg > CPU_USAGE_MAX check from the manager path (it existed in the old get_flow_manager_count code), and avg is now computed but unused. This changes manager scaling behavior; adding an optional CPU threshold parameter restores the lost logic.
Medium
Guard against out-of-bounds window slicing
*If result has a length that is not a multiple of WINDOWS (including the empty case), the slice result[(counter*WINDOWS)..((counter+1)WINDOWS)] will panic, and an empty current_windows makes the subsequent .last().expect(...) panic as well as leaving tmp_slope_vector empty while up stays true (leading to a division by zero for the average). Guard the loop with a bounds check before slicing so it terminates gracefully instead of panicking.
loop {
+ if ((counter + 1) * WINDOWS) as usize > result.len() {+ break;+ }+
avg_cpu_usage = Self::get_window_cpu_average_vector(cpu_usages, num_elements, counter);
current_windows = result[(counter*WINDOWS) as usize..((counter+1)*WINDOWS) as usize].to_vec();
Suggestion importance[1-10]: 4
__
Why: The bounds check is technically valid since a non-multiple result length would panic on slicing, and an empty current_windows would panic on .last().expect(...). However, this is a defensive error-handling improvement for an edge case that also existed in the pre-PR code, so its impact is moderate.
Low
General
Prevent NaN from empty average divisions
now_recycled is built with .windows(2), so if the recycled window slice contains fewer than two elements the resulting vector is empty and the division produces NaN, which then propagates into RecyclerUp and the downstream max_by comparison on queue_growth. Guard both averages against empty vectors to avoid NaN poisoning the recycler count computation.
- recycler_up.now_in_queue_avg = now_in_queue.iter().sum::<f64>() / now_in_queue.len() as f64;- recycler_up.now_recycled_avg = now_recycled.iter().sum::<f64>() / now_recycled.len() as f64;+ recycler_up.now_in_queue_avg = if now_in_queue.is_empty() { 0.0 } else { now_in_queue.iter().sum::<f64>() / now_in_queue.len() as f64 };+ recycler_up.now_recycled_avg = if now_recycled.is_empty() { 0.0 } else { now_recycled.iter().sum::<f64>() / now_recycled.len() as f64 };
Suggestion importance[1-10]: 4
__
Why: The suggestion correctly identifies that now_recycled from .windows(2) could be empty and produce NaN. It is a reasonable defensive fix, but it addresses an unlikely edge case (slices sized WINDOWS * num_elements) rather than a clear bug, so impact is limited.
Low
Author self-review: I have reviewed the PR code suggestions, and addressed the relevant ones.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Type
Enhancement
Description
Extract shared
get_up_windowswindow-detection logicAdd
get_window_cpu_average_vectorCPU averaging helperGeneralize threshold checks via
abovedirection parameterReset
upflag per window, fixing stale stateDiagram Walkthrough
File Walkthrough
flow_threads.rs
Unify recycler and manager window computation logicsrc/flow_threads.rs
get_up_windowswith
thresholdandaboveparametersget_window_cpu_average_vectorhelper for per-window CPU usageaveraging
get_recycler_countand manager count logic to reuseget_up_windowsupflag each outer-loop iteration and fix misplaced closingbrace