From 660e1ec44d4cd956fe72fd206c9b6dae0693c7f4 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Sun, 19 Jan 2014 18:07:50 +0900 Subject: [PATCH] nghttpx: Move backend outbuf threshold to each downstream type --- src/shrpx_downstream.h | 2 -- src/shrpx_http2_downstream_connection.cc | 4 ++-- src/shrpx_http2_session.cc | 11 ++++++++++- src/shrpx_http2_session.h | 4 ++++ src/shrpx_http_downstream_connection.cc | 6 +++++- 5 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/shrpx_downstream.h b/src/shrpx_downstream.h index 8536eb28..57f012f1 100644 --- a/src/shrpx_downstream.h +++ b/src/shrpx_downstream.h @@ -199,8 +199,6 @@ public: // Change the priority of downstream int change_priority(int32_t pri); - - static const size_t OUTPUT_UPPER_THRES = 64*1024; private: Headers request_headers_; Headers response_headers_; diff --git a/src/shrpx_http2_downstream_connection.cc b/src/shrpx_http2_downstream_connection.cc index 857fa6be..2700938f 100644 --- a/src/shrpx_http2_downstream_connection.cc +++ b/src/shrpx_http2_downstream_connection.cc @@ -522,8 +522,8 @@ StreamData* Http2DownstreamConnection::detach_stream_data() bool Http2DownstreamConnection::get_output_buffer_full() { if(request_body_buf_) { - return - evbuffer_get_length(request_body_buf_) >= Downstream::OUTPUT_UPPER_THRES; + return http2session_->get_outbuf_length() + + evbuffer_get_length(request_body_buf_) >= Http2Session::OUTBUF_MAX_THRES; } else { return false; } diff --git a/src/shrpx_http2_session.cc b/src/shrpx_http2_session.cc index c7925a24..2b973ec3 100644 --- a/src/shrpx_http2_session.cc +++ b/src/shrpx_http2_session.cc @@ -697,7 +697,7 @@ ssize_t send_callback(nghttp2_session *session, auto bev = http2session->get_bev(); auto output = bufferevent_get_output(bev); // Check buffer length and return WOULDBLOCK if it is large enough. - if(evbuffer_get_length(output) > Downstream::OUTPUT_UPPER_THRES) { + if(evbuffer_get_length(output) > Http2Session::OUTBUF_MAX_THRES) { return NGHTTP2_ERR_WOULDBLOCK; } @@ -1369,4 +1369,13 @@ int Http2Session::terminate_session(nghttp2_error_code error_code) return 0; } +size_t Http2Session::get_outbuf_length() const +{ + if(bev_) { + return evbuffer_get_length(bufferevent_get_output(bev_)); + } else { + return OUTBUF_MAX_THRES; + } +} + } // namespace shrpx diff --git a/src/shrpx_http2_session.h b/src/shrpx_http2_session.h index 2abf7639..0d926112 100644 --- a/src/shrpx_http2_session.h +++ b/src/shrpx_http2_session.h @@ -104,6 +104,8 @@ public: int start_settings_timer(); void stop_settings_timer(); + size_t get_outbuf_length() const; + enum { // Disconnected DISCONNECTED, @@ -118,6 +120,8 @@ public: // Connected to downstream CONNECTED }; + + static const size_t OUTBUF_MAX_THRES = 64*1024; private: std::set dconns_; std::set streams_; diff --git a/src/shrpx_http_downstream_connection.cc b/src/shrpx_http_downstream_connection.cc index 97fcfe48..8ce1ff62 100644 --- a/src/shrpx_http_downstream_connection.cc +++ b/src/shrpx_http_downstream_connection.cc @@ -37,6 +37,10 @@ using namespace nghttp2; namespace shrpx { +namespace { +const size_t OUTBUF_MAX_THRES = 64*1024; +} // namespace + // Workaround for the inability for Bufferevent to remove timeout from // bufferevent. Specify this long timeout instead of removing. namespace { @@ -371,7 +375,7 @@ void HttpDownstreamConnection::force_resume_read() bool HttpDownstreamConnection::get_output_buffer_full() { auto output = bufferevent_get_output(bev_); - return evbuffer_get_length(output) >= Downstream::OUTPUT_UPPER_THRES; + return evbuffer_get_length(output) >= OUTBUF_MAX_THRES; } namespace {