From 1303ec7b53b9a6916b0cb3ac8dfe8ddcef0f6736 Mon Sep 17 00:00:00 2001 From: Moiz Haidry Date: Mon, 5 Nov 2018 16:09:34 -0800 Subject: Added benchmarks for Callback based Unary server --- CMakeLists.txt | 1 + Makefile | 3 + build.yaml | 1 + grpc.gyp | 1 + src/proto/grpc/testing/control.proto | 1 + test/cpp/qps/BUILD | 1 + test/cpp/qps/qps_worker.cc | 2 + test/cpp/qps/server.h | 1 + test/cpp/qps/server_callback.cc | 96 ++++++++++++++++++++++ tools/run_tests/generated/sources_and_headers.json | 1 + 10 files changed, 108 insertions(+) create mode 100644 test/cpp/qps/server_callback.cc diff --git a/CMakeLists.txt b/CMakeLists.txt index 372a92d222..e7fadfd049 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5336,6 +5336,7 @@ add_library(qps test/cpp/qps/qps_worker.cc test/cpp/qps/report.cc test/cpp/qps/server_async.cc + test/cpp/qps/server_callback.cc test/cpp/qps/server_sync.cc test/cpp/qps/usage_timer.cc ) diff --git a/Makefile b/Makefile index 3ffbb8a50b..9735471c84 100644 --- a/Makefile +++ b/Makefile @@ -7606,6 +7606,7 @@ LIBQPS_SRC = \ test/cpp/qps/qps_worker.cc \ test/cpp/qps/report.cc \ test/cpp/qps/server_async.cc \ + test/cpp/qps/server_callback.cc \ test/cpp/qps/server_sync.cc \ test/cpp/qps/usage_timer.cc \ @@ -7663,6 +7664,7 @@ $(OBJDIR)/$(CONFIG)/test/cpp/qps/qps_server_builder.o: $(GENDIR)/src/proto/grpc/ $(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 +$(OBJDIR)/$(CONFIG)/test/cpp/qps/server_callback.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_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/usage_timer.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 @@ -25089,6 +25091,7 @@ 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) +test/cpp/qps/server_callback.cc: $(OPENSSL_DEP) test/cpp/qps/server_sync.cc: $(OPENSSL_DEP) test/cpp/qps/usage_timer.cc: $(OPENSSL_DEP) test/cpp/util/byte_buffer_proto_helper.cc: $(OPENSSL_DEP) diff --git a/build.yaml b/build.yaml index 24fe56ab60..742f96b2bb 100644 --- a/build.yaml +++ b/build.yaml @@ -2037,6 +2037,7 @@ libs: - test/cpp/qps/qps_worker.cc - test/cpp/qps/report.cc - test/cpp/qps/server_async.cc + - test/cpp/qps/server_callback.cc - test/cpp/qps/server_sync.cc - test/cpp/qps/usage_timer.cc deps: diff --git a/grpc.gyp b/grpc.gyp index ea61d5f6ac..fc0c61bcbd 100644 --- a/grpc.gyp +++ b/grpc.gyp @@ -1760,6 +1760,7 @@ 'test/cpp/qps/qps_worker.cc', 'test/cpp/qps/report.cc', 'test/cpp/qps/server_async.cc', + 'test/cpp/qps/server_callback.cc', 'test/cpp/qps/server_sync.cc', 'test/cpp/qps/usage_timer.cc', ], diff --git a/src/proto/grpc/testing/control.proto b/src/proto/grpc/testing/control.proto index 4cfdc2cafb..564d8234b7 100644 --- a/src/proto/grpc/testing/control.proto +++ b/src/proto/grpc/testing/control.proto @@ -33,6 +33,7 @@ enum ServerType { ASYNC_SERVER = 1; ASYNC_GENERIC_SERVER = 2; OTHER_SERVER = 3; // used for some language-specific variants + CALLBACK_SERVER = 4; } enum RpcType { diff --git a/test/cpp/qps/BUILD b/test/cpp/qps/BUILD index 2ef7441371..26f43284a6 100644 --- a/test/cpp/qps/BUILD +++ b/test/cpp/qps/BUILD @@ -36,6 +36,7 @@ grpc_cc_library( "qps_server_builder.cc", "qps_worker.cc", "server_async.cc", + "server_callback.cc", "server_sync.cc", ], hdrs = [ diff --git a/test/cpp/qps/qps_worker.cc b/test/cpp/qps/qps_worker.cc index d97d95d8f3..23fe72316a 100644 --- a/test/cpp/qps/qps_worker.cc +++ b/test/cpp/qps/qps_worker.cc @@ -79,6 +79,8 @@ static std::unique_ptr CreateServer(const ServerConfig& config) { return CreateAsyncServer(config); case ServerType::ASYNC_GENERIC_SERVER: return CreateAsyncGenericServer(config); + case ServerType::CALLBACK_SERVER: + return CreateCallbackServer(config); default: abort(); } diff --git a/test/cpp/qps/server.h b/test/cpp/qps/server.h index 6b1ef93617..89b0e3af4b 100644 --- a/test/cpp/qps/server.h +++ b/test/cpp/qps/server.h @@ -152,6 +152,7 @@ class Server { std::unique_ptr CreateSynchronousServer(const ServerConfig& config); std::unique_ptr CreateAsyncServer(const ServerConfig& config); std::unique_ptr CreateAsyncGenericServer(const ServerConfig& config); +std::unique_ptr CreateCallbackServer(const ServerConfig& config); } // namespace testing } // namespace grpc diff --git a/test/cpp/qps/server_callback.cc b/test/cpp/qps/server_callback.cc new file mode 100644 index 0000000000..8bedd44739 --- /dev/null +++ b/test/cpp/qps/server_callback.cc @@ -0,0 +1,96 @@ +/* + * + * 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 +#include +#include +#include +#include + +#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" + +namespace grpc { +namespace testing { + +class BenchmarkCallbackServiceImpl final + : public BenchmarkService::ExperimentalCallbackService { + public: + void UnaryCall( + ServerContext* context, const SimpleRequest* request, + SimpleResponse* response, + experimental::ServerCallbackRpcController* controller) override { + auto s = SetResponse(request, response); + controller->Finish(s); + } + + private: + static Status SetResponse(const SimpleRequest* request, + SimpleResponse* response) { + if (request->response_size() > 0) { + if (!Server::SetPayload(request->response_type(), + request->response_size(), + response->mutable_payload())) { + return Status(grpc::StatusCode::INTERNAL, "Error creating payload."); + } + } + return Status::OK; + } +}; + +class CallbackServer final : public grpc::testing::Server { + public: + explicit CallbackServer(const ServerConfig& config) : Server(config) { + std::unique_ptr 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, + Server::CreateServerCredentials(config)); + gpr_free(server_address); + } + + ApplyConfigToBuilder(config, builder.get()); + + builder->RegisterService(&service_); + + impl_ = builder->BuildAndStart(); + } + + std::shared_ptr InProcessChannel( + const ChannelArguments& args) override { + return impl_->InProcessChannel(args); + } + + private: + BenchmarkCallbackServiceImpl service_; + std::unique_ptr impl_; +}; + +std::unique_ptr CreateCallbackServer( + const ServerConfig& config) { + return std::unique_ptr(new CallbackServer(config)); +} + +} // namespace testing +} // namespace grpc diff --git a/tools/run_tests/generated/sources_and_headers.json b/tools/run_tests/generated/sources_and_headers.json index b94fc77d76..203b4fecae 100644 --- a/tools/run_tests/generated/sources_and_headers.json +++ b/tools/run_tests/generated/sources_and_headers.json @@ -7880,6 +7880,7 @@ "test/cpp/qps/report.h", "test/cpp/qps/server.h", "test/cpp/qps/server_async.cc", + "test/cpp/qps/server_callback.cc", "test/cpp/qps/server_sync.cc", "test/cpp/qps/stats.h", "test/cpp/qps/usage_timer.cc", -- cgit v1.2.3