You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@brpc.apache.org by "jenrryyou (via GitHub)" <gi...@apache.org> on 2025/02/07 09:06:06 UTC
[PR] Support segment large brpc stream messages automatically (brpc)
jenrryyou opened a new pull request, #2889:
URL: https://github.com/apache/brpc/pull/2889
### What problem does this PR solve?
https://github.com/apache/incubator-brpc/blob/master/docs/cn/streaming_rpc.md
"目前的实现还没有自动切割过大的消息,同一个tcp连接上的多个Stream之间可能有[Head-of-line blocking](https://en.wikipedia.org/wiki/Head-of-line_blocking)问题,请尽量避免过大的单个消息,实现自动切割后我们会告知并更新文档"
之前#1947 这个MR存在一点问题(见 comment)一直没有合入。最近内部有很多业务有需求,我重新实现了下。
--
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: dev-unsubscribe@brpc.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org
Re: [PR] Support segment large brpc stream messages automatically (brpc)
Posted by "chenBright (via GitHub)" <gi...@apache.org>.
chenBright commented on code in PR #2889:
URL: https://github.com/apache/brpc/pull/2889#discussion_r1957607047
##########
src/brpc/stream.cpp:
##########
@@ -36,6 +36,9 @@ namespace brpc {
DECLARE_bool(usercode_in_pthread);
DECLARE_int64(socket_max_streams_unconsumed_bytes);
+DEFINE_uint64(stream_write_max_segment_size, 512 * 1024 * 1024,
Review Comment:
也可以
--
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: dev-unsubscribe@brpc.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org
Re: [PR] Support segment large brpc stream messages automatically (brpc)
Posted by "wwbmmm (via GitHub)" <gi...@apache.org>.
wwbmmm commented on code in PR #2889:
URL: https://github.com/apache/brpc/pull/2889#discussion_r1948071619
##########
src/brpc/stream.cpp:
##########
@@ -36,6 +36,18 @@ namespace brpc {
DECLARE_bool(usercode_in_pthread);
DECLARE_int64(socket_max_streams_unconsumed_bytes);
+DEFINE_uint64(stream_write_max_segment_size, 512 * 1024 * 1024,
+ "Stream message exceeding this size will be automatically split into smaller segments");
+
+static bool ValidateStreamWriteMaxSegmentSize(const char* flagname, uint64_t value) {
Review Comment:
可以直接用 brpc::PositiveInteger
##########
src/brpc/stream.cpp:
##########
@@ -154,18 +173,54 @@ ssize_t Stream::CutMessageIntoFileDescriptor(int /*fd*/,
}
butil::IOBuf out;
ssize_t len = 0;
+ ssize_t unwritten_data_size = 0;
for (size_t i = 0; i < size; ++i) {
- StreamFrameMeta fm;
- fm.set_stream_id(_remote_settings.stream_id());
- fm.set_source_stream_id(id());
- fm.set_frame_type(FRAME_TYPE_DATA);
- // TODO: split large data
- fm.set_has_continuation(false);
- policy::PackStreamMessage(&out, fm, data_list[i]);
- len += data_list[i]->length();
- data_list[i]->clear();
+ butil::IOBuf *data = data_list[i];
+ size_t length = data->length();
+ if(length > FLAGS_stream_write_max_segment_size) {
Review Comment:
if后面加一个空格,下同
--
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: dev-unsubscribe@brpc.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org
Re: [PR] Support segment large brpc stream messages automatically (brpc)
Posted by "jenrryyou (via GitHub)" <gi...@apache.org>.
jenrryyou commented on code in PR #2889:
URL: https://github.com/apache/brpc/pull/2889#discussion_r1948099460
##########
src/brpc/stream.cpp:
##########
@@ -154,18 +173,54 @@ ssize_t Stream::CutMessageIntoFileDescriptor(int /*fd*/,
}
butil::IOBuf out;
ssize_t len = 0;
+ ssize_t unwritten_data_size = 0;
for (size_t i = 0; i < size; ++i) {
- StreamFrameMeta fm;
- fm.set_stream_id(_remote_settings.stream_id());
- fm.set_source_stream_id(id());
- fm.set_frame_type(FRAME_TYPE_DATA);
- // TODO: split large data
- fm.set_has_continuation(false);
- policy::PackStreamMessage(&out, fm, data_list[i]);
- len += data_list[i]->length();
- data_list[i]->clear();
+ butil::IOBuf *data = data_list[i];
+ size_t length = data->length();
+ if(length > FLAGS_stream_write_max_segment_size) {
Review Comment:
已改
--
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: dev-unsubscribe@brpc.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org
Re: [PR] Support segment large brpc stream messages automatically (brpc)
Posted by "chenBright (via GitHub)" <gi...@apache.org>.
chenBright merged PR #2889:
URL: https://github.com/apache/brpc/pull/2889
--
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: dev-unsubscribe@brpc.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org
Re: [PR] Support segment large brpc stream messages automatically (brpc)
Posted by "jenrryyou (via GitHub)" <gi...@apache.org>.
jenrryyou commented on code in PR #2889:
URL: https://github.com/apache/brpc/pull/2889#discussion_r1948099151
##########
src/brpc/stream.cpp:
##########
@@ -36,6 +36,18 @@ namespace brpc {
DECLARE_bool(usercode_in_pthread);
DECLARE_int64(socket_max_streams_unconsumed_bytes);
+DEFINE_uint64(stream_write_max_segment_size, 512 * 1024 * 1024,
+ "Stream message exceeding this size will be automatically split into smaller segments");
+
+static bool ValidateStreamWriteMaxSegmentSize(const char* flagname, uint64_t value) {
Review Comment:
已改
--
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: dev-unsubscribe@brpc.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org
Re: [PR] Support segment large brpc stream messages automatically (brpc)
Posted by "jenrryyou (via GitHub)" <gi...@apache.org>.
jenrryyou commented on code in PR #2889:
URL: https://github.com/apache/brpc/pull/2889#discussion_r1957544064
##########
src/brpc/stream.cpp:
##########
@@ -36,6 +36,9 @@ namespace brpc {
DECLARE_bool(usercode_in_pthread);
DECLARE_int64(socket_max_streams_unconsumed_bytes);
+DEFINE_uint64(stream_write_max_segment_size, 512 * 1024 * 1024,
Review Comment:
嗯,可以调小,不过没有想到一个合适的值,看你建议。当时设置默认值512MB是想让用户手动设置下Gflags来开启这个能力,否则就用一个比较大的值,等内部生产收集到比较多的最佳实践再调整这个默认值。
--
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: dev-unsubscribe@brpc.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org
Re: [PR] Support segment large brpc stream messages automatically (brpc)
Posted by "wwbmmm (via GitHub)" <gi...@apache.org>.
wwbmmm commented on PR #2889:
URL: https://github.com/apache/brpc/pull/2889#issuecomment-2646813800
LGTM
--
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: dev-unsubscribe@brpc.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org
Re: [PR] Support segment large brpc stream messages automatically (brpc)
Posted by "chenBright (via GitHub)" <gi...@apache.org>.
chenBright commented on code in PR #2889:
URL: https://github.com/apache/brpc/pull/2889#discussion_r1957510942
##########
src/brpc/stream.cpp:
##########
@@ -36,6 +36,9 @@ namespace brpc {
DECLARE_bool(usercode_in_pthread);
DECLARE_int64(socket_max_streams_unconsumed_bytes);
+DEFINE_uint64(stream_write_max_segment_size, 512 * 1024 * 1024,
Review Comment:
512MB?会不会太大了?
--
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: dev-unsubscribe@brpc.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org
Re: [PR] Support segment large brpc stream messages automatically (brpc)
Posted by "jenrryyou (via GitHub)" <gi...@apache.org>.
jenrryyou commented on PR #2889:
URL: https://github.com/apache/brpc/pull/2889#issuecomment-2661453771
辛苦大佬@wwbmmm @chenBright 有空点下merge
--
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: dev-unsubscribe@brpc.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@brpc.apache.org
For additional commands, e-mail: dev-help@brpc.apache.org