Commit 3f80472e authored by Tatsuhiro Tsujikawa's avatar Tatsuhiro Tsujikawa

nghttpx: Minor tweak to buffer size

Simplified when to send WINDOW_UPDATE to the backend, that is we send
WINDOW_UPDATE when input buffer is empty.
parent ec30af91
......@@ -47,6 +47,7 @@ namespace shrpx {
namespace {
const size_t OUTBUF_MAX_THRES = 64*1024;
const size_t INBUF_MAX_THRES = 64*1024;
} // namespace
namespace {
......@@ -610,8 +611,8 @@ int Http2Upstream::send()
auto output = bufferevent_get_output(bev);
util::EvbufferBuffer evbbuf(output, buf, sizeof(buf));
for(;;) {
// Check buffer length and return WOULDBLOCK if it is large enough.
if(handler_->get_outbuf_length() + evbbuf.get_buflen() >
// Check buffer length and break if it is large enough.
if(handler_->get_outbuf_length() + evbbuf.get_buflen() >=
OUTBUF_MAX_THRES) {
break;
}
......@@ -903,7 +904,6 @@ ssize_t downstream_data_read_callback(nghttp2_session *session,
{
auto downstream = static_cast<Downstream*>(source->ptr);
auto upstream = static_cast<Http2Upstream*>(downstream->get_upstream());
auto handler = upstream->get_client_handler();
auto body = downstream->get_response_body_buf();
assert(body);
......@@ -927,16 +927,12 @@ ssize_t downstream_data_read_callback(nghttp2_session *session,
(downstream->get_response_rst_stream_error_code()));
}
}
// Send WINDOW_UPDATE before buffer is empty to avoid delay because
// of RTT.
if(((*data_flags) & NGHTTP2_DATA_FLAG_EOF) == 0 &&
handler->get_outbuf_length() + evbuffer_get_length(body) <
OUTBUF_MAX_THRES) {
if(nread == 0 && ((*data_flags) & NGHTTP2_DATA_FLAG_EOF) == 0) {
if(downstream->resume_read(SHRPX_NO_BUFFER) != 0) {
return NGHTTP2_ERR_CALLBACK_FAILURE;
}
}
if(nread == 0 && ((*data_flags) & NGHTTP2_DATA_FLAG_EOF) == 0) {
return NGHTTP2_ERR_DEFERRED;
}
return nread;
......@@ -1105,8 +1101,6 @@ int Http2Upstream::on_downstream_body(Downstream *downstream,
const uint8_t *data, size_t len,
bool flush)
{
auto upstream = downstream->get_upstream();
auto handler = upstream->get_client_handler();
auto body = downstream->get_response_body_buf();
int rv = evbuffer_add(body, data, len);
if(rv != 0) {
......@@ -1118,9 +1112,7 @@ int Http2Upstream::on_downstream_body(Downstream *downstream,
nghttp2_session_resume_data(session_, downstream->get_stream_id());
}
auto outbuflen = handler->get_outbuf_length() +
evbuffer_get_length(body);
if(outbuflen > OUTBUF_MAX_THRES) {
if(evbuffer_get_length(body) >= INBUF_MAX_THRES) {
if(!flush) {
nghttp2_session_resume_data(session_, downstream->get_stream_id());
}
......
......@@ -405,6 +405,8 @@ void https_downstream_readcb(bufferevent *bev, void *ptr)
if(downstream->get_response_state() == Downstream::MSG_RESET) {
delete upstream->get_client_handler();
} else if(rv == 0) {
auto handler = upstream->get_client_handler();
if(downstream->get_response_state() == Downstream::MSG_COMPLETE) {
if(downstream->get_response_connection_close()) {
// Connection close
......@@ -415,7 +417,6 @@ void https_downstream_readcb(bufferevent *bev, void *ptr)
// Keep-alive
dconn->detach_downstream(downstream);
}
auto handler = upstream->get_client_handler();
if(downstream->get_request_state() == Downstream::MSG_COMPLETE) {
if(handler->get_should_close_after_write() &&
handler->get_outbuf_length() == 0) {
......@@ -450,8 +451,7 @@ void https_downstream_readcb(bufferevent *bev, void *ptr)
}
}
} else {
if(upstream->get_client_handler()->get_outbuf_length() >
OUTBUF_MAX_THRES) {
if(handler->get_outbuf_length() >= OUTBUF_MAX_THRES) {
downstream->pause_read(SHRPX_NO_BUFFER);
}
}
......
......@@ -46,6 +46,7 @@ namespace shrpx {
namespace {
const size_t OUTBUF_MAX_THRES = 64*1024;
const size_t INBUF_MAX_THRES = 64*1024;
} // namespace
namespace {
......@@ -58,7 +59,7 @@ ssize_t send_callback(spdylay_session *session,
auto handler = upstream->get_client_handler();
// Check buffer length and return WOULDBLOCK if it is large enough.
if(handler->get_outbuf_length() + upstream->sendbuf.get_buflen() >
if(handler->get_outbuf_length() + upstream->sendbuf.get_buflen() >=
OUTBUF_MAX_THRES) {
return SPDYLAY_ERR_WOULDBLOCK;
}
......@@ -725,7 +726,6 @@ ssize_t spdy_data_read_callback(spdylay_session *session,
{
auto downstream = static_cast<Downstream*>(source->ptr);
auto upstream = static_cast<SpdyUpstream*>(downstream->get_upstream());
auto handler = upstream->get_client_handler();
auto body = downstream->get_response_body_buf();
assert(body);
int nread = evbuffer_remove(body, buf, length);
......@@ -747,18 +747,15 @@ ssize_t spdy_data_read_callback(spdylay_session *session,
(downstream->get_response_rst_stream_error_code()));
}
}
// Send WINDOW_UPDATE before buffer is empty to avoid delay because
// of RTT.
if(*eof != 1 &&
handler->get_outbuf_length() + evbuffer_get_length(body) <
OUTBUF_MAX_THRES) {
if(nread == 0 && *eof != 1) {
if(downstream->resume_read(SHRPX_NO_BUFFER) != 0) {
return SPDYLAY_ERR_CALLBACK_FAILURE;
}
}
if(nread == 0 && *eof != 1) {
return SPDYLAY_ERR_DEFERRED;
}
return nread;
}
} // namespace
......@@ -930,7 +927,6 @@ int SpdyUpstream::on_downstream_body(Downstream *downstream,
const uint8_t *data, size_t len,
bool flush)
{
auto upstream = downstream->get_upstream();
auto body = downstream->get_response_body_buf();
int rv = evbuffer_add(body, data, len);
if(rv != 0) {
......@@ -942,9 +938,7 @@ int SpdyUpstream::on_downstream_body(Downstream *downstream,
spdylay_session_resume_data(session_, downstream->get_stream_id());
}
auto outbuflen = upstream->get_client_handler()->get_outbuf_length() +
evbuffer_get_length(body);
if(outbuflen > OUTBUF_MAX_THRES) {
if(evbuffer_get_length(body) >= INBUF_MAX_THRES) {
if(!flush) {
spdylay_session_resume_data(session_, downstream->get_stream_id());
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment