Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
B
brpc
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
brpc
Commits
fdc19fe2
Commit
fdc19fe2
authored
Mar 01, 2018
by
root
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
modification for GetBestServer
parent
87360ee3
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
21 deletions
+8
-21
weighted_round_robin_load_balancer.cpp
src/brpc/policy/weighted_round_robin_load_balancer.cpp
+8
-21
No files found.
src/brpc/policy/weighted_round_robin_load_balancer.cpp
View file @
fdc19fe2
...
@@ -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
;
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment