-
Notifications
You must be signed in to change notification settings - Fork 4.1k
split large data when using brpc streaming #1947
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,7 +35,8 @@ | |
| namespace brpc { | ||
|
|
||
| DECLARE_bool(usercode_in_pthread); | ||
|
|
||
| DEFINE_uint64(max_stream_data_frame_size, 64 * 1024 * 1024, | ||
| "Maximum size of a transmission unit that we used to cut the message."); | ||
| const static butil::IOBuf *TIMEOUT_TASK = (butil::IOBuf*)-1L; | ||
|
|
||
| Stream::Stream() | ||
|
|
@@ -140,20 +141,32 @@ ssize_t Stream::CutMessageIntoFileDescriptor(int /*fd*/, | |
| errno = EBADF; | ||
| return -1; | ||
| } | ||
| butil::IOBuf out; | ||
| ssize_t len = 0; | ||
| for (size_t i = 0; i < size; ++i) { | ||
| butil::IOBuf *data = data_list[i]; | ||
| size_t length = data->length(); | ||
| uint64_t trans_unit = FLAGS_max_stream_data_frame_size == 0 | ||
| ? length | ||
| : FLAGS_max_stream_data_frame_size; | ||
| int packet_num = ceil((double)length / (double)trans_unit); | ||
|
|
||
| butil::IOBuf split_data; | ||
| for (int j = 0; j < packet_num; j++) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 用while (!data->empty()) 来判断是不是更直接。也不用计算packet_num了。 |
||
| butil::IOBuf out; | ||
| data->cutn(&split_data, trans_unit); | ||
| bool has_continuation = (j != packet_num - 1); | ||
| 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(); | ||
| fm.set_has_continuation(has_continuation); | ||
| policy::PackStreamMessage(&out, fm, &split_data); | ||
| WriteToHostSocket(&out); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 如果has_continuation再Write
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这里是指如果消息没有达到 max_stream_data_frame_size, 就还是和之前一样放到最后统一 write 吗
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 是的 |
||
| len += (ssize_t)split_data.length(); | ||
| split_data.clear(); | ||
| } | ||
| data->clear(); | ||
| } | ||
| WriteToHostSocket(&out); | ||
| return len; | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.