Skip to content

Commit 4118b59

Browse files
committed
opt(lb): optimize the performance of weighted_random load balancer
1 parent 03191ec commit 4118b59

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

volo/src/discovery/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,8 @@ impl Discover for StaticDiscover {
165165
}
166166
}
167167

168-
/// [`WeightedStaticDiscover`] is a simple implementation of [`Discover`] that returns a static list of
169-
/// instances with weight.
168+
/// [`WeightedStaticDiscover`] is a simple implementation of [`Discover`] that returns a static list
169+
/// of instances with weight.
170170
#[derive(Clone)]
171171
pub struct WeightedStaticDiscover {
172172
instances: Vec<Arc<Instance>>,

volo/src/loadbalance/random.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -162,12 +162,16 @@ where
162162

163163
#[cfg(test)]
164164
mod tests {
165-
use super::{LoadBalance, WeightedRandomBalance};
166-
use crate::discovery::WeightedStaticDiscover;
167-
use crate::{context::Endpoint, discovery::StaticDiscover};
168-
use rand::{rng, RngCore};
169165
use std::collections::HashMap;
170166

167+
use rand::{rng, RngCore};
168+
169+
use super::{LoadBalance, WeightedRandomBalance};
170+
use crate::{
171+
context::Endpoint,
172+
discovery::{StaticDiscover, WeightedStaticDiscover},
173+
};
174+
171175
#[tokio::test]
172176
async fn test_weighted_random() {
173177
let empty = Endpoint::new("".into());

0 commit comments

Comments
 (0)