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
379caa1f
Commit
379caa1f
authored
Aug 14, 2018
by
TousakaRin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix bug: units are not unified, causing window calculation errors, fix code style
parent
362c5d02
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
12 deletions
+16
-12
auto_concurrency_limiter.cpp
src/brpc/policy/auto_concurrency_limiter.cpp
+16
-12
No files found.
src/brpc/policy/auto_concurrency_limiter.cpp
View file @
379caa1f
...
...
@@ -108,13 +108,12 @@ void AutoConcurrencyLimiter::OnResponded(int error_code, int64_t latency_us) {
if
(
last_sampling_time_us
==
0
||
now_time_us
-
last_sampling_time_us
>=
FLAGS_auto_cl_sampling_interval_ms
*
1000
)
{
bool
sample_this_call
=
_last_sampling_time_us
.
compare_exchange_weak
(
last_sampling_time_us
,
now_time_us
,
butil
::
memory_order_relaxed
);
bool
sample_this_call
=
_last_sampling_time_us
.
compare_exchange_strong
(
last_sampling_time_us
,
now_time_us
,
butil
::
memory_order_relaxed
);
if
(
sample_this_call
)
{
int32_t
max_concurrency
=
AddSample
(
error_code
,
latency_us
,
now_time_us
);
if
(
max_concurrency
!=
0
)
{
LOG
(
INFO
)
LOG
_EVERY_N
(
INFO
,
100
)
<<
"MaxConcurrency updated by auto limiter,"
<<
"current_max_concurrency:"
<<
max_concurrency
;
}
...
...
@@ -125,20 +124,19 @@ void AutoConcurrencyLimiter::OnResponded(int error_code, int64_t latency_us) {
int64_t
AutoConcurrencyLimiter
::
NextResetTime
(
int64_t
sampling_time_us
)
{
int64_t
reset_start_us
=
sampling_time_us
+
(
FLAGS_auto_cl_noload_latency_remeasure_interval_ms
/
2
+
butil
::
fast_rand_less_than
(
FLAGS_auto_cl_noload_latency_remeasure_interval_ms
/
2
))
*
1000
;
butil
::
fast_rand_less_than
(
FLAGS_auto_cl_noload_latency_remeasure_interval_ms
/
2
))
*
1000
;
return
reset_start_us
;
}
int32_t
AutoConcurrencyLimiter
::
AddSample
(
int
error_code
,
int64_t
latency_us
,
int64_t
sampling_time_us
)
{
int64_t
latency_us
,
int64_t
sampling_time_us
)
{
std
::
unique_lock
<
butil
::
Mutex
>
lock_guard
(
_sw_mutex
);
if
(
_sw
.
start_time_us
==
0
)
{
_sw
.
start_time_us
=
sampling_time_us
;
}
if
(
error_code
!=
0
&&
FLAGS_auto_cl_enable_error_punish
)
{
if
(
error_code
!=
0
&&
FLAGS_auto_cl_enable_error_punish
)
{
++
_sw
.
failed_count
;
_sw
.
total_failed_us
+=
latency_us
;
}
else
if
(
error_code
==
0
)
{
...
...
@@ -147,9 +145,16 @@ int32_t AutoConcurrencyLimiter::AddSample(int error_code,
}
if
(
_sw
.
succ_count
+
_sw
.
failed_count
<
FLAGS_auto_cl_min_sample_count
)
{
if
(
sampling_time_us
-
_sw
.
sampling_time_us
>=
FLAGS_auto_cl_sample_window_size_ms
*
1000
)
{
// If the sample size is insufficient at the end of the sampling
// window, discard the entire sampling window
ResetSampleWindow
(
sampling_time_us
);
}
return
0
;
}
if
(
sampling_time_us
-
_sw
.
start_time_us
<
FLAGS_auto_cl_sample_window_size_ms
&&
if
(
sampling_time_us
-
_sw
.
start_time_us
<
FLAGS_auto_cl_sample_window_size_ms
*
1000
&&
_sw
.
succ_count
+
_sw
.
failed_count
<
FLAGS_auto_cl_max_sample_count
)
{
return
0
;
}
...
...
@@ -221,7 +226,7 @@ int32_t AutoConcurrencyLimiter::UpdateMaxConcurrency(int64_t sampling_time_us) {
return
0
;
}
// Remeasure min_latency when concurrency has dropped to low load
if
(
_reset_latency_us
>
0
&&
_reset_latency_us
<
sampling_time_us
)
{
if
(
_reset_latency_us
>
0
&&
_reset_latency_us
<
=
sampling_time_us
)
{
_min_latency_us
=
-
1
;
_reset_latency_us
=
0
;
_remeasure_start_us
=
NextResetTime
(
sampling_time_us
);
...
...
@@ -233,7 +238,6 @@ int32_t AutoConcurrencyLimiter::UpdateMaxConcurrency(int64_t sampling_time_us) {
if
(
_remeasure_start_us
<=
sampling_time_us
)
{
_reset_latency_us
=
sampling_time_us
+
avg_latency
;
next_max_concurrency
=
_max_concurrency
/
2
;
LOG
(
INFO
)
<<
"Prepare"
<<
_max_concurrency
;
}
else
{
int32_t
noload_concurrency
=
std
::
ceil
(
_min_latency_us
*
_ema_peak_qps
/
1000000
);
...
...
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