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
f042bb6c
Commit
f042bb6c
authored
Aug 30, 2018
by
TousakaRin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix typo, delete member _init_completed
parent
75f768a8
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
20 deletions
+11
-20
circuit_breaker.cpp
src/brpc/circuit_breaker.cpp
+9
-18
circuit_breaker.h
src/brpc/circuit_breaker.h
+2
-2
No files found.
src/brpc/circuit_breaker.cpp
View file @
f042bb6c
...
...
@@ -31,7 +31,7 @@ DEFINE_int32(circuit_breaker_long_window_error_percent, 3,
DEFINE_int32
(
circuit_breaker_min_error_cost_us
,
100
,
"The minimum error_cost, when the ema of error cost is less than this "
"value, it will be set to zero."
);
DEFINE_int32
(
circuit_breaker_max_failed_latency_mut
li
ple
,
2
,
DEFINE_int32
(
circuit_breaker_max_failed_latency_mut
il
ple
,
2
,
"The maximum multiple of the latency of the failed request relative to "
"the average latency of the success requests."
);
...
...
@@ -54,7 +54,6 @@ CircuitBreaker::EmaErrorRecorder::EmaErrorRecorder(int window_size,
:
_window_size
(
window_size
)
,
_max_error_percent
(
max_error_percent
)
,
_smooth
(
std
::
pow
(
EPSILON
,
1.0
/
window_size
))
,
_init_completed
(
false
)
,
_sample_count
(
0
)
,
_ema_error_cost
(
0
)
,
_ema_latency
(
0
)
...
...
@@ -77,16 +76,10 @@ bool CircuitBreaker::EmaErrorRecorder::OnCallEnd(int error_code,
healthy
=
UpdateErrorCost
(
latency
,
ema_latency
);
}
int
sample_count
=
_sample_count
.
fetch_add
(
1
,
butil
::
memory_order_relaxed
);
bool
init_completed
=
_init_completed
.
load
(
butil
::
memory_order_acquire
);
if
(
!
init_completed
&&
sample_count
>=
_window_size
)
{
_init_completed
.
store
(
true
,
butil
::
memory_order_release
);
init_completed
=
true
;
}
if
(
!
init_completed
)
{
if
(
_sample_count
.
fetch_add
(
1
,
butil
::
memory_order_relaxed
)
<
_window_size
)
{
return
true
;
}
if
(
!
healthy
)
{
_broken
.
store
(
true
,
butil
::
memory_order_relaxed
);
}
...
...
@@ -94,7 +87,6 @@ bool CircuitBreaker::EmaErrorRecorder::OnCallEnd(int error_code,
}
void
CircuitBreaker
::
EmaErrorRecorder
::
Reset
()
{
_init_completed
.
store
(
false
,
butil
::
memory_order_relaxed
);
_sample_count
.
store
(
0
,
butil
::
memory_order_relaxed
);
_ema_error_cost
.
store
(
0
,
butil
::
memory_order_relaxed
);
_ema_latency
.
store
(
0
,
butil
::
memory_order_relaxed
);
...
...
@@ -102,8 +94,8 @@ void CircuitBreaker::EmaErrorRecorder::Reset() {
}
int64_t
CircuitBreaker
::
EmaErrorRecorder
::
UpdateLatency
(
int64_t
latency
)
{
while
(
true
)
{
int64_t
ema_latency
=
_ema_latency
.
load
(
butil
::
memory_order_relaxed
);
do
{
int64_t
next_ema_latency
=
0
;
if
(
0
==
ema_latency
)
{
next_ema_latency
=
latency
;
...
...
@@ -113,12 +105,12 @@ int64_t CircuitBreaker::EmaErrorRecorder::UpdateLatency(int64_t latency) {
if
(
_ema_latency
.
compare_exchange_weak
(
ema_latency
,
next_ema_latency
))
{
return
next_ema_latency
;
}
}
}
while
(
true
);
}
bool
CircuitBreaker
::
EmaErrorRecorder
::
UpdateErrorCost
(
int64_t
error_cost
,
int64_t
ema_latency
)
{
const
int
max_mutilple
=
FLAGS_circuit_breaker_max_failed_latency_mut
li
ple
;
const
int
max_mutilple
=
FLAGS_circuit_breaker_max_failed_latency_mut
il
ple
;
error_cost
=
std
::
min
(
ema_latency
*
max_mutilple
,
error_cost
);
//Errorous response
if
(
error_cost
!=
0
)
{
...
...
@@ -131,9 +123,8 @@ bool CircuitBreaker::EmaErrorRecorder::UpdateErrorCost(int64_t error_cost,
}
//Ordinary response
while
(
true
)
{
int64_t
ema_error_cost
=
_ema_error_cost
.
load
(
butil
::
memory_order_relaxed
);
int64_t
ema_error_cost
=
_ema_error_cost
.
load
(
butil
::
memory_order_relaxed
);
do
{
if
(
ema_error_cost
==
0
)
{
break
;
}
else
if
(
ema_error_cost
<
FLAGS_circuit_breaker_min_error_cost_us
)
{
...
...
@@ -148,7 +139,7 @@ bool CircuitBreaker::EmaErrorRecorder::UpdateErrorCost(int64_t error_cost,
break
;
}
}
}
}
while
(
true
);
return
true
;
}
...
...
src/brpc/circuit_breaker.h
View file @
f042bb6c
...
...
@@ -54,8 +54,8 @@ private:
const
int
_window_size
;
const
int
_max_error_percent
;
const
double
_smooth
;
butil
::
atomic
<
bool
>
_init_completed
;
butil
::
atomic
<
int
>
_sample_count
;
butil
::
atomic
<
int
64_t
>
BAIDU_CACHELINE_ALIGNMENT
_sample_count
;
butil
::
atomic
<
int64_t
>
_ema_error_cost
;
butil
::
atomic
<
int64_t
>
_ema_latency
;
butil
::
atomic
<
bool
>
_broken
;
...
...
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