Commit 87360ee3 authored by cdjin's avatar cdjin

wrr algorithm enhancement

parent d894cba7
...@@ -139,7 +139,7 @@ int WeightedRoundRobinLoadBalancer::SelectServer(const SelectIn& in, SelectOut* ...@@ -139,7 +139,7 @@ int WeightedRoundRobinLoadBalancer::SelectServer(const SelectIn& in, SelectOut*
tls.ResetRemainServer(); tls.ResetRemainServer();
} }
for ( uint32_t i = 0; i != tls.stride; ++i) { for ( uint32_t i = 0; i != tls.stride; ++i) {
int64_t best = GetBestServer(s->server_list, tls, tls.stride); int64_t best = GetBestServer(s->server_list, tls);
if (!ExcludedServers::IsExcluded(in.excluded, best) if (!ExcludedServers::IsExcluded(in.excluded, best)
&& Socket::Address(best, out->ptr) == 0 && Socket::Address(best, out->ptr) == 0
&& !(*out->ptr)->IsLogOff()) { && !(*out->ptr)->IsLogOff()) {
...@@ -150,10 +150,11 @@ int WeightedRoundRobinLoadBalancer::SelectServer(const SelectIn& in, SelectOut* ...@@ -150,10 +150,11 @@ int WeightedRoundRobinLoadBalancer::SelectServer(const SelectIn& in, SelectOut*
} }
int64_t WeightedRoundRobinLoadBalancer::GetBestServer( int64_t WeightedRoundRobinLoadBalancer::GetBestServer(
const std::vector<std::pair<SocketId, int>>& server_list, const std::vector<std::pair<SocketId, int>>& server_list,
TLS& tls, uint32_t stride) { TLS& tls) {
uint32_t comp_weight = 0; uint32_t comp_weight = 0;
int64_t final_server = -1; int64_t final_server = -1;
uint32_t stride = tls.stride;
while (stride > 0) { while (stride > 0) {
if (tls.HasRemainServer()) { if (tls.HasRemainServer()) {
uint32_t remain_weight = tls.remain_server.second; uint32_t remain_weight = tls.remain_server.second;
......
...@@ -87,7 +87,7 @@ private: ...@@ -87,7 +87,7 @@ private:
static size_t BatchRemove(Servers& bg, const std::vector<ServerId>& servers); static size_t BatchRemove(Servers& bg, const std::vector<ServerId>& servers);
static int64_t GetBestServer( static int64_t GetBestServer(
const std::vector<std::pair<SocketId, int>>& server_list, const std::vector<std::pair<SocketId, int>>& server_list,
TLS& tls, uint32_t stride); TLS& tls);
// Get a reasonable stride according to weights configured of servers. // Get a reasonable stride according to weights configured of servers.
static uint32_t GetStride(const uint32_t weight_sum, const uint32_t num); static uint32_t GetStride(const uint32_t weight_sum, const uint32_t num);
static void TryToGetFinalServer(const TLS& tls, static void TryToGetFinalServer(const TLS& tls,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment