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
74929cfc
Commit
74929cfc
authored
Oct 19, 2018
by
TousakaRin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Modify the naming, move health_score and isolated_times to DebugSocket
parent
fa91ba42
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
23 additions
and
48 deletions
+23
-48
connections_service.cpp
src/brpc/builtin/connections_service.cpp
+4
-11
circuit_breaker.cpp
src/brpc/circuit_breaker.cpp
+5
-6
circuit_breaker.h
src/brpc/circuit_breaker.h
+5
-5
socket.cpp
src/brpc/socket.cpp
+8
-21
socket.h
src/brpc/socket.h
+1
-5
No files found.
src/brpc/builtin/connections_service.cpp
View file @
74929cfc
...
...
@@ -122,9 +122,7 @@ void ConnectionsService::PrintConnections(
os
<<
"<th>SSL</th>"
"<th>Protocol</th>"
"<th>fd</th>"
"<th>error_count</th>"
"<th>health_index</th>"
"<th>broken_times</th>"
"<th>acc_errors</th>"
"<th>InBytes/s</th>"
"<th>In/s</th>"
"<th>InBytes/m</th>"
...
...
@@ -141,8 +139,7 @@ void ConnectionsService::PrintConnections(
if
(
need_local
)
{
os
<<
"Local|"
;
}
os
<<
"SSL|Protocol |fd |"
"error_count|health_index|broken_times|"
os
<<
"SSL|Protocol |fd |acc_errors|"
"InBytes/s|In/s |InBytes/m |In/m |"
"OutBytes/s|Out/s |OutBytes/m|Out/m |"
"Rtt/Var(ms)|SocketId
\n
"
;
...
...
@@ -181,9 +178,7 @@ void ConnectionsService::PrintConnections(
os
<<
min_width
(
"-"
,
3
)
<<
bar
<<
min_width
(
"-"
,
12
)
<<
bar
<<
min_width
(
"-"
,
5
)
<<
bar
<<
min_width
(
ptr
->
error_count
(),
11
)
<<
bar
<<
min_width
(
"0"
,
12
)
<<
bar
<<
min_width
(
ptr
->
broken_times
(),
12
)
<<
bar
<<
min_width
(
ptr
->
acc_errors
(),
10
)
<<
bar
<<
min_width
(
"-"
,
9
)
<<
bar
<<
min_width
(
"-"
,
6
)
<<
bar
<<
min_width
(
"-"
,
10
)
<<
bar
...
...
@@ -295,9 +290,7 @@ void ConnectionsService::PrintConnections(
}
else
{
os
<<
min_width
(
"-"
,
5
)
<<
bar
;
}
os
<<
min_width
(
ptr
->
error_count
(),
11
)
<<
bar
<<
min_width
(
ptr
->
health_index_in_percent
(),
12
)
<<
bar
<<
min_width
(
ptr
->
broken_times
(),
12
)
<<
bar
os
<<
min_width
(
ptr
->
acc_errors
(),
10
)
<<
bar
<<
min_width
(
stat
.
in_size_s
,
9
)
<<
bar
<<
min_width
(
stat
.
in_num_messages_s
,
6
)
<<
bar
<<
min_width
(
stat
.
in_size_m
,
10
)
<<
bar
...
...
src/brpc/circuit_breaker.cpp
View file @
74929cfc
...
...
@@ -94,7 +94,7 @@ int64_t CircuitBreaker::EmaErrorRecorder::max_error_cost() const {
return
ema_latency
*
_window_size
*
(
_max_error_percent
/
100.0
)
*
(
1.0
+
EPSILON
);
}
int
CircuitBreaker
::
EmaErrorRecorder
::
health_
index_in_percent
()
const
{
int
CircuitBreaker
::
EmaErrorRecorder
::
health_
score
()
const
{
const
int64_t
current_error_cost
=
_ema_error_cost
.
load
(
butil
::
memory_order_relaxed
);
const
int64_t
error_cost_threshold
=
max_error_cost
();
if
(
error_cost_threshold
==
0
)
{
...
...
@@ -160,7 +160,7 @@ CircuitBreaker::CircuitBreaker()
FLAGS_circuit_breaker_short_window_error_percent
)
,
_last_reset_time_ms
(
butil
::
cpuwide_time_ms
())
,
_isolation_duration_ms
(
FLAGS_circuit_breaker_min_isolation_duration_ms
)
,
_
broken
_times
(
0
)
{
,
_
isolated
_times
(
0
)
{
}
bool
CircuitBreaker
::
OnCallEnd
(
int
error_code
,
int64_t
latency
)
{
...
...
@@ -175,13 +175,12 @@ void CircuitBreaker::Reset() {
}
void
CircuitBreaker
::
MarkAsBroken
()
{
++
_
broken
_times
;
++
_
isolated
_times
;
UpdateIsolationDuration
();
}
int
CircuitBreaker
::
health_index_in_percent
()
const
{
return
std
::
min
(
_long_window
.
health_index_in_percent
(),
_short_window
.
health_index_in_percent
());
int
CircuitBreaker
::
health_score
()
const
{
return
std
::
min
(
_long_window
.
health_score
(),
_short_window
.
health_score
());
}
void
CircuitBreaker
::
UpdateIsolationDuration
()
{
...
...
src/brpc/circuit_breaker.h
View file @
74929cfc
...
...
@@ -44,11 +44,11 @@ public:
// The closer to 100, the less recent errors occurred, and 0 means that
// it should be isolated.
int
health_
index_in_percent
()
const
;
int
health_
score
()
const
;
// Number of times marked as broken
int
broken
_times
()
const
{
return
_
broken
_times
;
int
isolated
_times
()
const
{
return
_
isolated
_times
;
}
// The duration that should be isolated when the socket fails in milliseconds.
...
...
@@ -67,7 +67,7 @@ private:
void
Reset
();
int64_t
max_error_cost
()
const
;
int
health_
index_in_percent
()
const
;
int
health_
score
()
const
;
private
:
int64_t
UpdateLatency
(
int64_t
latency
);
...
...
@@ -86,7 +86,7 @@ private:
EmaErrorRecorder
_short_window
;
int64_t
_last_reset_time_ms
;
int
_isolation_duration_ms
;
int
_
broken
_times
;
int
_
isolated
_times
;
};
}
// namespace brpc
...
...
src/brpc/socket.cpp
View file @
74929cfc
...
...
@@ -178,7 +178,7 @@ public:
CircuitBreaker
circuit_breaker
;
butil
::
atomic
<
uint64_t
>
error_count
;
butil
::
atomic
<
uint64_t
>
acc_errors
;
explicit
SharedPart
(
SocketId
creator_socket_id
);
~
SharedPart
();
...
...
@@ -196,7 +196,7 @@ Socket::SharedPart::SharedPart(SocketId creator_socket_id2)
,
out_size
(
0
)
,
out_num_messages
(
0
)
,
extended_stat
(
NULL
)
,
error_count
(
0
)
{
,
acc_errors
(
0
)
{
}
Socket
::
SharedPart
::~
SharedPart
()
{
...
...
@@ -806,33 +806,17 @@ int Socket::ReleaseAdditionalReference() {
}
void
Socket
::
AddErrorCount
()
{
GetOrNewSharedPart
()
->
error_count
.
fetch_add
(
1
,
butil
::
memory_order_relaxed
);
GetOrNewSharedPart
()
->
acc_errors
.
fetch_add
(
1
,
butil
::
memory_order_relaxed
);
}
int
Socket
::
broken_time
s
()
const
{
uint64_t
Socket
::
acc_error
s
()
const
{
SharedPart
*
sp
=
GetSharedPart
();
if
(
sp
)
{
return
sp
->
circuit_breaker
.
broken_times
(
);
return
sp
->
acc_errors
.
load
(
butil
::
memory_order_relaxed
);
}
return
0
;
}
uint64_t
Socket
::
error_count
()
const
{
SharedPart
*
sp
=
GetSharedPart
();
if
(
sp
)
{
return
sp
->
error_count
.
load
(
butil
::
memory_order_relaxed
);
}
return
0
;
}
int
Socket
::
health_index_in_percent
()
const
{
SharedPart
*
sp
=
GetSharedPart
();
if
(
sp
)
{
return
sp
->
circuit_breaker
.
health_index_in_percent
();
}
return
100
;
}
int
Socket
::
SetFailed
(
int
error_code
,
const
char
*
error_fmt
,
...)
{
if
(
error_code
==
0
)
{
CHECK
(
false
)
<<
"error_code is 0"
;
...
...
@@ -2151,6 +2135,9 @@ void Socket::DebugSocket(std::ostream& os, SocketId id) {
<<
"
\n
in_num_messages="
<<
sp
->
in_num_messages
.
load
(
butil
::
memory_order_relaxed
)
<<
"
\n
out_size="
<<
sp
->
out_size
.
load
(
butil
::
memory_order_relaxed
)
<<
"
\n
out_num_messages="
<<
sp
->
out_num_messages
.
load
(
butil
::
memory_order_relaxed
)
<<
"
\n
health_score="
<<
sp
->
circuit_breaker
.
health_score
()
<<
"
\n
isolated_times="
<<
sp
->
circuit_breaker
.
isolated_times
()
<<
"
\n
acc_errors="
<<
sp
->
acc_errors
.
load
(
butil
::
memory_order_relaxed
)
<<
"
\n
}"
;
}
const
int
fd
=
ptr
->
_fd
.
load
(
butil
::
memory_order_relaxed
);
...
...
src/brpc/socket.h
View file @
74929cfc
...
...
@@ -319,11 +319,7 @@ public:
void
AddErrorCount
();
uint64_t
error_count
()
const
;
int
broken_times
()
const
;
int
health_index_in_percent
()
const
;
uint64_t
acc_errors
()
const
;
void
FeedbackCircuitBreaker
(
int
error_code
,
int64_t
latency_us
);
...
...
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