Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion sgl-model-gateway/src/policies/cache_aware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,10 @@ impl LoadBalancingPolicy for CacheAwarePolicy {
matched_worker.to_string()
} else {
RouterMetrics::record_cache_miss();
tree.get_smallest_tenant()
let min_load_idx = *healthy_indices
.iter()
.min_by_key(|&&idx| workers[idx].load())?;
Comment on lines +312 to +314
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This logic for finding the worker with the minimum load is also present earlier in this function (lines 261-264). For consistency and to use a more idiomatic approach, it would be better to use .copied() instead of dereferencing with *. This also makes the code identical to the existing implementation, reducing duplication.

Suggested change
let min_load_idx = *healthy_indices
.iter()
.min_by_key(|&&idx| workers[idx].load())?;
let min_load_idx = healthy_indices.iter().min_by_key(|&&idx| workers[idx].load()).copied()?;

workers[min_load_idx].url().to_string()
};

// Find the index of the selected worker
Expand Down
Loading