diff options
author | Vijay Pai <vpai@google.com> | 2017-08-24 10:42:27 -0700 |
---|---|---|
committer | Vijay Pai <vpai@google.com> | 2017-10-19 14:29:13 -0700 |
commit | 088112fea12ec364990909cda3a96e7d792480b3 (patch) | |
tree | 1fde83a8b7332891ccbb409da0ac97abd3ebe68d /test | |
parent | ac581ee24b24d9088d8755ce45daa4ec471ab951 (diff) |
Create inproc version of QPS test and add a few simple tests of this to standard testing suite.
Diffstat (limited to 'test')
-rw-r--r-- | test/cpp/qps/BUILD | 12 | ||||
-rw-r--r-- | test/cpp/qps/client.h | 36 | ||||
-rw-r--r-- | test/cpp/qps/driver.cc | 48 | ||||
-rw-r--r-- | test/cpp/qps/driver.h | 2 | ||||
-rwxr-xr-x | test/cpp/qps/gen_build_yaml.py | 18 | ||||
-rw-r--r-- | test/cpp/qps/inproc_sync_unary_ping_pong_test.cc | 66 | ||||
-rw-r--r-- | test/cpp/qps/json_run_localhost.cc | 12 | ||||
-rw-r--r-- | test/cpp/qps/qps_json_driver.cc | 7 | ||||
-rw-r--r-- | test/cpp/qps/qps_openloop_test.cc | 6 | ||||
-rw-r--r-- | test/cpp/qps/qps_worker.cc | 21 | ||||
-rw-r--r-- | test/cpp/qps/qps_worker.h | 14 | ||||
-rw-r--r-- | test/cpp/qps/secure_sync_unary_ping_pong_test.cc | 6 | ||||
-rw-r--r-- | test/cpp/qps/server.h | 8 | ||||
-rw-r--r-- | test/cpp/qps/server_async.cc | 22 | ||||
-rw-r--r-- | test/cpp/qps/server_sync.cc | 20 | ||||
-rw-r--r-- | test/cpp/qps/worker.cc | 3 |
16 files changed, 243 insertions, 58 deletions
diff --git a/test/cpp/qps/BUILD b/test/cpp/qps/BUILD index 3352269517..0d91d52f22 100644 --- a/test/cpp/qps/BUILD +++ b/test/cpp/qps/BUILD @@ -109,6 +109,18 @@ grpc_cc_library( deps = ["//:gpr"], ) +grpc_cc_test( + name = "inproc_sync_unary_ping_pong_test", + srcs = ["inproc_sync_unary_ping_pong_test.cc"], + deps = [ + ":benchmark_config", + ":driver_impl", + "//:grpc++", + "//test/cpp/util:test_config", + "//test/cpp/util:test_util", + ], +) + grpc_cc_library( name = "interarrival", hdrs = ["interarrival.h"], diff --git a/test/cpp/qps/client.h b/test/cpp/qps/client.h index abf755b393..48c8995666 100644 --- a/test/cpp/qps/client.h +++ b/test/cpp/qps/client.h @@ -37,10 +37,14 @@ #include "src/cpp/util/core_stats.h" #include "test/cpp/qps/histogram.h" #include "test/cpp/qps/interarrival.h" +#include "test/cpp/qps/qps_worker.h" +#include "test/cpp/qps/server.h" #include "test/cpp/qps/usage_timer.h" #include "test/cpp/util/create_test_channel.h" #include "test/cpp/util/test_credentials_provider.h" +#define INPROC_NAME_PREFIX "qpsinproc:" + namespace grpc { namespace testing { @@ -422,11 +426,24 @@ class ClientImpl : public Client { type = config.security_params().cred_type(); } - channel_ = CreateTestChannel( - target, type, config.security_params().server_host_override(), - !config.security_params().use_test_ca(), - std::shared_ptr<CallCredentials>(), args); - gpr_log(GPR_INFO, "Connecting to %s", target.c_str()); + grpc::string inproc_pfx(INPROC_NAME_PREFIX); + if (target.find(inproc_pfx) != 0) { + channel_ = CreateTestChannel( + target, type, config.security_params().server_host_override(), + !config.security_params().use_test_ca(), + std::shared_ptr<CallCredentials>(), args); + gpr_log(GPR_INFO, "Connecting to %s", target.c_str()); + GPR_ASSERT(channel_->WaitForConnected( + gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), + gpr_time_from_seconds(300, GPR_TIMESPAN)))); + is_inproc_ = false; + } else { + grpc::string tgt = target; + tgt.erase(0, inproc_pfx.length()); + int srv_num = std::stoi(tgt); + channel_ = (*g_inproc_servers)[srv_num]->InProcessChannel(args); + is_inproc_ = true; + } stub_ = create_stub(channel_); } Channel* get_channel() { return channel_.get(); } @@ -434,9 +451,11 @@ class ClientImpl : public Client { std::unique_ptr<std::thread> WaitForReady() { return std::unique_ptr<std::thread>(new std::thread([this]() { - GPR_ASSERT(channel_->WaitForConnected( - gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), - gpr_time_from_seconds(10, GPR_TIMESPAN)))); + if (!is_inproc_) { + GPR_ASSERT(channel_->WaitForConnected( + gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), + gpr_time_from_seconds(10, GPR_TIMESPAN)))); + } })); } @@ -455,6 +474,7 @@ class ClientImpl : public Client { std::shared_ptr<Channel> channel_; std::unique_ptr<StubType> stub_; + bool is_inproc_; }; std::vector<ClientChannelInfo> channels_; std::function<std::unique_ptr<StubType>(const std::shared_ptr<Channel>&)> diff --git a/test/cpp/qps/driver.cc b/test/cpp/qps/driver.cc index 4458e389e7..5504c0b96a 100644 --- a/test/cpp/qps/driver.cc +++ b/test/cpp/qps/driver.cc @@ -36,6 +36,7 @@ #include "src/proto/grpc/testing/services.grpc.pb.h" #include "test/core/util/port.h" #include "test/core/util/test_config.h" +#include "test/cpp/qps/client.h" #include "test/cpp/qps/driver.h" #include "test/cpp/qps/histogram.h" #include "test/cpp/qps/qps_worker.h" @@ -63,11 +64,11 @@ static std::string get_host(const std::string& worker) { } static deque<string> get_workers(const string& env_name) { + deque<string> out; char* env = gpr_getenv(env_name.c_str()); if (!env) { env = gpr_strdup(""); } - deque<string> out; char* p = env; if (strlen(env) != 0) { for (;;) { @@ -187,12 +188,17 @@ static void postprocess_scenario_result(ScenarioResult* result) { client_queries_per_cpu_sec); } +std::vector<grpc::testing::Server*>* g_inproc_servers = nullptr; + std::unique_ptr<ScenarioResult> RunScenario( const ClientConfig& initial_client_config, size_t num_clients, const ServerConfig& initial_server_config, size_t num_servers, int warmup_seconds, int benchmark_seconds, int spawn_local_worker_count, const grpc::string& qps_server_target_override, - const grpc::string& credential_type) { + const grpc::string& credential_type, bool run_inproc) { + if (run_inproc) { + g_inproc_servers = new std::vector<grpc::testing::Server*>; + } // Log everything from the driver gpr_set_log_verbosity(GPR_LOG_SEVERITY_DEBUG); @@ -210,8 +216,8 @@ std::unique_ptr<ScenarioResult> RunScenario( ClientConfig result_client_config; const ServerConfig result_server_config = initial_server_config; - // Get client, server lists - auto workers = get_workers("QPS_WORKERS"); + // Get client, server lists; ignore if inproc test + auto workers = (!run_inproc) ? get_workers("QPS_WORKERS") : deque<string>(); ClientConfig client_config = initial_client_config; // Spawn some local workers if desired @@ -227,9 +233,10 @@ std::unique_ptr<ScenarioResult> RunScenario( called_init = true; } - int driver_port = grpc_pick_unused_port_or_die(); - local_workers.emplace_back(new QpsWorker(driver_port, 0, credential_type)); char addr[256]; + // we use port # of -1 to indicate inproc + int driver_port = (!run_inproc) ? grpc_pick_unused_port_or_die() : -1; + local_workers.emplace_back(new QpsWorker(driver_port, 0, credential_type)); sprintf(addr, "localhost:%d", driver_port); if (spawn_local_worker_count < 0) { workers.push_front(addr); @@ -265,9 +272,14 @@ std::unique_ptr<ScenarioResult> RunScenario( for (size_t i = 0; i < num_servers; i++) { gpr_log(GPR_INFO, "Starting server on %s (worker #%" PRIuPTR ")", workers[i].c_str(), i); - servers[i].stub = WorkerService::NewStub(CreateChannel( - workers[i], GetCredentialsProvider()->GetChannelCredentials( - credential_type, &channel_args))); + if (!run_inproc) { + servers[i].stub = WorkerService::NewStub(CreateChannel( + workers[i], GetCredentialsProvider()->GetChannelCredentials( + credential_type, &channel_args))); + } else { + servers[i].stub = WorkerService::NewStub( + local_workers[i]->InProcessChannel(channel_args)); + } ServerConfig server_config = initial_server_config; if (server_config.core_limit() != 0) { @@ -289,6 +301,10 @@ std::unique_ptr<ScenarioResult> RunScenario( // overriding the qps server target only works if there is 1 server GPR_ASSERT(num_servers == 1); client_config.add_server_targets(qps_server_target_override); + } else if (run_inproc) { + std::string cli_target(INPROC_NAME_PREFIX); + cli_target += std::to_string(i); + client_config.add_server_targets(cli_target); } else { std::string host; char* cli_target; @@ -312,9 +328,14 @@ std::unique_ptr<ScenarioResult> RunScenario( const auto& worker = workers[i + num_servers]; gpr_log(GPR_INFO, "Starting client on %s (worker #%" PRIuPTR ")", worker.c_str(), i + num_servers); - clients[i].stub = WorkerService::NewStub( - CreateChannel(worker, GetCredentialsProvider()->GetChannelCredentials( - credential_type, &channel_args))); + if (!run_inproc) { + clients[i].stub = WorkerService::NewStub( + CreateChannel(worker, GetCredentialsProvider()->GetChannelCredentials( + credential_type, &channel_args))); + } else { + clients[i].stub = WorkerService::NewStub( + local_workers[i + num_servers]->InProcessChannel(channel_args)); + } ClientConfig per_client_config = client_config; if (initial_client_config.core_limit() != 0) { @@ -495,6 +516,9 @@ std::unique_ptr<ScenarioResult> RunScenario( } } + if (g_inproc_servers != nullptr) { + delete g_inproc_servers; + } postprocess_scenario_result(result.get()); return result; } diff --git a/test/cpp/qps/driver.h b/test/cpp/qps/driver.h index 29f2776d79..fede4d8045 100644 --- a/test/cpp/qps/driver.h +++ b/test/cpp/qps/driver.h @@ -32,7 +32,7 @@ std::unique_ptr<ScenarioResult> RunScenario( const grpc::testing::ServerConfig& server_config, size_t num_servers, int warmup_seconds, int benchmark_seconds, int spawn_local_worker_count, const grpc::string& qps_server_target_override, - const grpc::string& credential_type); + const grpc::string& credential_type, bool run_inproc); bool RunQuit(const grpc::string& credential_type); } // namespace testing diff --git a/test/cpp/qps/gen_build_yaml.py b/test/cpp/qps/gen_build_yaml.py index 65553f57f1..1ef8f65b0b 100755 --- a/test/cpp/qps/gen_build_yaml.py +++ b/test/cpp/qps/gen_build_yaml.py @@ -85,6 +85,24 @@ print yaml.dump({ if 'scalable' in scenario_json.get('CATEGORIES', []) ] + [ { + 'name': 'qps_json_driver', + 'shortname': 'qps_json_driver:inproc_%s' % scenario_json['name'], + 'args': ['--run_inproc', '--scenarios_json', _scenario_json_string(scenario_json, False)], + 'ci_platforms': ['linux'], + 'platforms': ['linux'], + 'flaky': False, + 'language': 'c++', + 'boringssl': True, + 'defaults': 'boringssl', + 'cpu_cost': guess_cpu(scenario_json, False), + 'exclude_configs': ['tsan', 'asan'], + 'timeout_seconds': 6*60, + 'excluded_poll_engines': scenario_json.get('EXCLUDED_POLL_ENGINES', []) + } + for scenario_json in scenario_config.CXXLanguage().scenarios() + if 'inproc' in scenario_json.get('CATEGORIES', []) + ] + [ + { 'name': 'json_run_localhost', 'shortname': 'json_run_localhost:%s_low_thread_count' % scenario_json['name'], 'args': ['--scenarios_json', _scenario_json_string(scenario_json, True)], diff --git a/test/cpp/qps/inproc_sync_unary_ping_pong_test.cc b/test/cpp/qps/inproc_sync_unary_ping_pong_test.cc new file mode 100644 index 0000000000..f2e977d48b --- /dev/null +++ b/test/cpp/qps/inproc_sync_unary_ping_pong_test.cc @@ -0,0 +1,66 @@ +/* + * + * Copyright 2015 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include <set> + +#include <grpc/support/log.h> + +#include "test/cpp/qps/benchmark_config.h" +#include "test/cpp/qps/driver.h" +#include "test/cpp/qps/report.h" +#include "test/cpp/qps/server.h" +#include "test/cpp/util/test_config.h" +#include "test/cpp/util/test_credentials_provider.h" + +namespace grpc { +namespace testing { + +static const int WARMUP = 5; +static const int BENCHMARK = 5; + +static void RunSynchronousUnaryPingPong() { + gpr_log(GPR_INFO, "Running Synchronous Unary Ping Pong"); + + ClientConfig client_config; + client_config.set_client_type(SYNC_CLIENT); + client_config.set_outstanding_rpcs_per_channel(1); + client_config.set_client_channels(1); + client_config.set_rpc_type(UNARY); + client_config.mutable_load_params()->mutable_closed_loop(); + + ServerConfig server_config; + server_config.set_server_type(SYNC_SERVER); + + const auto result = + RunScenario(client_config, 1, server_config, 1, WARMUP, BENCHMARK, -2, "", + kInsecureCredentialsType, true); + + GetReporter()->ReportQPS(*result); + GetReporter()->ReportLatency(*result); +} + +} // namespace testing +} // namespace grpc + +int main(int argc, char** argv) { + grpc::testing::InitTest(&argc, &argv, true); + + grpc::testing::RunSynchronousUnaryPingPong(); + + return 0; +} diff --git a/test/cpp/qps/json_run_localhost.cc b/test/cpp/qps/json_run_localhost.cc index 1d394b216f..4b788eae73 100644 --- a/test/cpp/qps/json_run_localhost.cc +++ b/test/cpp/qps/json_run_localhost.cc @@ -117,8 +117,14 @@ int main(int argc, char** argv) { } } - delete g_driver; - g_driver = NULL; - for (int i = 0; i < kNumWorkers; ++i) delete g_workers[i]; + if (g_driver != nullptr) { + delete g_driver; + } + g_driver = nullptr; + for (int i = 0; i < kNumWorkers; ++i) { + if (g_workers[i] != nullptr) { + delete g_workers[i]; + } + } GPR_ASSERT(driver_join_status == 0); } diff --git a/test/cpp/qps/qps_json_driver.cc b/test/cpp/qps/qps_json_driver.cc index cca59f64d8..1672527426 100644 --- a/test/cpp/qps/qps_json_driver.cc +++ b/test/cpp/qps/qps_json_driver.cc @@ -30,6 +30,7 @@ #include "test/cpp/qps/driver.h" #include "test/cpp/qps/parse_json.h" #include "test/cpp/qps/report.h" +#include "test/cpp/qps/server.h" #include "test/cpp/util/test_config.h" #include "test/cpp/util/test_credentials_provider.h" @@ -64,6 +65,7 @@ DEFINE_string(json_file_out, "", "File to write the JSON output to."); DEFINE_string(credential_type, grpc::testing::kInsecureCredentialsType, "Credential type for communication with workers"); +DEFINE_bool(run_inproc, false, "Perform an in-process transport test"); namespace grpc { namespace testing { @@ -75,8 +77,9 @@ static std::unique_ptr<ScenarioResult> RunAndReport(const Scenario& scenario, RunScenario(scenario.client_config(), scenario.num_clients(), scenario.server_config(), scenario.num_servers(), scenario.warmup_seconds(), scenario.benchmark_seconds(), - scenario.spawn_local_worker_count(), - FLAGS_qps_server_target_override, FLAGS_credential_type); + !FLAGS_run_inproc ? scenario.spawn_local_worker_count() : -2, + FLAGS_qps_server_target_override, FLAGS_credential_type, + FLAGS_run_inproc); // Amend the result with scenario config. Eventually we should adjust // RunScenario contract so we don't need to touch the result here. diff --git a/test/cpp/qps/qps_openloop_test.cc b/test/cpp/qps/qps_openloop_test.cc index 069b3fa076..df929b9811 100644 --- a/test/cpp/qps/qps_openloop_test.cc +++ b/test/cpp/qps/qps_openloop_test.cc @@ -24,6 +24,7 @@ #include "test/cpp/qps/benchmark_config.h" #include "test/cpp/qps/driver.h" #include "test/cpp/qps/report.h" +#include "test/cpp/qps/server.h" #include "test/cpp/util/test_config.h" #include "test/cpp/util/test_credentials_provider.h" @@ -49,8 +50,9 @@ static void RunQPS() { server_config.set_server_type(ASYNC_SERVER); server_config.set_async_server_threads(8); - const auto result = RunScenario(client_config, 1, server_config, 1, WARMUP, - BENCHMARK, -2, "", kInsecureCredentialsType); + const auto result = + RunScenario(client_config, 1, server_config, 1, WARMUP, BENCHMARK, -2, "", + kInsecureCredentialsType, false); GetReporter()->ReportQPSPerCore(*result); GetReporter()->ReportLatency(*result); diff --git a/test/cpp/qps/qps_worker.cc b/test/cpp/qps/qps_worker.cc index d20bc1b074..c288b03ec5 100644 --- a/test/cpp/qps/qps_worker.cc +++ b/test/cpp/qps/qps_worker.cc @@ -225,11 +225,14 @@ class WorkerServiceImpl final : public WorkerService::Service { if (!args.has_setup()) { return Status(StatusCode::INVALID_ARGUMENT, "Bad server creation args"); } - if (server_port_ != 0) { + if (server_port_ > 0) { args.mutable_setup()->set_port(server_port_); } gpr_log(GPR_INFO, "RunServerBody: about to create server"); auto server = CreateServer(args.setup()); + if (g_inproc_servers != nullptr) { + g_inproc_servers->push_back(server.get()); + } if (!server) { return Status(StatusCode::INVALID_ARGUMENT, "Couldn't create server"); } @@ -269,17 +272,17 @@ QpsWorker::QpsWorker(int driver_port, int server_port, impl_.reset(new WorkerServiceImpl(server_port, this)); gpr_atm_rel_store(&done_, static_cast<gpr_atm>(0)); - char* server_address = NULL; - gpr_join_host_port(&server_address, "::", driver_port); - ServerBuilder builder; - builder.AddListeningPort( - server_address, - GetCredentialsProvider()->GetServerCredentials(credential_type)); + if (driver_port >= 0) { + char* server_address = nullptr; + gpr_join_host_port(&server_address, "::", driver_port); + builder.AddListeningPort( + server_address, + GetCredentialsProvider()->GetServerCredentials(credential_type)); + gpr_free(server_address); + } builder.RegisterService(impl_.get()); - gpr_free(server_address); - server_ = builder.BuildAndStart(); } diff --git a/test/cpp/qps/qps_worker.h b/test/cpp/qps/qps_worker.h index 360125fb17..a5167426d0 100644 --- a/test/cpp/qps/qps_worker.h +++ b/test/cpp/qps/qps_worker.h @@ -21,17 +21,21 @@ #include <memory> +#include <grpc++/server.h> +#include <grpc++/support/channel_arguments.h> #include <grpc++/support/config.h> #include <grpc/support/atm.h> -namespace grpc { +#include "test/cpp/qps/server.h" -class Server; +namespace grpc { namespace testing { class WorkerServiceImpl; +extern std::vector<grpc::testing::Server*>* g_inproc_servers; + class QpsWorker { public: explicit QpsWorker(int driver_port, int server_port, @@ -41,9 +45,13 @@ class QpsWorker { bool Done() const; void MarkDone(); + std::shared_ptr<Channel> InProcessChannel(const ChannelArguments& args) { + return server_->InProcessChannel(args); + } + private: std::unique_ptr<WorkerServiceImpl> impl_; - std::unique_ptr<Server> server_; + std::unique_ptr<grpc::Server> server_; gpr_atm done_; }; diff --git a/test/cpp/qps/secure_sync_unary_ping_pong_test.cc b/test/cpp/qps/secure_sync_unary_ping_pong_test.cc index 137b33ee25..bb415e9d63 100644 --- a/test/cpp/qps/secure_sync_unary_ping_pong_test.cc +++ b/test/cpp/qps/secure_sync_unary_ping_pong_test.cc @@ -23,6 +23,7 @@ #include "test/cpp/qps/benchmark_config.h" #include "test/cpp/qps/driver.h" #include "test/cpp/qps/report.h" +#include "test/cpp/qps/server.h" #include "test/cpp/util/test_config.h" #include "test/cpp/util/test_credentials_provider.h" @@ -52,8 +53,9 @@ static void RunSynchronousUnaryPingPong() { client_config.mutable_security_params()->CopyFrom(security); server_config.mutable_security_params()->CopyFrom(security); - const auto result = RunScenario(client_config, 1, server_config, 1, WARMUP, - BENCHMARK, -2, "", kInsecureCredentialsType); + const auto result = + RunScenario(client_config, 1, server_config, 1, WARMUP, BENCHMARK, -2, "", + kInsecureCredentialsType, false); GetReporter()->ReportQPS(*result); GetReporter()->ReportLatency(*result); diff --git a/test/cpp/qps/server.h b/test/cpp/qps/server.h index 16d101d5e6..9da33566dd 100644 --- a/test/cpp/qps/server.h +++ b/test/cpp/qps/server.h @@ -42,10 +42,9 @@ class Server { explicit Server(const ServerConfig& config) : timer_(new UsageTimer), last_reset_poll_count_(0) { cores_ = gpr_cpu_num_cores(); - if (config.port()) { + if (config.port()) { // positive for a fixed port, negative for inproc port_ = config.port(); - - } else { + } else { // zero for dynamic port port_ = grpc_pick_unused_port_or_die(); } } @@ -115,6 +114,9 @@ class Server { return 0; } + virtual std::shared_ptr<Channel> InProcessChannel( + const ChannelArguments& args) = 0; + protected: static void ApplyConfigToBuilder(const ServerConfig& config, ServerBuilder* builder) { diff --git a/test/cpp/qps/server_async.cc b/test/cpp/qps/server_async.cc index 4a82f98199..776371a2c6 100644 --- a/test/cpp/qps/server_async.cc +++ b/test/cpp/qps/server_async.cc @@ -74,14 +74,17 @@ class AsyncQpsServerTest final : public grpc::testing::Server { ResponseType *)> process_rpc) : Server(config) { - char *server_address = NULL; - - gpr_join_host_port(&server_address, "::", port()); - ServerBuilder builder; - builder.AddListeningPort(server_address, - Server::CreateServerCredentials(config)); - gpr_free(server_address); + + auto port_num = port(); + // Negative port number means inproc server, so no listen port needed + if (port_num >= 0) { + char *server_address = NULL; + gpr_join_host_port(&server_address, "::", port_num); + builder.AddListeningPort(server_address, + Server::CreateServerCredentials(config)); + gpr_free(server_address); + } register_service(&builder, &async_service_); @@ -183,6 +186,11 @@ class AsyncQpsServerTest final : public grpc::testing::Server { return count; } + std::shared_ptr<Channel> InProcessChannel( + const ChannelArguments &args) override { + return server_->InProcessChannel(args); + } + private: void ShutdownThreadFunc() { // TODO (vpai): Remove this deadline and allow Shutdown to finish properly diff --git a/test/cpp/qps/server_sync.cc b/test/cpp/qps/server_sync.cc index 9954e2c0bf..4ef57bd08b 100644 --- a/test/cpp/qps/server_sync.cc +++ b/test/cpp/qps/server_sync.cc @@ -156,12 +156,15 @@ class SynchronousServer final : public grpc::testing::Server { explicit SynchronousServer(const ServerConfig& config) : Server(config) { ServerBuilder builder; - char* server_address = NULL; - - gpr_join_host_port(&server_address, "::", port()); - builder.AddListeningPort(server_address, - Server::CreateServerCredentials(config)); - gpr_free(server_address); + auto port_num = port(); + // Negative port number means inproc server, so no listen port needed + if (port_num >= 0) { + char* server_address = NULL; + gpr_join_host_port(&server_address, "::", port_num); + builder.AddListeningPort(server_address, + Server::CreateServerCredentials(config)); + gpr_free(server_address); + } ApplyConfigToBuilder(config, &builder); @@ -170,6 +173,11 @@ class SynchronousServer final : public grpc::testing::Server { impl_ = builder.BuildAndStart(); } + std::shared_ptr<Channel> InProcessChannel( + const ChannelArguments& args) override { + return impl_->InProcessChannel(args); + } + private: BenchmarkServiceImpl service_; std::unique_ptr<grpc::Server> impl_; diff --git a/test/cpp/qps/worker.cc b/test/cpp/qps/worker.cc index 27010b7315..38287464d9 100644 --- a/test/cpp/qps/worker.cc +++ b/test/cpp/qps/worker.cc @@ -20,6 +20,7 @@ #include <chrono> #include <thread> +#include <vector> #include <gflags/gflags.h> #include <grpc/grpc.h> @@ -41,6 +42,8 @@ static void sigint_handler(int x) { got_sigint = true; } namespace grpc { namespace testing { +std::vector<grpc::testing::Server*>* g_inproc_servers = nullptr; + static void RunServer() { QpsWorker worker(FLAGS_driver_port, FLAGS_server_port, FLAGS_credential_type); |