Skip to content

Commit 4b06efd

Browse files
authored
test(storage): control gRPC background thread count (#9570)
1 parent f8d1216 commit 4b06efd

4 files changed

Lines changed: 35 additions & 1 deletion

File tree

google/cloud/storage/benchmarks/storage_throughput_vs_cpu_benchmark.cc

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,13 @@ int main(int argc, char* argv[]) {
219219

220220
std::cout << "\n# Api Version Path: "
221221
<< options->target_api_version_path.value_or("[default]")
222-
<< "\n# Build info: " << notes << "\n";
222+
<< "\n# Grpc Background Threads: ";
223+
if (options->grpc_background_threads.has_value()) {
224+
std::cout << *options->grpc_background_threads;
225+
} else {
226+
std::cout << "[default]";
227+
}
228+
std::cout << "\n# Build info: " << notes << "\n";
223229
// Make the output generated so far immediately visible, helps with debugging.
224230
std::cout << std::flush;
225231

@@ -297,6 +303,10 @@ gcs_bm::ClientProvider BaseProvider(ThroughputOptions const& options) {
297303
}
298304
#if GOOGLE_CLOUD_CPP_STORAGE_HAVE_GRPC
299305
using ::google::cloud::storage_experimental::DefaultGrpcClient;
306+
if (options.grpc_background_threads.has_value()) {
307+
opts.set<google::cloud::GrpcBackgroundThreadPoolSizeOption>(
308+
*options.grpc_background_threads);
309+
}
300310
if (t == ExperimentTransport::kDirectPath) {
301311
if (options.direct_path_channel_count > 0) {
302312
opts.set<google::cloud::GrpcNumChannelsOption>(

google/cloud/storage/benchmarks/throughput_options.cc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,11 @@ google::cloud::StatusOr<ThroughputOptions> ParseThroughputOptions(
251251
[&options](std::string const& val) {
252252
options.target_api_version_path = val;
253253
}},
254+
{"--grpc-background-threads",
255+
"change the default number of gRPC background threads",
256+
[&options](std::string const& val) {
257+
options.grpc_background_threads = std::stoi(val);
258+
}},
254259
};
255260
auto usage = BuildUsage(desc, argv[0]);
256261

@@ -379,6 +384,12 @@ google::cloud::StatusOr<ThroughputOptions> ParseThroughputOptions(
379384
options.read_size_quantum);
380385
if (!status.ok()) return status;
381386

387+
if (options.grpc_background_threads.value_or(1) <= 0) {
388+
std::ostringstream os;
389+
os << "Invalid value for --grpc-background-threads";
390+
return make_status(os);
391+
}
392+
382393
return options;
383394
}
384395

google/cloud/storage/benchmarks/throughput_options.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ struct ThroughputOptions {
6969
std::int64_t maximum_read_size = 0;
7070
std::int64_t read_size_quantum = 128 * kKiB;
7171
absl::optional<std::string> target_api_version_path;
72+
absl::optional<int> grpc_background_threads;
7273
};
7374

7475
google::cloud::StatusOr<ThroughputOptions> ParseThroughputOptions(

google/cloud/storage/benchmarks/throughput_options_test.cc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ TEST(ThroughputOptions, Basic) {
6464
"--maximum-read-size=64KiB",
6565
"--read-size-quantum=16KiB",
6666
"--target-api-version-path=vN",
67+
"--grpc-background-threads=16",
6768
});
6869
ASSERT_STATUS_OK(options);
6970
EXPECT_EQ("test-project", options->project_id);
@@ -99,6 +100,7 @@ TEST(ThroughputOptions, Basic) {
99100
EXPECT_EQ(std::chrono::seconds(86401), options->download_stall_timeout);
100101
EXPECT_EQ(std::chrono::milliseconds(250), options->minimum_sample_delay);
101102
EXPECT_EQ("vN", options->target_api_version_path.value_or(""));
103+
EXPECT_EQ(16, options->grpc_background_threads.value_or(0));
102104
}
103105

104106
TEST(ThroughputOptions, Description) {
@@ -291,6 +293,16 @@ TEST(ThroughputOptions, Validate) {
291293
"--maximum-read-size=8",
292294
"--read-size-quantum=5",
293295
}));
296+
EXPECT_FALSE(ParseThroughputOptions({
297+
"self-test",
298+
"--region=r",
299+
"--grpc-background-threads=0",
300+
}));
301+
EXPECT_FALSE(ParseThroughputOptions({
302+
"self-test",
303+
"--region=r",
304+
"--grpc-background-threads=-1",
305+
}));
294306
}
295307

296308
} // namespace

0 commit comments

Comments
 (0)