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
83daab16
Commit
83daab16
authored
Mar 09, 2018
by
root
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
wrr ut
parent
f375e9b6
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
56 additions
and
14 deletions
+56
-14
brpc_load_balancer_unittest.cpp
test/brpc_load_balancer_unittest.cpp
+56
-14
No files found.
test/brpc_load_balancer_unittest.cpp
View file @
83daab16
...
...
@@ -10,6 +10,7 @@
#include "butil/gperftools_profiler.h"
#include "butil/time.h"
#include "butil/containers/doubly_buffered_data.h"
#include "brpc/describable.h"
#include "brpc/socket.h"
#include "butil/strings/string_number_conversions.h"
#include "brpc/policy/weighted_round_robin_load_balancer.h"
...
...
@@ -233,7 +234,7 @@ class SaveRecycle : public brpc::SocketUser {
};
TEST_F
(
LoadBalancerTest
,
update_while_selection
)
{
for
(
size_t
round
=
0
;
round
<
4
;
++
round
)
{
for
(
size_t
round
=
0
;
round
<
5
;
++
round
)
{
brpc
::
LoadBalancer
*
lb
=
NULL
;
SelectArg
sa
=
{
NULL
,
NULL
};
bool
is_lalb
=
false
;
...
...
@@ -244,6 +245,8 @@ TEST_F(LoadBalancerTest, update_while_selection) {
}
else
if
(
round
==
2
)
{
lb
=
new
LALB
;
is_lalb
=
true
;
}
else
if
(
round
==
3
)
{
lb
=
new
brpc
::
policy
::
WeightedRoundRobinLoadBalancer
;
}
else
{
lb
=
new
brpc
::
policy
::
ConsistentHashingLoadBalancer
(
::
brpc
::
policy
::
MurmurHash32
);
...
...
@@ -267,6 +270,9 @@ TEST_F(LoadBalancerTest, update_while_selection) {
butil
::
EndPoint
dummy
;
ASSERT_EQ
(
0
,
str2endpoint
(
addr
,
&
dummy
));
brpc
::
ServerId
id
(
8888
);
if
(
3
==
round
)
{
id
.
tag
=
"1"
;
}
brpc
::
SocketOptions
options
;
options
.
remote_side
=
dummy
;
options
.
user
=
new
SaveRecycle
;
...
...
@@ -344,7 +350,7 @@ TEST_F(LoadBalancerTest, update_while_selection) {
}
TEST_F
(
LoadBalancerTest
,
fairness
)
{
for
(
size_t
round
=
0
;
round
<
4
;
++
round
)
{
for
(
size_t
round
=
0
;
round
<
6
;
++
round
)
{
brpc
::
LoadBalancer
*
lb
=
NULL
;
SelectArg
sa
=
{
NULL
,
NULL
};
if
(
round
==
0
)
{
...
...
@@ -353,6 +359,8 @@ TEST_F(LoadBalancerTest, fairness) {
lb
=
new
brpc
::
policy
::
RandomizedLoadBalancer
;
}
else
if
(
round
==
2
)
{
lb
=
new
LALB
;
}
else
if
(
3
==
round
||
4
==
round
)
{
lb
=
new
brpc
::
policy
::
WeightedRoundRobinLoadBalancer
;
}
else
{
lb
=
new
brpc
::
policy
::
ConsistentHashingLoadBalancer
(
brpc
::
policy
::
MurmurHash32
);
...
...
@@ -377,6 +385,15 @@ TEST_F(LoadBalancerTest, fairness) {
butil
::
EndPoint
dummy
;
ASSERT_EQ
(
0
,
str2endpoint
(
addr
,
&
dummy
));
brpc
::
ServerId
id
(
8888
);
if
(
3
==
round
)
{
id
.
tag
=
"100"
;
}
else
if
(
4
==
round
)
{
if
(
i
%
50
==
0
)
{
id
.
tag
=
std
::
to_string
(
i
/
50
*
100
+
butil
::
fast_rand_less_than
(
40
)
+
80
);
}
else
{
id
.
tag
=
std
::
to_string
(
butil
::
fast_rand_less_than
(
40
)
+
80
);
}
}
brpc
::
SocketOptions
options
;
options
.
remote_side
=
dummy
;
options
.
user
=
new
SaveRecycle
;
...
...
@@ -420,18 +437,43 @@ TEST_F(LoadBalancerTest, fairness) {
size_t
count_sum
=
0
;
size_t
count_squared_sum
=
0
;
std
::
cout
<<
lb_name
<<
':'
<<
'\n'
;
for
(
size_t
i
=
0
;
i
<
ids
.
size
();
++
i
)
{
s
ize_t
count
=
total_count
[
ids
[
i
].
id
]
;
ASSERT_NE
(
0ul
,
count
)
<<
"i="
<<
i
;
std
::
cout
<<
i
<<
'='
<<
count
<<
' '
;
count_sum
+=
count
;
count_squared_sum
+=
count
*
count
;
if
(
3
==
round
||
4
==
round
)
{
s
td
::
cout
<<
"configured weight: "
<<
std
::
endl
;
std
::
ostringstream
os
;
brpc
::
DescribeOptions
opt
;
lb
->
Describe
(
os
,
opt
)
;
std
::
cout
<<
os
.
str
()
<<
std
::
endl
;
}
std
::
cout
<<
'\n'
<<
": average="
<<
count_sum
/
ids
.
size
()
<<
" deviation="
<<
sqrt
(
count_squared_sum
*
ids
.
size
()
-
count_sum
*
count_sum
)
/
ids
.
size
()
<<
std
::
endl
;
if
(
round
!=
3
&&
round
!=
4
)
{
for
(
size_t
i
=
0
;
i
<
ids
.
size
();
++
i
)
{
size_t
count
=
total_count
[
ids
[
i
].
id
];
ASSERT_NE
(
0ul
,
count
)
<<
"i="
<<
i
;
std
::
cout
<<
i
<<
'='
<<
count
<<
' '
;
count_sum
+=
count
;
count_squared_sum
+=
count
*
count
;
}
std
::
cout
<<
'\n'
<<
": average="
<<
count_sum
/
ids
.
size
()
<<
" deviation="
<<
sqrt
(
count_squared_sum
*
ids
.
size
()
-
count_sum
*
count_sum
)
/
ids
.
size
()
<<
std
::
endl
;
}
else
{
// for weighted round robin load balancer
double
scaling_count_sum
=
0.0
;
double
scaling_count_squared_sum
=
0.0
;
for
(
size_t
i
=
0
;
i
<
ids
.
size
();
++
i
)
{
size_t
count
=
total_count
[
ids
[
i
].
id
];
ASSERT_NE
(
0ul
,
count
)
<<
"i="
<<
i
;
std
::
cout
<<
i
<<
'='
<<
count
<<
' '
;
double
scaling_count
=
static_cast
<
double
>
(
count
)
/
std
::
stoi
(
ids
[
i
].
tag
);
scaling_count_sum
+=
scaling_count
;
scaling_count_squared_sum
+=
scaling_count
*
scaling_count
;
}
std
::
cout
<<
'\n'
<<
": scaling average="
<<
scaling_count_sum
/
ids
.
size
()
<<
" scaling deviation="
<<
sqrt
(
scaling_count_squared_sum
*
ids
.
size
()
-
scaling_count_sum
*
scaling_count_sum
)
/
ids
.
size
()
<<
std
::
endl
;
}
for
(
size_t
i
=
0
;
i
<
ids
.
size
();
++
i
)
{
ASSERT_EQ
(
0
,
brpc
::
Socket
::
SetFailed
(
ids
[
i
].
id
));
}
...
...
@@ -530,8 +572,8 @@ TEST_F(LoadBalancerTest, weighted_round_robin) {
brpc
::
policy
::
WeightedRoundRobinLoadBalancer
wrrlb
;
// Add server to selected list. The server with invalid weight will be skipped.
for
(
int
i
=
0
;
i
<
6
;
++
i
)
{
const
char
*
addr
=
servers
[
i
];
for
(
size_t
i
=
0
;
i
<
ARRAY_SIZE
(
servers
)
;
++
i
)
{
const
char
*
addr
=
servers
[
i
];
butil
::
EndPoint
dummy
;
ASSERT_EQ
(
0
,
str2endpoint
(
addr
,
&
dummy
));
brpc
::
ServerId
id
(
8888
);
...
...
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