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
5d440eb9
Commit
5d440eb9
authored
Oct 23, 2018
by
TousakaRin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Change isolated_times to atomic variable
parent
aaf20ce8
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
8 deletions
+11
-8
circuit_breaker.cpp
src/brpc/circuit_breaker.cpp
+7
-4
circuit_breaker.h
src/brpc/circuit_breaker.h
+4
-4
No files found.
src/brpc/circuit_breaker.cpp
View file @
5d440eb9
...
...
@@ -184,7 +184,7 @@ void CircuitBreaker::Reset() {
void
CircuitBreaker
::
MarkAsBroken
()
{
if
(
_broken
.
exchange
(
true
,
butil
::
memory_order_acquire
))
{
++
_isolated_times
;
_isolated_times
.
fetch_add
(
butil
::
memory_order_relaxed
)
;
UpdateIsolationDuration
();
}
}
...
...
@@ -194,17 +194,20 @@ int CircuitBreaker::health_score() const {
}
void
CircuitBreaker
::
UpdateIsolationDuration
()
{
int
isolation_duration_ms
=
_isolation_duration_ms
.
load
(
butil
::
memory_order_relaxed
);
int64_t
now_time_ms
=
butil
::
cpuwide_time_ms
();
const
int
max_isolation_duration_ms
=
FLAGS_circuit_breaker_max_isolation_duration_ms
;
const
int
min_isolation_duration_ms
=
FLAGS_circuit_breaker_min_isolation_duration_ms
;
if
(
now_time_ms
-
_last_reset_time_ms
<
max_isolation_duration_ms
)
{
_
isolation_duration_ms
=
std
::
min
(
_
isolation_duration_ms
*
2
,
max_isolation_duration_ms
);
isolation_duration_ms
=
std
::
min
(
isolation_duration_ms
*
2
,
max_isolation_duration_ms
);
}
else
{
_
isolation_duration_ms
=
min_isolation_duration_ms
;
isolation_duration_ms
=
min_isolation_duration_ms
;
}
_isolation_duration_ms
.
store
(
isolation_duration_ms
,
butil
::
memory_order_relaxed
);
}
}
// namespace brpc
src/brpc/circuit_breaker.h
View file @
5d440eb9
...
...
@@ -52,13 +52,13 @@ public:
// Number of times marked as broken
int
isolated_times
()
const
{
return
_isolated_times
;
return
_isolated_times
.
load
(
butil
::
memory_order_relaxed
)
;
}
// The duration that should be isolated when the socket fails in milliseconds.
// The higher the frequency of socket errors, the longer the duration.
int
isolation_duration_ms
()
const
{
return
_isolation_duration_ms
;
return
_isolation_duration_ms
.
load
(
butil
::
memory_order_relaxed
)
;
}
private
:
...
...
@@ -89,8 +89,8 @@ private:
EmaErrorRecorder
_long_window
;
EmaErrorRecorder
_short_window
;
int64_t
_last_reset_time_ms
;
int
_isolation_duration_ms
;
int
_isolated_times
;
butil
::
atomic
<
int
>
_isolation_duration_ms
;
butil
::
atomic
<
int
>
_isolated_times
;
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