WingsGo commented on issue #2120:
URL: https://github.com/apache/brpc/issues/2120#issuecomment-1439883604
> > @chenzhangyi @wwbmmm
我理解对于baidu_rpc协议来说,meta和payload的length是在协议头就已经确定好了的,这样可以修改append_from_file_descriptor,在从socket的fd读取数据的时候,将allocate内存的方法提供给用户,然后通过append_user_data就可以在recever端减少这一次拷贝了吧?我可以提一个PR来实现一下,不知道这样的方案是否可行?
>
> 可以考虑给iobuf加个reserve_continuous_buffer(int size)方法,然后由协议来控制预留buffer的大小
那也就是说可以这么实现?在协议层直接预先分配内存,后续从fd读取的数据可以保证不会超过这个大小,这样就能保证block的数量始终保持为1,然后在读取数据的时候通过fetch方法来避免拷贝,我理解这样的改动是最小的?
`
else if (source->length() < sizeof(header_buf) + body_size) {
//
预先分配size大小的内存,并作为一个block放入source中,然后将source->length()的内容拷贝进这个block里
source-> reserve_continuous_buffer(sizeof(header_buf) + body_size)
return MakeParseError(PARSE_ERROR_NOT_ENOUGH_DATA);
}
`
--
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]