h2load: Record TTFB on first byte of response body, rather than first socket read

This commit is contained in:
Tatsuhiro Tsujikawa 2015-09-12 11:18:54 +09:00
parent 5ea90ba6bd
commit 0d8c8ca033
4 changed files with 18 additions and 13 deletions

View File

@ -659,11 +659,6 @@ int Client::read_clear() {
if (on_read(buf, nread) != 0) { if (on_read(buf, nread) != 0) {
return -1; return -1;
} }
if (!first_byte_received) {
first_byte_received = true;
record_ttfb(&worker->stats);
}
} }
return 0; return 0;
@ -786,11 +781,6 @@ int Client::read_tls() {
if (on_read(buf, rv) != 0) { if (on_read(buf, rv) != 0) {
return -1; 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()); stat->connect_times.push_back(std::chrono::steady_clock::now());
} }
void Client::record_ttfb(Stats *stat) { void Client::record_ttfb() {
stat->ttfbs.push_back(std::chrono::steady_clock::now()); 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); } void Client::signal_write() { ev_io_start(worker->loop, &wev); }

View File

@ -268,7 +268,7 @@ struct Client {
void record_request_time(RequestStat *req_stat); void record_request_time(RequestStat *req_stat);
void record_start_time(Stats *stat); void record_start_time(Stats *stat);
void record_connect_time(Stats *stat); void record_connect_time(Stats *stat);
void record_ttfb(Stats *stat); void record_ttfb();
void signal_write(); void signal_write();
}; };

View File

@ -64,6 +64,9 @@ int on_frame_recv_callback(nghttp2_session *session, const nghttp2_frame *frame,
return 0; return 0;
} }
client->worker->stats.bytes_head += frame->hd.length; client->worker->stats.bytes_head += frame->hd.length;
if (frame->hd.flags & NGHTTP2_FLAG_END_STREAM) {
client->record_ttfb();
}
return 0; return 0;
} }
} // namespace } // 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, int32_t stream_id, const uint8_t *data,
size_t len, void *user_data) { size_t len, void *user_data) {
auto client = static_cast<Client *>(user_data); auto client = static_cast<Client *>(user_data);
client->record_ttfb();
client->worker->stats.bytes_body += len; client->worker->stats.bytes_body += len;
return 0; return 0;
} }

View File

@ -70,6 +70,10 @@ void on_ctrl_recv_callback(spdylay_session *session, spdylay_frame_type type,
reinterpret_cast<const uint8_t *>(value), strlen(value)); reinterpret_cast<const uint8_t *>(value), strlen(value));
} }
client->worker->stats.bytes_head += frame->syn_reply.hd.length; client->worker->stats.bytes_head += frame->syn_reply.hd.length;
if (frame->syn_stream.hd.flags & SPDYLAY_CTRL_FLAG_FIN) {
client->record_ttfb();
}
} }
} // namespace } // 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, int32_t stream_id, const uint8_t *data,
size_t len, void *user_data) { size_t len, void *user_data) {
auto client = static_cast<Client *>(user_data); auto client = static_cast<Client *>(user_data);
client->record_ttfb();
client->worker->stats.bytes_body += len; client->worker->stats.bytes_body += len;
auto spdy_session = static_cast<SpdySession *>(client->session.get()); auto spdy_session = static_cast<SpdySession *>(client->session.get());