Make QPS server builder customizeabled

pull/16092/head
Alex Polcyn 7 years ago
parent 2cfc216cfd
commit 92e0a70ec6
  1. 1
      CMakeLists.txt
  2. 3
      Makefile
  3. 2
      build.yaml
  4. 1
      grpc.gyp
  5. 6
      test/cpp/qps/BUILD
  6. 45
      test/cpp/qps/qps_server_builder.cc
  7. 46
      test/cpp/qps/qps_server_builder.h
  8. 9
      test/cpp/qps/qps_worker.cc
  9. 13
      test/cpp/qps/server_async.cc
  10. 11
      test/cpp/qps/server_sync.cc
  11. 3
      tools/run_tests/generated/sources_and_headers.json

@ -5164,6 +5164,7 @@ add_library(qps
test/cpp/qps/client_sync.cc
test/cpp/qps/driver.cc
test/cpp/qps/parse_json.cc
test/cpp/qps/qps_server_builder.cc
test/cpp/qps/qps_worker.cc
test/cpp/qps/report.cc
test/cpp/qps/server_async.cc

@ -7438,6 +7438,7 @@ LIBQPS_SRC = \
test/cpp/qps/client_sync.cc \
test/cpp/qps/driver.cc \
test/cpp/qps/parse_json.cc \
test/cpp/qps/qps_server_builder.cc \
test/cpp/qps/qps_worker.cc \
test/cpp/qps/report.cc \
test/cpp/qps/server_async.cc \
@ -7493,6 +7494,7 @@ $(OBJDIR)/$(CONFIG)/test/cpp/qps/client_async.o: $(GENDIR)/src/proto/grpc/testin
$(OBJDIR)/$(CONFIG)/test/cpp/qps/client_sync.o: $(GENDIR)/src/proto/grpc/testing/messages.pb.cc $(GENDIR)/src/proto/grpc/testing/messages.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/payloads.pb.cc $(GENDIR)/src/proto/grpc/testing/payloads.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/stats.pb.cc $(GENDIR)/src/proto/grpc/testing/stats.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/control.pb.cc $(GENDIR)/src/proto/grpc/testing/control.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/benchmark_service.pb.cc $(GENDIR)/src/proto/grpc/testing/benchmark_service.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/report_qps_scenario_service.pb.cc $(GENDIR)/src/proto/grpc/testing/report_qps_scenario_service.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/worker_service.pb.cc $(GENDIR)/src/proto/grpc/testing/worker_service.grpc.pb.cc
$(OBJDIR)/$(CONFIG)/test/cpp/qps/driver.o: $(GENDIR)/src/proto/grpc/testing/messages.pb.cc $(GENDIR)/src/proto/grpc/testing/messages.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/payloads.pb.cc $(GENDIR)/src/proto/grpc/testing/payloads.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/stats.pb.cc $(GENDIR)/src/proto/grpc/testing/stats.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/control.pb.cc $(GENDIR)/src/proto/grpc/testing/control.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/benchmark_service.pb.cc $(GENDIR)/src/proto/grpc/testing/benchmark_service.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/report_qps_scenario_service.pb.cc $(GENDIR)/src/proto/grpc/testing/report_qps_scenario_service.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/worker_service.pb.cc $(GENDIR)/src/proto/grpc/testing/worker_service.grpc.pb.cc
$(OBJDIR)/$(CONFIG)/test/cpp/qps/parse_json.o: $(GENDIR)/src/proto/grpc/testing/messages.pb.cc $(GENDIR)/src/proto/grpc/testing/messages.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/payloads.pb.cc $(GENDIR)/src/proto/grpc/testing/payloads.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/stats.pb.cc $(GENDIR)/src/proto/grpc/testing/stats.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/control.pb.cc $(GENDIR)/src/proto/grpc/testing/control.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/benchmark_service.pb.cc $(GENDIR)/src/proto/grpc/testing/benchmark_service.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/report_qps_scenario_service.pb.cc $(GENDIR)/src/proto/grpc/testing/report_qps_scenario_service.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/worker_service.pb.cc $(GENDIR)/src/proto/grpc/testing/worker_service.grpc.pb.cc
$(OBJDIR)/$(CONFIG)/test/cpp/qps/qps_server_builder.o: $(GENDIR)/src/proto/grpc/testing/messages.pb.cc $(GENDIR)/src/proto/grpc/testing/messages.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/payloads.pb.cc $(GENDIR)/src/proto/grpc/testing/payloads.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/stats.pb.cc $(GENDIR)/src/proto/grpc/testing/stats.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/control.pb.cc $(GENDIR)/src/proto/grpc/testing/control.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/benchmark_service.pb.cc $(GENDIR)/src/proto/grpc/testing/benchmark_service.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/report_qps_scenario_service.pb.cc $(GENDIR)/src/proto/grpc/testing/report_qps_scenario_service.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/worker_service.pb.cc $(GENDIR)/src/proto/grpc/testing/worker_service.grpc.pb.cc
$(OBJDIR)/$(CONFIG)/test/cpp/qps/qps_worker.o: $(GENDIR)/src/proto/grpc/testing/messages.pb.cc $(GENDIR)/src/proto/grpc/testing/messages.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/payloads.pb.cc $(GENDIR)/src/proto/grpc/testing/payloads.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/stats.pb.cc $(GENDIR)/src/proto/grpc/testing/stats.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/control.pb.cc $(GENDIR)/src/proto/grpc/testing/control.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/benchmark_service.pb.cc $(GENDIR)/src/proto/grpc/testing/benchmark_service.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/report_qps_scenario_service.pb.cc $(GENDIR)/src/proto/grpc/testing/report_qps_scenario_service.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/worker_service.pb.cc $(GENDIR)/src/proto/grpc/testing/worker_service.grpc.pb.cc
$(OBJDIR)/$(CONFIG)/test/cpp/qps/report.o: $(GENDIR)/src/proto/grpc/testing/messages.pb.cc $(GENDIR)/src/proto/grpc/testing/messages.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/payloads.pb.cc $(GENDIR)/src/proto/grpc/testing/payloads.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/stats.pb.cc $(GENDIR)/src/proto/grpc/testing/stats.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/control.pb.cc $(GENDIR)/src/proto/grpc/testing/control.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/benchmark_service.pb.cc $(GENDIR)/src/proto/grpc/testing/benchmark_service.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/report_qps_scenario_service.pb.cc $(GENDIR)/src/proto/grpc/testing/report_qps_scenario_service.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/worker_service.pb.cc $(GENDIR)/src/proto/grpc/testing/worker_service.grpc.pb.cc
$(OBJDIR)/$(CONFIG)/test/cpp/qps/server_async.o: $(GENDIR)/src/proto/grpc/testing/messages.pb.cc $(GENDIR)/src/proto/grpc/testing/messages.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/payloads.pb.cc $(GENDIR)/src/proto/grpc/testing/payloads.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/stats.pb.cc $(GENDIR)/src/proto/grpc/testing/stats.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/control.pb.cc $(GENDIR)/src/proto/grpc/testing/control.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/benchmark_service.pb.cc $(GENDIR)/src/proto/grpc/testing/benchmark_service.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/report_qps_scenario_service.pb.cc $(GENDIR)/src/proto/grpc/testing/report_qps_scenario_service.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/worker_service.pb.cc $(GENDIR)/src/proto/grpc/testing/worker_service.grpc.pb.cc
@ -24691,6 +24693,7 @@ test/cpp/qps/client_async.cc: $(OPENSSL_DEP)
test/cpp/qps/client_sync.cc: $(OPENSSL_DEP)
test/cpp/qps/driver.cc: $(OPENSSL_DEP)
test/cpp/qps/parse_json.cc: $(OPENSSL_DEP)
test/cpp/qps/qps_server_builder.cc: $(OPENSSL_DEP)
test/cpp/qps/qps_worker.cc: $(OPENSSL_DEP)
test/cpp/qps/report.cc: $(OPENSSL_DEP)
test/cpp/qps/server_async.cc: $(OPENSSL_DEP)

@ -1963,6 +1963,7 @@ libs:
- test/cpp/qps/histogram.h
- test/cpp/qps/interarrival.h
- test/cpp/qps/parse_json.h
- test/cpp/qps/qps_server_builder.h
- test/cpp/qps/qps_worker.h
- test/cpp/qps/report.h
- test/cpp/qps/server.h
@ -1981,6 +1982,7 @@ libs:
- test/cpp/qps/client_sync.cc
- test/cpp/qps/driver.cc
- test/cpp/qps/parse_json.cc
- test/cpp/qps/qps_server_builder.cc
- test/cpp/qps/qps_worker.cc
- test/cpp/qps/report.cc
- test/cpp/qps/server_async.cc

@ -1718,6 +1718,7 @@
'test/cpp/qps/client_sync.cc',
'test/cpp/qps/driver.cc',
'test/cpp/qps/parse_json.cc',
'test/cpp/qps/qps_server_builder.cc',
'test/cpp/qps/qps_worker.cc',
'test/cpp/qps/report.cc',
'test/cpp/qps/server_async.cc',

@ -34,11 +34,13 @@ grpc_cc_library(
"qps_worker.cc",
"server_async.cc",
"server_sync.cc",
"qps_server_builder.cc",
],
hdrs = [
"client.h",
"qps_worker.h",
"server.h",
"qps_server_builder.h",
],
deps = [
":histogram",
@ -55,6 +57,10 @@ grpc_cc_library(
"//test/core/util:gpr_test_util",
"//test/core/util:grpc_test_util",
"//test/cpp/util:test_util",
"//test/cpp/util:test_config",
],
external_deps = [
"gflags",
],
)

@ -0,0 +1,45 @@
/*
*
* Copyright 2016 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 "qps_server_builder.h"
using grpc::ServerBuilder;
namespace grpc {
namespace testing {
namespace {
std::unique_ptr<ServerBuilder> DefaultCreateQpsServerBuilder() {
return std::unique_ptr<ServerBuilder>(new ServerBuilder());
}
std::function<std::unique_ptr<ServerBuilder>()> g_create_qps_server_builder =
DefaultCreateQpsServerBuilder;
} // namespace
std::unique_ptr<ServerBuilder> CreateQpsServerBuilder() {
return g_create_qps_server_builder();
}
void SetCreateQpsServerBuilderFunc(
std::function<std::unique_ptr<ServerBuilder>()> create_qps_server_builder) {
g_create_qps_server_builder = std::move(create_qps_server_builder);
}
} // namespace testing
} // namespace grpc

@ -0,0 +1,46 @@
/*
*
* Copyright 2016 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.
*
*/
#ifndef GRPC_QPS_SERVER_BUILDER_H
#define GRPC_QPS_SERVER_BUILDER_H
#include <functional>
#include <memory>
#include <grpcpp/server_builder.h>
namespace grpc {
namespace testing {
// CreateQpsServerBuilder creates a new ServerBuilder.
// This uses the "create ServerBuilder" func that was set
// in SetCreateQpsServerBuilderFunc if one has been set,
// otherwise, this defaults to creating a new ServerBuilder
// with only its default constructor.
std::unique_ptr<ServerBuilder> CreateQpsServerBuilder();
// SetCreateQpsServerBuilderFunc sets a function to use to create new
// ServerBuilders in "CreateQpsServerBuilder". It can be used to modify options
// that the server is built with.
void SetCreateQpsServerBuilderFunc(
std::function<std::unique_ptr<ServerBuilder>()>);
} // namespace testing
} // namespace grpc
#endif // GRPC_QPS_SERVER_BUILDER_H

@ -39,6 +39,7 @@
#include "test/core/util/grpc_profiler.h"
#include "test/core/util/histogram.h"
#include "test/cpp/qps/client.h"
#include "test/cpp/qps/qps_server_builder.h"
#include "test/cpp/qps/server.h"
#include "test/cpp/util/create_test_channel.h"
#include "test/cpp/util/test_credentials_provider.h"
@ -272,18 +273,18 @@ 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));
ServerBuilder builder;
std::unique_ptr<ServerBuilder> builder = CreateQpsServerBuilder();
if (driver_port >= 0) {
char* server_address = nullptr;
gpr_join_host_port(&server_address, "::", driver_port);
builder.AddListeningPort(
builder->AddListeningPort(
server_address,
GetCredentialsProvider()->GetServerCredentials(credential_type));
gpr_free(server_address);
}
builder.RegisterService(impl_.get());
builder->RegisterService(impl_.get());
server_ = builder.BuildAndStart();
server_ = builder->BuildAndStart();
}
QpsWorker::~QpsWorker() {}

