From 2c1022a3360deb7ede1a4998399d625316017f33 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 b95eb011..d0408f2b 100644 --- a/src/h2load.cc +++ b/src/h2load.cc @@ -212,8 +212,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; }