From 23ac0429bedc589633a4b26b012b8108081bfde3 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Tue, 5 Jan 2016 23:56:31 +0900 Subject: [PATCH] h2load: Show progress in rate mode --- src/h2load.cc | 36 +++++++++++++++++++++++++----------- src/h2load.h | 3 ++- 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/src/h2load.cc b/src/h2load.cc index 6403a783..8c980efb 100644 --- a/src/h2load.cc +++ b/src/h2load.cc @@ -173,6 +173,7 @@ void rate_period_timeout_w_cb(struct ev_loop *loop, ev_timer *w, int revents) { } else { client.release(); } + worker->report_rate_progress(); } if (worker->nconns_made >= worker->nclients) { ev_timer_stop(worker->loop, w); @@ -484,15 +485,6 @@ void Client::process_request_failure() { } } -void Client::report_progress() { - if (!worker->config->is_rate_mode() && worker->id == 0 && - worker->stats.req_done % worker->progress_interval == 0) { - std::cout << "progress: " - << worker->stats.req_done * 100 / worker->stats.req_todo - << "% done" << std::endl; - } -} - namespace { void print_server_tmp_key(SSL *ssl) { // libressl does not have SSL_get_server_tmp_key @@ -647,7 +639,7 @@ void Client::on_stream_close(int32_t stream_id, bool success, bool final) { worker->sample_req_stat(req_stat); } - report_progress(); + worker->report_progress(); streams.erase(stream_id); if (req_done == req_todo) { terminate_session(); @@ -1070,7 +1062,11 @@ Worker::Worker(uint32_t id, SSL_CTX *ssl_ctx, size_t req_todo, size_t nclients, nreqs_per_client(req_todo / nclients), nreqs_rem(req_todo % nclients), rate(rate), next_client_id(0) { stats.req_todo = req_todo; - progress_interval = std::max(static_cast(1), req_todo / 10); + if (!config->is_rate_mode()) { + progress_interval = std::max(static_cast(1), req_todo / 10); + } else { + progress_interval = std::max(static_cast(1), nclients / 10); + } // create timer that will go off every rate_period ev_timer_init(&timeout_watcher, rate_period_timeout_w_cb, 0., @@ -1117,6 +1113,24 @@ void Worker::sample_req_stat(RequestStat *req_stat) { assert(stats.req_stats.size() <= MAX_STATS); } +void Worker::report_progress() { + if (id != 0 || config->is_rate_mode() || stats.req_done % progress_interval) { + return; + } + + std::cout << "progress: " << stats.req_done * 100 / stats.req_todo << "% done" + << std::endl; +} + +void Worker::report_rate_progress() { + if (id != 0 || nconns_made % progress_interval) { + return; + } + + std::cout << "progress: " << nconns_made * 100 / nclients + << "% of clients started" << std::endl; +} + namespace { // Returns percentage of number of samples within mean +/- sd. double within_sd(const std::vector &samples, double mean, double sd) { diff --git a/src/h2load.h b/src/h2load.h index 2c4ad997..7910bf66 100644 --- a/src/h2load.h +++ b/src/h2load.h @@ -238,6 +238,8 @@ struct Worker { Worker(Worker &&o) = default; void run(); void sample_req_stat(RequestStat *req_stat); + void report_progress(); + void report_rate_progress(); }; struct Stream { @@ -292,7 +294,6 @@ struct Client { void process_request_failure(); void process_timedout_streams(); void process_abandoned_streams(); - void report_progress(); void report_tls_info(); void report_app_info(); void terminate_session();