Skip to content

Commit

Permalink
Merge pull request #2106 from yanglimingcn/feature/timeout_concurrenc…
Browse files Browse the repository at this point in the history
…y_limiter_add_max_concurrency

make sure we can receive at least one request
  • Loading branch information
wwbmmm authored Feb 6, 2023
2 parents 7f1a8ed + 4eee48c commit 02ec31d
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 02ec31d

Please sign in to comment.