Skip to content

Commit

Permalink
rr lb优化:在第一次初始化时offset使用随机数,以适配每次都是在新线程使用的场景 (apache#2289)
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoma2015 authored and Yang Liming committed Oct 31, 2023
1 parent 510b1a5 commit 61c3386
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/brpc/policy/round_robin_load_balancer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,9 @@ int RoundRobinLoadBalancer::SelectServer(const SelectIn& in, SelectOut* out) {
TLS tls = s.tls();
if (tls.stride == 0) {
tls.stride = GenRandomStride();
tls.offset = 0;
// use random at first time, for the case of
// use rr lb every time in new thread
tls.offset = butil::fast_rand_less_than(n);
}

for (size_t i = 0; i < n; ++i) {
Expand Down

0 comments on commit 61c3386

Please sign in to comment.