aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorzhuravsky-max <zhuravsky-max@yandex-team.com>2024-04-12 13:58:33 +0300
committerzhuravsky-max <zhuravsky-max@yandex-team.com>2024-04-12 14:25:02 +0300
commitf34afc9271d1a64cc057402be5aacc49b995ab0f (patch)
tree65a802ca3694d0bf30c4fcb7335be359bd852136
parent0cf62e63269c57775e2990bcc45f6e00e984c3ec (diff)
downloadydb-f34afc9271d1a64cc057402be5aacc49b995ab0f.tar.gz
Возможность управления пулом nexting thread в gRPC
Добавил возможность управлять количеством потоков в пуле `nexting_thread` в gRPC библиотеке. Судя по коду количество потоков в пуле в этом месте выбирается, исходя из количества ядер, доступных на машине. Для некоторых сценариев использования это избыточно. 159df251a530632c3c611ce85ff87f63907d917a
-rw-r--r--contrib/libs/grpc/src/cpp/common/completion_queue_cc.cc20
1 files changed, 20 insertions, 0 deletions
diff --git a/contrib/libs/grpc/src/cpp/common/completion_queue_cc.cc b/contrib/libs/grpc/src/cpp/common/completion_queue_cc.cc
index abb20e245d..154e3471b8 100644
--- a/contrib/libs/grpc/src/cpp/common/completion_queue_cc.cc
+++ b/contrib/libs/grpc/src/cpp/common/completion_queue_cc.cc
@@ -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(