Commit fdc19fe2 authored by root's avatar root

modification for GetBestServer

parent 87360ee3
...@@ -154,39 +154,26 @@ int64_t WeightedRoundRobinLoadBalancer::GetBestServer( ...@@ -154,39 +154,26 @@ int64_t WeightedRoundRobinLoadBalancer::GetBestServer(
TLS& tls) { 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; int stride = tls.stride;
int weight = 0;
while (stride > 0) { while (stride > 0) {
if (tls.HasRemainServer()) { if (tls.HasRemainServer()) {
uint32_t remain_weight = tls.remain_server.second; weight = tls.remain_server.second;
if (remain_weight < stride) { if (weight <= stride) {
TryToGetFinalServer(tls, tls.remain_server, TryToGetFinalServer(tls, tls.remain_server,
comp_weight, &final_server); comp_weight, &final_server);
tls.ResetRemainServer(); tls.ResetRemainServer();
stride -= remain_weight;
} else if (remain_weight == stride) {
TryToGetFinalServer(tls, tls.remain_server,
comp_weight, &final_server);
tls.ResetRemainServer();
break;
} else { } else {
TryToGetFinalServer(tls, TryToGetFinalServer(tls,
std::pair<SocketId, int>(tls.remain_server.first, stride), std::pair<SocketId, int>(tls.remain_server.first, stride),
comp_weight, &final_server); comp_weight, &final_server);
tls.remain_server.second -= stride; tls.remain_server.second -= stride;
break;
} }
} else { } else {
uint32_t weight = server_list[tls.position].second; weight = server_list[tls.position].second;
if (weight < stride) { if (weight <= stride) {
TryToGetFinalServer(tls, server_list[tls.position],
comp_weight, &final_server);
stride -= weight;
tls.UpdatePosition(server_list.size());
} else if (weight == stride) {
TryToGetFinalServer(tls, server_list[tls.position], TryToGetFinalServer(tls, server_list[tls.position],
comp_weight, &final_server); comp_weight, &final_server);
tls.UpdatePosition(server_list.size());
break;
} else { } else {
TryToGetFinalServer(tls, TryToGetFinalServer(tls,
std::pair<SocketId, int>( std::pair<SocketId, int>(
...@@ -194,10 +181,10 @@ int64_t WeightedRoundRobinLoadBalancer::GetBestServer( ...@@ -194,10 +181,10 @@ int64_t WeightedRoundRobinLoadBalancer::GetBestServer(
comp_weight, &final_server); comp_weight, &final_server);
tls.SetRemainServer(server_list[tls.position].first, tls.SetRemainServer(server_list[tls.position].first,
weight - stride); weight - stride);
tls.UpdatePosition(server_list.size());
break;
} }
tls.UpdatePosition(server_list.size());
} }
stride -= weight;
} }
return final_server; return final_server;
} }
......
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