@ -38,6 +38,7 @@
#include "src/core/lib/surface/completion_queue.h"
#include "src/proto/grpc/testing/benchmark_service.grpc.pb.h"
#include "test/core/util/test_config.h"
#include "test/cpp/qps/qps_server_builder.h"
#include "test/cpp/qps/server.h"
namespace grpc {
@ -74,19 +75,19 @@ class AsyncQpsServerTest final : public grpc::testing::Server {
ResponseType*)>
process_rpc)
: Server(config) {
ServerBuilder builder;
std::unique_ptr<ServerBuilder> builder = CreateQpsServerBuilder();
auto port_num = port();
// Negative port number means inproc server, so no listen port needed
if (port_num >= 0) {
char* server_address = nullptr;
gpr_join_host_port(&server_address, "::", port_num);
builder.AddListeningPort(server_address,
builder->AddListeningPort(server_address,
Server::CreateServerCredentials(config));
gpr_free(server_address);
}
register_service(&builder, &async_service_);
register_service(builder.get(), &async_service_);
int num_threads = config.async_server_threads();
if (num_threads <= 0) { // dynamic sizing
@ -97,15 +98,15 @@ class AsyncQpsServerTest final : public grpc::testing::Server {
int tpc = std::max(1, config.threads_per_cq()); // 1 if unspecified
int num_cqs = (num_threads + tpc - 1) / tpc; // ceiling operator
for (int i = 0; i < num_cqs; i++) {
srv_cqs_.emplace_back(builder.AddCompletionQueue());
srv_cqs_.emplace_back(builder->AddCompletionQueue());
}
for (int i = 0; i < num_threads; i++) {
cq_.emplace_back(i % srv_cqs_.size());
}
ApplyConfigToBuilder(config, &builder);
ApplyConfigToBuilder(config, builder.get());
server_ = builder.BuildAndStart();
server_ = builder->BuildAndStart();
auto process_rpc_bound =
std::bind(process_rpc, config.payload_config(), std::placeholders::_1,

@ -27,6 +27,7 @@
#include "src/core/lib/gpr/host_port.h"
#include "src/proto/grpc/testing/benchmark_service.grpc.pb.h"
#include "test/cpp/qps/qps_server_builder.h"
#include "test/cpp/qps/server.h"
#include "test/cpp/qps/usage_timer.h"
@ -154,23 +155,23 @@ class BenchmarkServiceImpl final : public BenchmarkService::Service {
class SynchronousServer final : public grpc::testing::Server {
public:
explicit SynchronousServer(const ServerConfig& config) : Server(config) {
ServerBuilder builder;
std::unique_ptr<ServerBuilder> builder = CreateQpsServerBuilder();
auto port_num = port();
// Negative port number means inproc server, so no listen port needed
if (port_num >= 0) {
char* server_address = nullptr;
gpr_join_host_port(&server_address, "::", port_num);
builder.AddListeningPort(server_address,
builder->AddListeningPort(server_address,
Server::CreateServerCredentials(config));
gpr_free(server_address);
}
ApplyConfigToBuilder(config, &builder);
ApplyConfigToBuilder(config, builder.get());
builder.RegisterService(&service_);
builder->RegisterService(&service_);
impl_ = builder.BuildAndStart();
impl_ = builder->BuildAndStart();
}
std::shared_ptr<Channel> InProcessChannel(

@ -7761,6 +7761,7 @@
"test/cpp/qps/histogram.h",
"test/cpp/qps/interarrival.h",
"test/cpp/qps/parse_json.h",
"test/cpp/qps/qps_server_builder.h",
"test/cpp/qps/qps_worker.h",
"test/cpp/qps/report.h",
"test/cpp/qps/server.h",
@ -7782,6 +7783,8 @@
"test/cpp/qps/interarrival.h",
"test/cpp/qps/parse_json.cc",
"test/cpp/qps/parse_json.h",
"test/cpp/qps/qps_server_builder.cc",
"test/cpp/qps/qps_server_builder.h",
"test/cpp/qps/qps_worker.cc",
"test/cpp/qps/qps_worker.h",
"test/cpp/qps/report.cc",

Loading…
Cancel
Save