This is an automated email from the ASF dual-hosted git repository.

serverglen pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/brpc.git


The following commit(s) were added to refs/heads/master by this push:
     new af899d7b rr lb优化:在第一次初始化时offset使用随机数,以适配每次都是在新线程使用的场景 (#2289)
af899d7b is described below

commit af899d7b7e985886f5ac3fb71077c664e88e7da0
Author: dongpo <[email protected]>
AuthorDate: Mon Jul 10 13:06:03 2023 +0800

    rr lb优化:在第一次初始化时offset使用随机数,以适配每次都是在新线程使用的场景 (#2289)
---
 src/brpc/policy/round_robin_load_balancer.cpp | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/brpc/policy/round_robin_load_balancer.cpp 
b/src/brpc/policy/round_robin_load_balancer.cpp
index ee7fa53c..c7dd972d 100644
--- a/src/brpc/policy/round_robin_load_balancer.cpp
+++ b/src/brpc/policy/round_robin_load_balancer.cpp
@@ -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) {


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to