nghttpx: Move backend outbuf threshold to each downstream type

This commit is contained in:
Tatsuhiro Tsujikawa 2014-01-19 18:07:50 +09:00
parent a37bc88f40
commit 660e1ec44d
5 changed files with 21 additions and 6 deletions

View File

@ -199,8 +199,6 @@ public:
// Change the priority of downstream // Change the priority of downstream
int change_priority(int32_t pri); int change_priority(int32_t pri);
static const size_t OUTPUT_UPPER_THRES = 64*1024;
private: private:
Headers request_headers_; Headers request_headers_;
Headers response_headers_; Headers response_headers_;

View File

@ -522,8 +522,8 @@ StreamData* Http2DownstreamConnection::detach_stream_data()
bool Http2DownstreamConnection::get_output_buffer_full() bool Http2DownstreamConnection::get_output_buffer_full()
{ {
if(request_body_buf_) { if(request_body_buf_) {
return return http2session_->get_outbuf_length() +
evbuffer_get_length(request_body_buf_) >= Downstream::OUTPUT_UPPER_THRES; evbuffer_get_length(request_body_buf_) >= Http2Session::OUTBUF_MAX_THRES;
} else { } else {
return false; return false;
} }

View File

@ -697,7 +697,7 @@ ssize_t send_callback(nghttp2_session *session,
auto bev = http2session->get_bev(); auto bev = http2session->get_bev();
auto output = bufferevent_get_output(bev); auto output = bufferevent_get_output(bev);
// Check buffer length and return WOULDBLOCK if it is large enough. // 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; return NGHTTP2_ERR_WOULDBLOCK;
} }
@ -1369,4 +1369,13 @@ int Http2Session::terminate_session(nghttp2_error_code error_code)
return 0; 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 } // namespace shrpx

View File

@ -104,6 +104,8 @@ public:
int start_settings_timer(); int start_settings_timer();
void stop_settings_timer(); void stop_settings_timer();
size_t get_outbuf_length() const;
enum { enum {
// Disconnected // Disconnected
DISCONNECTED, DISCONNECTED,
@ -118,6 +120,8 @@ public:
// Connected to downstream // Connected to downstream
CONNECTED CONNECTED
}; };
static const size_t OUTBUF_MAX_THRES = 64*1024;
private: private:
std::set<Http2DownstreamConnection*> dconns_; std::set<Http2DownstreamConnection*> dconns_;
std::set<StreamData*> streams_; std::set<StreamData*> streams_;

View File

@ -37,6 +37,10 @@ using namespace nghttp2;
namespace shrpx { namespace shrpx {
namespace {
const size_t OUTBUF_MAX_THRES = 64*1024;
} // namespace
// Workaround for the inability for Bufferevent to remove timeout from // Workaround for the inability for Bufferevent to remove timeout from
// bufferevent. Specify this long timeout instead of removing. // bufferevent. Specify this long timeout instead of removing.
namespace { namespace {
@ -371,7 +375,7 @@ void HttpDownstreamConnection::force_resume_read()
bool HttpDownstreamConnection::get_output_buffer_full() bool HttpDownstreamConnection::get_output_buffer_full()
{ {
auto output = bufferevent_get_output(bev_); auto output = bufferevent_get_output(bev_);
return evbuffer_get_length(output) >= Downstream::OUTPUT_UPPER_THRES; return evbuffer_get_length(output) >= OUTBUF_MAX_THRES;
} }
namespace { namespace {