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
54df0863
Commit
54df0863
authored
Mar 06, 2018
by
root
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix for code review comments
parent
d4432f32
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
10 deletions
+13
-10
weighted_round_robin_load_balancer.cpp
src/brpc/policy/weighted_round_robin_load_balancer.cpp
+0
-0
weighted_round_robin_load_balancer.h
src/brpc/policy/weighted_round_robin_load_balancer.h
+13
-10
No files found.
src/brpc/policy/weighted_round_robin_load_balancer.cpp
View file @
54df0863
This diff is collapsed.
Click to expand it.
src/brpc/policy/weighted_round_robin_load_balancer.h
View file @
54df0863
...
...
@@ -39,27 +39,31 @@ public:
void
Describe
(
std
::
ostream
&
,
const
DescribeOptions
&
options
);
private
:
struct
Server
{
Server
(
SocketId
s_id
=
0
,
int
s_w
=
0
)
:
id
(
s_id
),
weight
(
s_w
)
{}
SocketId
id
;
int
weight
;
};
struct
Servers
{
// The value is configured weight for each server.
std
::
vector
<
std
::
pair
<
SocketId
,
int
>
>
server_list
;
std
::
vector
<
Server
>
server_list
;
// The value is the index of the server in "server_list".
std
::
map
<
SocketId
,
size_t
>
server_map
;
uint32_t
weight_sum
=
0
;
};
struct
TLS
{
TLS
()
:
remain_server
(
0
,
0
)
{
}
uint32_t
position
=
0
;
uint32_t
stride
=
0
;
std
::
pair
<
SocketId
,
int
>
remain_server
;
Server
remain_server
;
bool
HasRemainServer
()
const
{
return
remain_server
.
second
!=
0
;
return
remain_server
.
weight
!=
0
;
}
void
SetRemainServer
(
const
SocketId
id
,
const
int
weight
)
{
remain_server
.
first
=
id
;
remain_server
.
second
=
weight
;
remain_server
.
id
=
id
;
remain_server
.
weight
=
weight
;
}
void
ResetRemainServer
()
{
remain_server
.
second
=
0
;
remain_server
.
weight
=
0
;
}
void
UpdatePosition
(
const
uint32_t
size
)
{
++
position
;
...
...
@@ -84,9 +88,8 @@ private:
static
bool
Remove
(
Servers
&
bg
,
const
ServerId
&
id
);
static
size_t
BatchAdd
(
Servers
&
bg
,
const
std
::
vector
<
ServerId
>&
servers
);
static
size_t
BatchRemove
(
Servers
&
bg
,
const
std
::
vector
<
ServerId
>&
servers
);
static
int64_t
GetBestServer
(
const
std
::
vector
<
std
::
pair
<
SocketId
,
int
>>&
server_list
,
TLS
&
tls
);
static
int64_t
GetServerInNextStride
(
const
std
::
vector
<
Server
>&
server_list
,
TLS
&
tls
);
// Get a reasonable stride according to weights configured of servers.
static
uint32_t
GetStride
(
const
uint32_t
weight_sum
,
const
uint32_t
num
);
...
...
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