Measure the number of UDP datagrams sent and received

This commit is contained in:
Tatsuhiro Tsujikawa 2021-02-23 17:39:38 +09:00
parent 0362bd6e00
commit fadedc46f8
3 changed files with 41 additions and 24 deletions

View File

@ -160,7 +160,9 @@ Stats::Stats(size_t req_todo, size_t nclients)
bytes_head(0), bytes_head(0),
bytes_head_decomp(0), bytes_head_decomp(0),
bytes_body(0), bytes_body(0),
status() {} status(),
udp_dgram_recv(0),
udp_dgram_sent(0) {}
Stream::Stream() : req_stat{}, status_success(-1) {} Stream::Stream() : req_stat{}, status_success(-1) {}
@ -1377,6 +1379,8 @@ int Client::write_udp(const sockaddr *addr, socklen_t addrlen,
auto nwrite = sendto(fd, data, datalen, MSG_DONTWAIT, addr, addrlen); auto nwrite = sendto(fd, data, datalen, MSG_DONTWAIT, addr, addrlen);
if (nwrite < 0) { if (nwrite < 0) {
std::cerr << "sendto: errno=" << errno << std::endl; std::cerr << "sendto: errno=" << errno << std::endl;
} else {
++worker->stats.udp_dgram_sent;
} }
ev_io_stop(worker->loop, &wev); ev_io_stop(worker->loop, &wev);
@ -2971,6 +2975,8 @@ int main(int argc, char **argv) {
stats.bytes_head += s.bytes_head; stats.bytes_head += s.bytes_head;
stats.bytes_head_decomp += s.bytes_head_decomp; stats.bytes_head_decomp += s.bytes_head_decomp;
stats.bytes_body += s.bytes_body; stats.bytes_body += s.bytes_body;
stats.udp_dgram_recv += s.udp_dgram_recv;
stats.udp_dgram_sent += s.udp_dgram_sent;
for (size_t i = 0; i < stats.status.size(); ++i) { for (size_t i = 0; i < stats.status.size(); ++i) {
stats.status[i] += s.status[i]; stats.status[i] += s.status[i];
@ -3029,30 +3035,35 @@ traffic: )" << util::utos_funit(stats.bytes_total)
<< util::utos_funit(stats.bytes_head) << "B (" << stats.bytes_head << util::utos_funit(stats.bytes_head) << "B (" << stats.bytes_head
<< ") headers (space savings " << header_space_savings * 100 << ") headers (space savings " << header_space_savings * 100
<< "%), " << util::utos_funit(stats.bytes_body) << "B (" << "%), " << util::utos_funit(stats.bytes_body) << "B ("
<< stats.bytes_body << R"() data << stats.bytes_body << R"() data)" << std::endl;
min max mean sd +/- sd if (config.is_quic()) {
std::cout << "UDP datagram: " << stats.udp_dgram_sent << " sent, "
<< stats.udp_dgram_recv << " received" << std::endl;
}
std::cout
<< R"( min max mean sd +/- sd
time for request: )" time for request: )"
<< std::setw(10) << util::format_duration(ts.request.min) << " " << std::setw(10) << util::format_duration(ts.request.min) << " "
<< std::setw(10) << util::format_duration(ts.request.max) << " " << std::setw(10) << util::format_duration(ts.request.max) << " "
<< std::setw(10) << util::format_duration(ts.request.mean) << " " << std::setw(10) << util::format_duration(ts.request.mean) << " "
<< std::setw(10) << util::format_duration(ts.request.sd) << std::setw(10) << util::format_duration(ts.request.sd) << std::setw(9)
<< std::setw(9) << util::dtos(ts.request.within_sd) << "%" << util::dtos(ts.request.within_sd) << "%"
<< "\ntime for connect: " << std::setw(10) << "\ntime for connect: " << std::setw(10)
<< util::format_duration(ts.connect.min) << " " << std::setw(10) << util::format_duration(ts.connect.min) << " " << std::setw(10)
<< util::format_duration(ts.connect.max) << " " << std::setw(10) << util::format_duration(ts.connect.max) << " " << std::setw(10)
<< util::format_duration(ts.connect.mean) << " " << std::setw(10) << util::format_duration(ts.connect.mean) << " " << std::setw(10)
<< util::format_duration(ts.connect.sd) << std::setw(9) << util::format_duration(ts.connect.sd) << std::setw(9)
<< util::dtos(ts.connect.within_sd) << "%" << util::dtos(ts.connect.within_sd) << "%"
<< "\ntime to 1st byte: " << std::setw(10) << "\ntime to 1st byte: " << std::setw(10)
<< util::format_duration(ts.ttfb.min) << " " << std::setw(10) << util::format_duration(ts.ttfb.min) << " " << std::setw(10)
<< util::format_duration(ts.ttfb.max) << " " << std::setw(10) << util::format_duration(ts.ttfb.max) << " " << std::setw(10)
<< util::format_duration(ts.ttfb.mean) << " " << std::setw(10) << util::format_duration(ts.ttfb.mean) << " " << std::setw(10)
<< util::format_duration(ts.ttfb.sd) << std::setw(9) << util::format_duration(ts.ttfb.sd) << std::setw(9)
<< util::dtos(ts.ttfb.within_sd) << "%" << util::dtos(ts.ttfb.within_sd) << "%"
<< "\nreq/s : " << std::setw(10) << ts.rps.min << " " << "\nreq/s : " << std::setw(10) << ts.rps.min << " "
<< std::setw(10) << ts.rps.max << " " << std::setw(10) << std::setw(10) << ts.rps.max << " " << std::setw(10) << ts.rps.mean
<< ts.rps.mean << " " << std::setw(10) << ts.rps.sd << std::setw(9) << " " << std::setw(10) << ts.rps.sd << std::setw(9)
<< util::dtos(ts.rps.within_sd) << "%" << std::endl; << util::dtos(ts.rps.within_sd) << "%" << std::endl;
SSL_CTX_free(ssl_ctx); SSL_CTX_free(ssl_ctx);

View File

@ -230,6 +230,10 @@ struct Stats {
std::vector<RequestStat> req_stats; std::vector<RequestStat> req_stats;
// The statistics per client // The statistics per client
std::vector<ClientStat> client_stats; std::vector<ClientStat> client_stats;
// The number of UDP datagrams received.
size_t udp_dgram_recv;
// The number of UDP datagrams sent.
size_t udp_dgram_sent;
}; };
enum ClientState { CLIENT_IDLE, CLIENT_CONNECTED }; enum ClientState { CLIENT_IDLE, CLIENT_CONNECTED };

View File

@ -524,6 +524,8 @@ int Client::read_quic() {
assert(quic.conn); assert(quic.conn);
++worker->stats.udp_dgram_recv;
auto path = ngtcp2_path{ auto path = ngtcp2_path{
{local_addr.len, &local_addr.su.sa}, {local_addr.len, &local_addr.su.sa},
{addrlen, &su.sa}, {addrlen, &su.sa},