wwbmmm commented on code in PR #2027:
URL: https://github.com/apache/incubator-brpc/pull/2027#discussion_r1037923288


##########
src/brpc/policy/timeout_concurrency_limiter.cpp:
##########
@@ -0,0 +1,161 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include "brpc/policy/timeout_concurrency_limiter.h"
+#include "brpc/controller.h"
+#include "brpc/errno.pb.h"
+#include <cmath>
+#include <gflags/gflags.h>
+
+namespace brpc {
+namespace policy {
+
+DEFINE_int32(timeout_cl_sample_window_size_ms, 1000,
+             "Duration of the sampling window.");
+DEFINE_int32(timeout_cl_min_sample_count, 100,
+             "During the duration of the sampling window, if the number of "
+             "requests collected is less than this value, the sampling window "
+             "will be discarded.");
+DEFINE_int32(timeout_cl_max_sample_count, 200,
+             "During the duration of the sampling window, once the number of "
+             "requests collected is greater than this value, even if the "
+             "duration of the window has not ended, the max_concurrency will "
+             "be updated and a new sampling window will be started.");
+DEFINE_double(timeout_cl_sampling_interval_ms, 0.1,
+              "Interval for sampling request in auto concurrency limiter");
+DEFINE_int32(timeout_cl_initial_avg_latency_us, 500,
+             "Initial max concurrency for gradient concurrency limiter");
+DEFINE_bool(
+    timeout_cl_enable_error_punish, true,
+    "Whether to consider failed requests when calculating maximum 
concurrency");
+DEFINE_double(
+    timeout_cl_fail_punish_ratio, 1.0,
+    "Use the failed requests to punish normal requests. The larger "
+    "the configuration item, the more aggressive the penalty strategy.");
+DEFINE_int32(timeout_cl_default_timeout_ms, 500,
+             "Default timeout for rpc request");
+
+TimeoutConcurrencyLimiter::TimeoutConcurrencyLimiter()
+    : _avg_latency_us(FLAGS_timeout_cl_initial_avg_latency_us),
+      _last_sampling_time_us(0) {}
+
+TimeoutConcurrencyLimiter *TimeoutConcurrencyLimiter::New(
+    const AdaptiveMaxConcurrency &) const {
+    return new (std::nothrow) TimeoutConcurrencyLimiter;
+}
+
+bool TimeoutConcurrencyLimiter::OnRequested(int current_concurrency,
+                                            Controller *cntl) {
+    auto timeout_ms = FLAGS_timeout_cl_default_timeout_ms;
+    if (cntl != nullptr && cntl->timeout_ms() != UNSET_MAGIC_NUM) {
+        timeout_ms = cntl->timeout_ms();

Review Comment:
   哦,如果是不同method分别统计avg_latency的话,那这里用请求级别timeout是有意义的。



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to