From 53989dc70c7070203076a073b5e563fc6f0e44b4 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Sat, 2 Apr 2016 00:02:48 +0900 Subject: [PATCH] nghttpx: Better distribute load to backend h2 servers --- src/shrpx_client_handler.cc | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/shrpx_client_handler.cc b/src/shrpx_client_handler.cc index a84e5c0b..29b55e48 100644 --- a/src/shrpx_client_handler.cc +++ b/src/shrpx_client_handler.cc @@ -737,6 +737,8 @@ ClientHandler::get_downstream_connection(Downstream *downstream) { if (shared_addr->proto == PROTO_HTTP2) { auto &http2_freelist = shared_addr->http2_freelist; + Http2Session *http2session; + if (http2_freelist.empty() || http2_freelist.size() < shared_addr->addrs.size()) { if (LOG_ENABLED(INFO)) { @@ -749,21 +751,22 @@ ClientHandler::get_downstream_connection(Downstream *downstream) { << shared_addr->addrs.size(); } } - auto session = make_unique( + http2session = new Http2Session( conn_.loop, shared_addr->tls ? worker_->get_cl_ssl_ctx() : nullptr, worker_, &group); - http2_freelist.append(session.release()); + } else { + http2session = http2_freelist.head; + http2_freelist.remove(http2session); } - auto http2session = http2_freelist.head; - if (http2session->max_concurrency_reached(1)) { if (LOG_ENABLED(INFO)) { CLOG(INFO, this) << "Maximum streams are reached for Http2Session(" << http2session << "). Remove Http2Session from http2_freelist"; } - http2_freelist.remove(http2session); + } else { + http2_freelist.append(http2session); } dconn = make_unique(http2session);