FangzuoZhang commented on code in PR #3484:
URL: https://github.com/apache/brpc/pull/3484#discussion_r3891276960
##########
src/brpc/tcp_transport.cpp:
##########
@@ -103,4 +103,25 @@ void TcpTransport::QueueMessage(InputMessageClosure&
input_msg,
}
}
+void TcpTransport::QueueMessages(InputMessageBatch* input_msgs,
+ int* num_bthread_created) {
+ if (!input_msgs || input_msgs->empty()) {
+ delete input_msgs;
+ return;
+ }
+ bthread_t th;
+ bthread_attr_t tmp =
+ (FLAGS_usercode_in_pthread ? BTHREAD_ATTR_PTHREAD :
BTHREAD_ATTR_NORMAL) |
+ BTHREAD_NOSIGNAL;
+ tmp.keytable_pool = _socket->keytable_pool();
+ tmp.tag = bthread_self_tag();
+ if (!FLAGS_usercode_in_coroutine && bthread_start_background(
+ &th, &tmp, ProcessInputMessageBatch, input_msgs) == 0) {
+ ++*num_bthread_created;
+ } else {
+ input_msgs->Run();
+ delete input_msgs;
+ }
+}
Review Comment:
Addressed in commit 95368dbd.
I extracted the common batch scheduling logic into
`Transport::QueueInputMessageBatch`. The shared helper now handles:
- empty batches;
- transport-specific synchronous execution;
- bthread attributes, name, keytable pool, and tag;
- synchronous fallback when bthread creation fails;
- `num_bthread_created` accounting.
`TcpTransport`, `RdmaTransport`, and `UBShmTransport` now only provide their
transport-specific synchronous execution condition and delegate the remaining
work to the shared helper.
The unit tests cover the empty-batch path, synchronous execution,
asynchronous scheduling, and bthread creation accounting.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]