You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

ms_server.cc 2.4 kB

5 years ago
5 years ago
5 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /**
  2. * Copyright 2020 Huawei Technologies Co., Ltd
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #include <grpcpp/grpcpp.h>
  17. #include <grpcpp/health_check_service_interface.h>
  18. #include <grpcpp/ext/proto_server_reflection_plugin.h>
  19. #include <iostream>
  20. #include "./ms_service.grpc.pb.h"
  21. using grpc::Server;
  22. using grpc::ServerBuilder;
  23. using grpc::ServerContext;
  24. using grpc::Status;
  25. using ms_serving::MSService;
  26. using ms_serving::PredictReply;
  27. using ms_serving::PredictRequest;
  28. // Logic and data behind the server's behavior.
  29. class MSServiceImpl final : public MSService::Service {
  30. Status Predict(ServerContext *context, const PredictRequest *request, PredictReply *reply) override {
  31. std::cout << "server eval" << std::endl;
  32. return Status::OK;
  33. }
  34. };
  35. void RunServer() {
  36. std::string server_address("0.0.0.0:50051");
  37. MSServiceImpl service;
  38. grpc::EnableDefaultHealthCheckService(true);
  39. grpc::reflection::InitProtoReflectionServerBuilderPlugin();
  40. auto option = grpc::MakeChannelArgumentOption(GRPC_ARG_ALLOW_REUSEPORT, 0);
  41. ServerBuilder builder;
  42. builder.SetOption(std::move(option));
  43. // Listen on the given address without any authentication mechanism.
  44. builder.AddListeningPort(server_address, grpc::InsecureServerCredentials());
  45. // Register "service" as the instance through which we'll communicate with
  46. // clients. In this case it corresponds to an *synchronous* service.
  47. builder.RegisterService(&service);
  48. // Finally assemble the server.
  49. std::unique_ptr<Server> server(builder.BuildAndStart());
  50. std::cout << "Server listening on " << server_address << std::endl;
  51. // Wait for the server to shutdown. Note that some other thread must be
  52. // responsible for shutting down the server for this call to ever return.
  53. server->Wait();
  54. }
  55. int main(int argc, char **argv) {
  56. RunServer();
  57. return 0;
  58. }