wwbmmm commented on code in PR #1958:
URL: https://github.com/apache/incubator-brpc/pull/1958#discussion_r1002857418
##########
src/brpc/stream.cpp:
##########
@@ -284,21 +297,43 @@ int Stream::AppendIfNotFull(const butil::IOBuf &data) {
_produced -= data.length();
return -1;
}
+ if (FLAGS_socket_max_streams_unconsumed_bytes > 0) {
+ _host_socket->_total_streams_unconsumed_size += data.length();
+ }
return 0;
}
void Stream::SetRemoteConsumed(size_t new_remote_consumed) {
- CHECK(_options.max_buf_size > 0);
+ CHECK(_cur_buf_size > 0);
bthread_id_list_t tmplist;
bthread_id_list_init(&tmplist, 0, 0);
bthread_mutex_lock(&_congestion_control_mutex);
if (_remote_consumed >= new_remote_consumed) {
bthread_mutex_unlock(&_congestion_control_mutex);
return;
}
- const bool was_full = _produced >= _remote_consumed +
(size_t)_options.max_buf_size;
+ const bool was_full = _produced >= _remote_consumed +
(size_t)_cur_buf_size;
+
+ if (FLAGS_socket_max_streams_unconsumed_bytes > 0) {
+ _host_socket->_total_streams_unconsumed_size -= new_remote_consumed -
_remote_consumed;
+ if (_host_socket->_total_streams_unconsumed_size >
FLAGS_socket_max_streams_unconsumed_bytes) {
+ if (_options.min_buf_size > 0) {
+ _cur_buf_size = _options.min_buf_size;
+ } else {
+ _cur_buf_size /= 2;
+ }
+ LOG(INFO) << "stream consumers on socket " << _host_socket->id()
<< " is crowded, " << "cut stream " << id() << " buffer to " << _cur_buf_size;
+ } else if (_produced >= new_remote_consumed + _cur_buf_size &&
(_options.max_buf_size == 0 || _cur_buf_size < (size_t)_options.max_buf_size)) {
Review Comment:
如果_options.max_buf_size为负值,转size_t之后可能成为一个很大的正数
##########
src/brpc/stream.cpp:
##########
@@ -72,6 +74,11 @@ int Stream::Create(const StreamOptions &options,
s->_connected = false;
s->_options = options;
s->_closed = false;
+ s->_cur_max_buf_size = options.max_buf_size;
+ if (FLAGS_socket_max_streams_unconsumed_bytes > 0 && options.min_buf_size
> 0) {
Review Comment:
此处应使用s->_options.min_buf_size
--
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]