mirror of https://github.com/grpc/grpc.git
Basic callback client and server for new perchannel benchmark (#30305)
* Added new files for channel client/server * Committing to switch branch * Rebasing branch * Switching branch * Server process getting called * Still working * RPC received success, with sleep * gRPC Receive success, grpc timeout * Earlier but Clang tidy * Fix timeout issue, remove some logs * Added signint handler, test passing but flaky * added sleep to reduce flakiness, removed some dependencies, changed LOG to gpr_log * Changed benchmark_name default back to call * remove deleted files * grpc shutdown timeout * trying to add shutdown * Some changes * Removed shutdown * Automated change: Fix sanity tests * Changes for review comments * Changed comments * Changed benchmark driver defaults so that CI testing would happen for all benchmarks * Automated change: Fix sanity tests Co-authored-by: nancylucy01 <nancylucy01@users.noreply.github.com>pull/29936/head^2
parent
cacbd74f5d
commit
3cd368b28d
5 changed files with 364 additions and 36 deletions
@ -0,0 +1,106 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2022 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 <stdio.h> |
||||
#include <string.h> |
||||
|
||||
#include <gtest/gtest.h> |
||||
|
||||
#include "absl/algorithm/container.h" |
||||
#include "absl/flags/flag.h" |
||||
#include "absl/flags/parse.h" |
||||
#include "util/logging.h" |
||||
|
||||
#include <grpc/byte_buffer.h> |
||||
#include <grpc/byte_buffer_reader.h> |
||||
#include <grpc/grpc.h> |
||||
#include <grpc/grpc_security.h> |
||||
#include <grpc/support/alloc.h> |
||||
#include <grpc/support/log.h> |
||||
#include <grpc/support/time.h> |
||||
#include <grpcpp/grpcpp.h> |
||||
#include <grpcpp/support/client_callback.h> |
||||
|
||||
#include "src/core/lib/address_utils/sockaddr_utils.h" |
||||
#include "src/core/lib/channel/channel_args.h" |
||||
#include "src/core/lib/gpr/env.h" |
||||
#include "src/core/lib/gpr/string.h" |
||||
#include "src/core/lib/gpr/useful.h" |
||||
#include "src/core/lib/gprpp/host_port.h" |
||||
#include "src/core/lib/iomgr/exec_ctx.h" |
||||
#include "src/core/lib/iomgr/sockaddr.h" |
||||
#include "src/core/lib/iomgr/socket_utils.h" |
||||
#include "src/core/lib/security/credentials/credentials.h" |
||||
#include "src/cpp/client/secure_credentials.h" |
||||
#include "src/proto/grpc/testing/benchmark_service.grpc.pb.h" |
||||
#include "test/core/memory_usage/memstats.h" |
||||
#include "test/core/util/port.h" |
||||
#include "test/core/util/subprocess.h" |
||||
#include "test/core/util/test_config.h" |
||||
|
||||
ABSL_FLAG(std::string, target, "", "Target host:port"); |
||||
ABSL_FLAG(bool, secure, false, "Use SSL Credentials"); |
||||
|
||||
void UnaryCall() { |
||||
// Set the authentication mechanism.
|
||||
std::shared_ptr<grpc::ChannelCredentials> creds = |
||||
grpc::InsecureChannelCredentials(); |
||||
if (absl::GetFlag(FLAGS_secure)) { |
||||
// TODO (chennancy) Add in secure credentials
|
||||
gpr_log(GPR_INFO, "Supposed to be secure, is not yet"); |
||||
} |
||||
|
||||
// Create a channel to the server and a stub
|
||||
std::shared_ptr<grpc::Channel> channel = |
||||
CreateChannel(absl::GetFlag(FLAGS_target), creds); |
||||
std::unique_ptr<grpc::testing::BenchmarkService::Stub> stub = |
||||
grpc::testing::BenchmarkService::NewStub(channel); |
||||
|
||||
// Start a call.
|
||||
struct CallParams { |
||||
grpc::ClientContext context; |
||||
grpc::testing::SimpleRequest request; |
||||
grpc::testing::SimpleResponse response; |
||||
}; |
||||
CallParams* params = new CallParams(); |
||||
stub->async()->UnaryCall(¶ms->context, ¶ms->request, |
||||
¶ms->response, [](const grpc::Status& status) { |
||||
if (status.ok()) { |
||||
gpr_log(GPR_INFO, "UnaryCall RPC succeeded."); |
||||
} else { |
||||
gpr_log(GPR_ERROR, "UnaryCall RPC failed."); |
||||
} |
||||
}); |
||||
} |
||||
|
||||
int main(int argc, char** argv) { |
||||
absl::ParseCommandLine(argc, argv); |
||||
char* fake_argv[1]; |
||||
GPR_ASSERT(argc >= 1); |
||||
fake_argv[0] = argv[0]; |
||||
grpc::testing::TestEnvironment env(&argc, argv); |
||||
if (absl::GetFlag(FLAGS_target).empty()) { |
||||
gpr_log(GPR_ERROR, "Client: No target port entered"); |
||||
return 1; |
||||
} |
||||
gpr_log(GPR_INFO, "Client Target: %s", absl::GetFlag(FLAGS_target).c_str()); |
||||
|
||||
UnaryCall(); |
||||
gpr_log(GPR_INFO, "Client Done"); |
||||
return 0; |
||||
} |
@ -0,0 +1,107 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2022 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 <stdio.h> |
||||
#include <string.h> |
||||
|
||||
#include <thread> |
||||
|
||||
#include <gtest/gtest.h> |
||||
|
||||
#include "absl/algorithm/container.h" |
||||
#include "absl/flags/flag.h" |
||||
#include "absl/flags/parse.h" |
||||
#include "util/logging.h" |
||||
|
||||
#include <grpc/grpc.h> |
||||
#include <grpc/grpc_security.h> |
||||
#include <grpc/support/alloc.h> |
||||
#include <grpc/support/log.h> |
||||
#include <grpc/support/time.h> |
||||
#include <grpcpp/grpcpp.h> |
||||
#include <grpcpp/support/client_callback.h> |
||||
|
||||
#include "src/core/lib/address_utils/sockaddr_utils.h" |
||||
#include "src/core/lib/channel/channel_args.h" |
||||
#include "src/core/lib/gpr/env.h" |
||||
#include "src/core/lib/gpr/string.h" |
||||
#include "src/core/lib/gpr/useful.h" |
||||
#include "src/core/lib/gprpp/host_port.h" |
||||
#include "src/core/lib/security/credentials/credentials.h" |
||||
#include "src/cpp/client/secure_credentials.h" |
||||
#include "src/proto/grpc/testing/benchmark_service.grpc.pb.h" |
||||
#include "test/core/memory_usage/memstats.h" |
||||
#include "test/core/util/port.h" |
||||
#include "test/core/util/subprocess.h" |
||||
#include "test/core/util/test_config.h" |
||||
|
||||
class ServerCallbackImpl final |
||||
: public grpc::testing::BenchmarkService::CallbackService { |
||||
grpc::ServerUnaryReactor* UnaryCall( |
||||
grpc::CallbackServerContext* context, |
||||
const grpc::testing::SimpleRequest* request, |
||||
grpc::testing::SimpleResponse* response) override { |
||||
gpr_log(GPR_INFO, "RPC CALL RECEIVED"); |
||||
auto* reactor = context->DefaultReactor(); |
||||
reactor->Finish(grpc::Status::OK); |
||||
return reactor; |
||||
} |
||||
}; |
||||
|
||||
/* We have some sort of deadlock, so let's not exit gracefully for now.
|
||||
TODO(chennancy) Add graceful shutdown */ |
||||
static void sigint_handler(int /*x*/) { _exit(0); } |
||||
|
||||
ABSL_FLAG(std::string, bind, "", "Bind host:port"); |
||||
ABSL_FLAG(bool, secure, false, "Use SSL Credentials"); |
||||
|
||||
int main(int argc, char** argv) { |
||||
absl::ParseCommandLine(argc, argv); |
||||
char* fake_argv[1]; |
||||
GPR_ASSERT(argc >= 1); |
||||
fake_argv[0] = argv[0]; |
||||
grpc::testing::TestEnvironment env(&argc, argv); |
||||
grpc_init(); |
||||
signal(SIGINT, sigint_handler); |
||||
std::string server_address = absl::GetFlag(FLAGS_bind); |
||||
if (server_address.empty()) { |
||||
gpr_log(GPR_ERROR, "Server: No port entered"); |
||||
return 1; |
||||
} |
||||
gpr_log(GPR_INFO, "Server port: %s", server_address.c_str()); |
||||
|
||||
ServerCallbackImpl callback_server; |
||||
grpc::ServerBuilder builder; |
||||
// Set the authentication mechanism.
|
||||
std::shared_ptr<grpc::ServerCredentials> creds = |
||||
grpc::InsecureServerCredentials(); |
||||
if (absl::GetFlag(FLAGS_secure)) { |
||||
gpr_log(GPR_INFO, "Supposed to be secure, is not yet"); |
||||
// TODO (chennancy) Add in secure credentials
|
||||
} |
||||
builder.AddListeningPort(server_address, creds); |
||||
builder.RegisterService(&callback_server); |
||||
|
||||
// Set up the server to start accepting requests.
|
||||
std::shared_ptr<grpc::Server> server(builder.BuildAndStart()); |
||||
gpr_log(GPR_INFO, "Server listening on %s", server_address.c_str()); |
||||
|
||||
// Keep the program running until the server shuts down.
|
||||
server->Wait(); |
||||
return 0; |
||||
} |
Loading…
Reference in new issue