Skip to content

Commit 72ea42a

Browse files
lcnilescopybara-github
authored andcommitted
Add a Bazel config setting to minimize thread pool size. (grpc#39633)
There is an existing config setting `GRPC_MAXIMIZE_THREADYNESS`. This change adds a similar `GRPC_MINIMIZE_THREADYNESS` and uses each to apply max thread pool size for the CFEngine. This is particularly useful for build systems where custom `-copt` flags cannot be provided to the compiler. <!-- If you know who should review your pull request, please assign it to that person, otherwise the pull request would get assigned randomly. If your pull request is for a specific language, please add the appropriate lang label. --> Closes grpc#39633 COPYBARA_INTEGRATE_REVIEW=grpc#39633 from lcniles:master 7fe748d PiperOrigin-RevId: 762521428
1 parent 04edb99 commit 72ea42a

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/core/BUILD

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ config_setting(
5454
values = {"define": "GRPC_MAXIMIZE_THREADYNESS=1"},
5555
)
5656

57+
config_setting(
58+
name = "minimize_threadyness",
59+
values = {"define": "GRPC_MINIMIZE_THREADYNESS=1"},
60+
)
61+
5762
grpc_cc_library(
5863
name = "channel_fwd",
5964
hdrs = [
@@ -2786,6 +2791,11 @@ grpc_cc_library(
27862791
"lib/event_engine/cf_engine/cftype_unique_ref.h",
27872792
"lib/event_engine/cf_engine/dns_service_resolver.h",
27882793
],
2794+
defines = select({
2795+
":maximize_threadyness": ["GRPC_CFSTREAM_MAX_THREADPOOL_SIZE=16u"],
2796+
":minimize_threadyness": ["GRPC_CFSTREAM_MAX_THREADPOOL_SIZE=2u"],
2797+
"//conditions:default": [],
2798+
}),
27892799
external_deps = [
27902800
"absl/container:flat_hash_map",
27912801
"absl/log",

src/core/lib/event_engine/cf_engine/cf_engine.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "src/core/lib/event_engine/thread_pool/thread_pool.h"
3232
#include "src/core/lib/event_engine/utils.h"
3333
#include "src/core/util/crash.h"
34+
#include "src/core/util/useful.h"
3435

3536
#ifndef GRPC_CFSTREAM_MAX_THREADPOOL_SIZE
3637
#define GRPC_CFSTREAM_MAX_THREADPOOL_SIZE 16u
@@ -58,7 +59,8 @@ struct CFEventEngine::Closure final : public EventEngine::Closure {
5859

5960
CFEventEngine::CFEventEngine()
6061
: thread_pool_(MakeThreadPool(grpc_core::Clamp(
61-
gpr_cpu_num_cores(), 2u, GRPC_CFSTREAM_MAX_THREADPOOL_SIZE))),
62+
gpr_cpu_num_cores(), 2u,
63+
static_cast<unsigned int>(GRPC_CFSTREAM_MAX_THREADPOOL_SIZE)))),
6264
timer_manager_(thread_pool_) {}
6365

6466
CFEventEngine::~CFEventEngine() {

0 commit comments

Comments
 (0)