From a93eb8b8f55209080584b74ff765bea743328ec6 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Wed, 20 Nov 2019 23:40:51 +0900 Subject: [PATCH] Optimize QUIC write --- src/h2load.cc | 3 +-- src/h2load_quic.cc | 41 +++++++++++++++++++++++------------------ 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/src/h2load.cc b/src/h2load.cc index ebb7ec24..2deb21ef 100644 --- a/src/h2load.cc +++ b/src/h2load.cc @@ -214,8 +214,7 @@ void readcb(struct ev_loop *loop, ev_io *w, int revents) { delete client; return; } - writecb(loop, &client->wev, revents); - // client->disconnect() and client->fail() may be called + client->signal_write(); } } // namespace diff --git a/src/h2load_quic.cc b/src/h2load_quic.cc index d81ca340..5f69d278 100644 --- a/src/h2load_quic.cc +++ b/src/h2load_quic.cc @@ -601,35 +601,40 @@ int Client::read_quic() { sockaddr_union su; socklen_t addrlen = sizeof(su); int rv; + size_t pktcnt = 0; - auto nread = - recvfrom(fd, buf.data(), buf.size(), MSG_DONTWAIT, &su.sa, &addrlen); - if (nread == -1) { - return 0; - } + for (;;) { + auto nread = + recvfrom(fd, buf.data(), buf.size(), MSG_DONTWAIT, &su.sa, &addrlen); + if (nread == -1) { + return 0; + } - assert(quic.conn); + assert(quic.conn); - auto path = ngtcp2_path{ - {local_addr.len, reinterpret_cast(&local_addr.su.sa)}, - {addrlen, reinterpret_cast(&su.sa)}, - }; + auto path = ngtcp2_path{ + {local_addr.len, reinterpret_cast(&local_addr.su.sa)}, + {addrlen, reinterpret_cast(&su.sa)}, + }; - rv = ngtcp2_conn_read_pkt(quic.conn, &path, buf.data(), nread, - timestamp(worker->loop)); - if (rv != 0) { - std::cerr << "ngtcp2_conn_read_pkt: " << ngtcp2_strerror(rv) << std::endl; - return -1; - } + rv = ngtcp2_conn_read_pkt(quic.conn, &path, buf.data(), nread, + timestamp(worker->loop)); + if (rv != 0) { + std::cerr << "ngtcp2_conn_read_pkt: " << ngtcp2_strerror(rv) << std::endl; + return -1; + } - if (worker->current_phase == Phase::MAIN_DURATION) { - worker->stats.bytes_total += nread; + if (pktcnt == 10) { + break; + } } return 0; } int Client::write_quic() { + ev_io_stop(worker->loop, &wev); + if (quic.close_requested) { return -1; }