nghttpx: Use an existing h2 backend connection as much as possible
h2load measurement reveals that this strategy is 3 times faster than the previous implementations.
This commit is contained in:
parent
aaa0b858e4
commit
f507b5eee4
|
@ -804,28 +804,8 @@ bool load_lighter(const DownstreamAddr *lhs, const DownstreamAddr *rhs) {
|
|||
Http2Session *ClientHandler::select_http2_session(
|
||||
const std::shared_ptr<DownstreamAddrGroup> &group) {
|
||||
auto &shared_addr = group->shared_addr;
|
||||
|
||||
// First count the working backend addresses.
|
||||
size_t min = 0;
|
||||
for (const auto &addr : shared_addr->addrs) {
|
||||
if (addr.proto != PROTO_HTTP2 || addr.connect_blocker->blocked()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
++min;
|
||||
}
|
||||
|
||||
if (min == 0) {
|
||||
if (LOG_ENABLED(INFO)) {
|
||||
CLOG(INFO, this) << "No working backend address found";
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto &http2_avail_freelist = shared_addr->http2_avail_freelist;
|
||||
|
||||
if (http2_avail_freelist.size() >= min) {
|
||||
for (auto session = http2_avail_freelist.head; session;) {
|
||||
auto next = session->dlnext;
|
||||
|
||||
|
@ -835,8 +815,8 @@ Http2Session *ClientHandler::select_http2_session(
|
|||
if (session->max_concurrency_reached(0)) {
|
||||
if (LOG_ENABLED(INFO)) {
|
||||
CLOG(INFO, this)
|
||||
<< "Maximum streams have been reached for Http2Session("
|
||||
<< session << "). Skip it";
|
||||
<< "Maximum streams have been reached for Http2Session(" << session
|
||||
<< "). Skip it";
|
||||
}
|
||||
|
||||
session = next;
|
||||
|
@ -859,7 +839,6 @@ Http2Session *ClientHandler::select_http2_session(
|
|||
}
|
||||
return session;
|
||||
}
|
||||
}
|
||||
|
||||
DownstreamAddr *selected_addr = nullptr;
|
||||
|
||||
|
@ -901,7 +880,12 @@ Http2Session *ClientHandler::select_http2_session(
|
|||
}
|
||||
}
|
||||
|
||||
assert(selected_addr);
|
||||
if (selected_addr == nullptr) {
|
||||
if (LOG_ENABLED(INFO)) {
|
||||
CLOG(INFO, this) << "No working backend address found";
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (LOG_ENABLED(INFO)) {
|
||||
CLOG(INFO, this) << "Selected DownstreamAddr=" << selected_addr
|
||||
|
|
Loading…
Reference in New Issue