File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -298,6 +298,7 @@ void Controller::ResetPods() {
298298 _response_streams.clear ();
299299 _remote_stream_settings = NULL ;
300300 _auth_flags = 0 ;
301+ _rpc_received_us = 0 ;
301302}
302303
303304Controller::Call::Call (Controller::Call* rhs)
Original file line number Diff line number Diff line change @@ -638,6 +638,17 @@ friend void policy::ProcessThriftRequest(InputMessageBase*);
638638 return _response_content_type;
639639 }
640640
641+ // If brpc acts as a server, this interface exposes the time when the RPC was received from the
642+ // socket. This function can be used in scenarios where the user code needs to understand the RPC
643+ // reception time, such as for precise control of timeouts. Users will require timing to start
644+ // from the receipt of the RPC. When the user processing function starts to handle the RPC, if
645+ // it is found that the RPC has timed out, it will be directly discarded
646+ void set_rpc_received_us (int64_t received_us) { _rpc_received_us = received_us; }
647+
648+ // Get the received time of RPC (in microseconds), if the returned value is 0, it means that
649+ // the received time of RPC is not recorded in the controller.
650+ int64_t get_rpc_received_us () const { return _rpc_received_us; }
651+
641652private:
642653 struct CompletionInfo {
643654 CallId id; // call_id of the corresponding request
@@ -909,6 +920,9 @@ friend void policy::ProcessThriftRequest(InputMessageBase*);
909920 uint32_t _auth_flags;
910921
911922 AfterRpcRespFnType _after_rpc_resp_fn;
923+
924+ // The point in time when the rpc is read from the socket
925+ int64_t _rpc_received_us;
912926};
913927
914928// Advises the RPC system that the caller desires that the RPC call be
Original file line number Diff line number Diff line change @@ -615,6 +615,7 @@ void ProcessRpcRequest(InputMessageBase* msg_base) {
615615 cntl->set_request_content_type (meta.content_type ());
616616 cntl->set_request_compress_type ((CompressType)meta.compress_type ());
617617 cntl->set_request_checksum_type ((ChecksumType)meta.checksum_type ());
618+ cntl->set_rpc_received_us (msg->received_us ());
618619 accessor.set_checksum_value (meta.checksum_value ());
619620 accessor.set_server (server)
620621 .set_security_mode (security_mode)
@@ -943,6 +944,7 @@ void ProcessRpcResponse(InputMessageBase* msg_base) {
943944 }
944945 }
945946
947+ cntl->set_rpc_received_us (msg->received_us ());
946948 Span* span = accessor.span ();
947949 if (span) {
948950 span->set_base_real_us (msg->base_real_us ());
You can’t perform that action at this time.
0 commit comments