Skip to content

Commit

Permalink
In extreme cases, the average latency may be greater than requested t…
Browse files Browse the repository at this point in the history
…imeout, allow currency_concurrency is 1 ensures the average latency can be obtained renew.
  • Loading branch information
yanglimingcn committed Feb 2, 2023
1 parent 7c6ca2b commit 4eee48c
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/brpc/policy/timeout_concurrency_limiter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,12 @@ bool TimeoutConcurrencyLimiter::OnRequested(int current_concurrency,
if (cntl != nullptr && cntl->timeout_ms() != UNSET_MAGIC_NUM) {
timeout_ms = cntl->timeout_ms();
}
return current_concurrency <= FLAGS_timeout_cl_max_concurrency &&
_avg_latency_us < timeout_ms * 1000;
// In extreme cases, the average latency may be greater than requested
// timeout, allow currency_concurrency is 1 ensures the average latency can
// be obtained renew.
return current_concurrency == 1 ||
(current_concurrency <= FLAGS_timeout_cl_max_concurrency &&
_avg_latency_us < timeout_ms * 1000);
}

void TimeoutConcurrencyLimiter::OnResponded(int error_code,
Expand Down Expand Up @@ -137,7 +141,7 @@ bool TimeoutConcurrencyLimiter::AddSample(int error_code, int64_t latency_us,
UpdateAvgLatency();
} else {
// All request failed
AdjustAvgLatency(_avg_latency_us / 2);
AdjustAvgLatency(_avg_latency_us * 2);
}
ResetSampleWindow(sampling_time_us);
return true;
Expand Down

0 comments on commit 4eee48c

Please sign in to comment.