From 0d8c8ca033b73027d737fe5c07d9bdc0c9ce6c06 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Sat, 12 Sep 2015 11:18:54 +0900 Subject: [PATCH] h2load: Record TTFB on first byte of response body, rather than first socket read --- src/h2load.cc | 19 +++++++------------ src/h2load.h | 2 +- src/h2load_http2_session.cc | 4 ++++ src/h2load_spdy_session.cc | 6 ++++++ 4 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/h2load.cc b/src/h2load.cc index 38d43464..9ec18d5d 100644 --- a/src/h2load.cc +++ b/src/h2load.cc @@ -659,11 +659,6 @@ int Client::read_clear() { if (on_read(buf, nread) != 0) { return -1; } - - if (!first_byte_received) { - first_byte_received = true; - record_ttfb(&worker->stats); - } } return 0; @@ -786,11 +781,6 @@ int Client::read_tls() { if (on_read(buf, rv) != 0) { return -1; } - - if (!first_byte_received) { - first_byte_received = true; - record_ttfb(&worker->stats); - } } } @@ -849,8 +839,13 @@ void Client::record_connect_time(Stats *stat) { stat->connect_times.push_back(std::chrono::steady_clock::now()); } -void Client::record_ttfb(Stats *stat) { - stat->ttfbs.push_back(std::chrono::steady_clock::now()); +void Client::record_ttfb() { + if (first_byte_received) { + return; + } + first_byte_received = true; + + worker->stats.ttfbs.push_back(std::chrono::steady_clock::now()); } void Client::signal_write() { ev_io_start(worker->loop, &wev); } diff --git a/src/h2load.h b/src/h2load.h index 07fa2dcb..13363a32 100644 --- a/src/h2load.h +++ b/src/h2load.h @@ -268,7 +268,7 @@ struct Client { void record_request_time(RequestStat *req_stat); void record_start_time(Stats *stat); void record_connect_time(Stats *stat); - void record_ttfb(Stats *stat); + void record_ttfb(); void signal_write(); }; diff --git a/src/h2load_http2_session.cc b/src/h2load_http2_session.cc index 0cbb702d..2b56d115 100644 --- a/src/h2load_http2_session.cc +++ b/src/h2load_http2_session.cc @@ -64,6 +64,9 @@ int on_frame_recv_callback(nghttp2_session *session, const nghttp2_frame *frame, return 0; } client->worker->stats.bytes_head += frame->hd.length; + if (frame->hd.flags & NGHTTP2_FLAG_END_STREAM) { + client->record_ttfb(); + } return 0; } } // namespace @@ -73,6 +76,7 @@ int on_data_chunk_recv_callback(nghttp2_session *session, uint8_t flags, int32_t stream_id, const uint8_t *data, size_t len, void *user_data) { auto client = static_cast(user_data); + client->record_ttfb(); client->worker->stats.bytes_body += len; return 0; } diff --git a/src/h2load_spdy_session.cc b/src/h2load_spdy_session.cc index 60258b76..9700a518 100644 --- a/src/h2load_spdy_session.cc +++ b/src/h2load_spdy_session.cc @@ -70,6 +70,10 @@ void on_ctrl_recv_callback(spdylay_session *session, spdylay_frame_type type, reinterpret_cast(value), strlen(value)); } client->worker->stats.bytes_head += frame->syn_reply.hd.length; + + if (frame->syn_stream.hd.flags & SPDYLAY_CTRL_FLAG_FIN) { + client->record_ttfb(); + } } } // namespace @@ -78,6 +82,8 @@ void on_data_chunk_recv_callback(spdylay_session *session, uint8_t flags, int32_t stream_id, const uint8_t *data, size_t len, void *user_data) { auto client = static_cast(user_data); + + client->record_ttfb(); client->worker->stats.bytes_body += len; auto spdy_session = static_cast(client->session.get());