29-set-nexting-thread-num-via-env.patch 1.4 KB

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