Add brpc surpport.#11263
Conversation
| endif() | ||
|
|
||
|
|
||
| set(DISTRIBUTE_COMPILE_FLAGS "-Wno-non-virtual-dtor -Wno-error=non-virtual-dtor -Wno-error=delete-non-virtual-dtor") |
There was a problem hiding this comment.
Do brpc still need to set this flags?
| TEST(SendNcclId, GrpcServer) { | ||
| TEST(SendNcclId, RPCServer) { | ||
| g_req_handler.reset(new detail::RequestSendHandler(true)); | ||
| #ifdef PADDLE_WITH_GRPC |
There was a problem hiding this comment.
Can use a macro somewhere in the header to define the RPCServer type to save some lines, like:
#ifdef PADDLE_WITH_GRPC
#define RPCSERVER_T detail::AsyncGRPCServer
#else
#define RPCSERVER_T detail::AsyncBRPCServer
#endifThen use RPCSERVER_T
|
|
||
| DEFINE_int32(brpc_channel_num, 24, | ||
| "Number of channels to send requests connected to one server"); | ||
| DEFINE_string(connection_type, "pooled", |
There was a problem hiding this comment.
I think we can directly use "pooled" connection type. "single" means that we can use at most one connection to one server.
| "Number of channels to send requests connected to one server"); | ||
| DEFINE_string(connection_type, "pooled", | ||
| "Connection type. Available values: single, pooled, short"); | ||
| DEFINE_int32(timeout_ms, -1, "RPC timeout in milliseconds"); |
There was a problem hiding this comment.
Since we have time_out specified in AsyncSendVar, it seems that we do not need this flag.
There was a problem hiding this comment.
Is there a way to apply timeout to one send or recv action instead of to channel options?
There was a problem hiding this comment.
You can set_timeout_ms() to configure controller, which works for the current RPC call.
| sendrecv::VoidMessage* response = new sendrecv::VoidMessage(); | ||
|
|
||
| google::protobuf::Closure* done = | ||
| brpc::NewCallback(&HandleSendResponse, cntl, response); |
There was a problem hiding this comment.
This callback is called when the RPC is finished, which means that the client have got the response. It looks like a misuse.
There was a problem hiding this comment.
So it's ok to handle the response?
There was a problem hiding this comment.
Maybe I misunderstand the meaning of HandleSendResponse. Does it refer to the handler after getting the response of "Send" RPC call? If it is, there is no problem here.
There was a problem hiding this comment.
Ye, it's a handler. The name should be polished. Thanks!
| @@ -0,0 +1,44 @@ | |||
| # Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserved. | |||
There was a problem hiding this comment.
Is there anyway to avoid depending on this?
There was a problem hiding this comment.
I will delete this if I found a way to avoid depending on this.
There was a problem hiding this comment.
What is the reason for depending on it now?
There was a problem hiding this comment.
There was a problem hiding this comment.
@Tuvie Is there anyway for brpc to avoid depending on leveldb?
| sendrecv::VoidMessage* response) { | ||
| // std::unique_ptr makes sure cntl/response will be deleted before returning. | ||
| std::unique_ptr<brpc::Controller> cntl_guard(cntl); | ||
| std::unique_ptr<sendrecv::VoidMessage> response_guard(response); |
There was a problem hiding this comment.
usually we can just make std::unique_ptr<brpc::Controller> cntl argument
There was a problem hiding this comment.
It should be copied.
| namespace sendrecv { | ||
| class BRPCServiceImpl : public SendRecvService { | ||
| public: | ||
| BRPCServiceImpl(const std::unordered_map< |
There was a problem hiding this comment.
Can use typedef std::unordered_map<std::string, paddle::operators::detail::RequestHandler*> HandlerMap to simplify the code.
| google::protobuf::Closure* done) override { | ||
| brpc::ClosureGuard done_guard(done); | ||
|
|
||
| paddle::framework::Scope* local_scope = request_send_h_->scope(); |
There was a problem hiding this comment.
request_send_h_ may be nullptr? well in some rare cases, but request_prefetch_h_ may be null in most cases. Better to add a check here?
There was a problem hiding this comment.
Set nullptr when initialize.
There was a problem hiding this comment.
Well, if request_prefetch_h_ is not set actually, request_prefetch_h_->scope() will cause error.
There was a problem hiding this comment.
I add checker when they're called.
| syntax = "proto3"; | ||
| package sendrecv; | ||
|
|
||
| // option cc_generic_services = true; |
There was a problem hiding this comment.
Can delete this if not needed? Curious what will this line affect?
There was a problem hiding this comment.
https://developers.google.com/protocol-buffers/docs/proto
Whether or not the protocol buffer compiler should generate abstract service code
based on services definitions in C++, Java, and Python, respectively. For legacy
reasons, these default to true. However, as of version 2.3.0 (January 2010), it is
considered preferrable for RPC implementations to provide code generator plugins to
generate code more specific to each system, rather than rely on the "abstract" services
Grpc uses the code generator plugin to generate more specific to each system, and it needs this to be false. While brpc uses the default generated abstract service code, and it needs this to be true. I will fix this to be compatbile in next PR.
There was a problem hiding this comment.
Thanks for this information!
| rpc_service_->SavePort(); | ||
| } | ||
|
|
||
| static int64_t GetTimestamp() { |
There was a problem hiding this comment.
This is already defined in sendrecvop_utils.h can delete codes there.
There was a problem hiding this comment.
If sendrecvop_utils.h is included in files it needs to know grpc types explicitly.
So I move this function's definition here and it's used only in this file now.
| detail::AsyncGRPCServer rpc_service(endpoint, 1); | ||
| rpc_service.RegisterRPC(detail::kRequestSend, &rpc_h); | ||
| rpc_h.SetRPCServer(&rpc_service); | ||
| std::unique_ptr<detail::RPCServer> rpc_service(nullptr); |
| #include "paddle/fluid/operators/detail/request_handler.h" | ||
| #include "paddle/fluid/operators/detail/rpc_server.h" | ||
| #include "paddle/fluid/operators/detail/send_recv.pb.h" | ||
| #include "paddle/fluid/platform/profiler.h" |
There was a problem hiding this comment.
It seems you don't need to include most of these things in header?
| } | ||
| } | ||
| brpc::Channel channel; | ||
| sendrecv::SendRecvService_Stub* stub; |
There was a problem hiding this comment.
why not make it unique_ptr?
There was a problem hiding this comment.
It's need to be copied.
There was a problem hiding this comment.
Can use shared_ptr here?
|
|
||
| DEFINE_int32(brpc_channel_num, 24, | ||
| "Number of channels to send requests connected to one server"); | ||
| DEFINE_int32(timeout_ms, -1, "RPC timeout in milliseconds"); |
| @@ -0,0 +1,44 @@ | |||
| # Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserved. | |||
There was a problem hiding this comment.
@Tuvie Is there anyway for brpc to avoid depending on leveldb?
Add only brpc framework and use a macro to avoid affecting original grpc functions.