blob: 25208e57c10f110c5bfb9dc30038f34d87ca39f4 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
--- contrib/libs/grpc/src/cpp/common/completion_queue_cc.cc (index)
+++ contrib/libs/grpc/src/cpp/common/completion_queue_cc.cc (working tree)
@@ -31,10 +31,23 @@
#include "src/core/lib/gpr/useful.h"
#include "src/core/lib/gprpp/sync.h"
#include "src/core/lib/gprpp/thd.h"
+#include "src/core/lib/gprpp/env.h"
+#include "src/core/lib/gpr/string.h"
namespace grpc {
namespace {
+size_t GetNextingThreadNumFromEnv() {
+ auto value = grpc_core::GetEnv("GRPC_NEXTING_THREAD_NUM_ENV");
+ if (!value.has_value()) return 0;
+ int parse_succeeded = gpr_parse_nonnegative_int(value->c_str());
+
+ if (parse_succeeded <= 0) {
+ return 0;
+ }
+ return static_cast<size_t>(parse_succeeded);
+}
+
gpr_once g_once_init_callback_alternative = GPR_ONCE_INIT;
grpc_core::Mutex* g_callback_alternative_mu;
@@ -55,6 +68,13 @@ struct CallbackAlternativeCQ {
cq = new CompletionQueue;
int num_nexting_threads =
grpc_core::Clamp(gpr_cpu_num_cores() / 2, 2u, 16u);
+
+ auto threads_limit_env = GetNextingThreadNumFromEnv();
+ if (threads_limit_env) {
+ gpr_log(GPR_INFO, "Nexting thread number changed via env from %d to %zd", num_nexting_threads, threads_limit_env);
+ num_nexting_threads = static_cast<int>(threads_limit_env);
+ }
+
nexting_threads = new std::vector<grpc_core::Thread>;
for (int i = 0; i < num_nexting_threads; i++) {
nexting_threads->emplace_back(
|