From 1e8663557262b71b4faa4dea42f2f3d2217ccec3 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Fri, 7 Nov 2014 00:28:10 +0900 Subject: [PATCH] h2load: Make shutdown sequence simpler --- src/h2load.cc | 48 +++++------------------------------------------- src/h2load.h | 6 +----- 2 files changed, 6 insertions(+), 48 deletions(-) diff --git a/src/h2load.cc b/src/h2load.cc index e3dfbcde..d27eeeb4 100644 --- a/src/h2load.cc +++ b/src/h2load.cc @@ -168,10 +168,6 @@ void Client::fail() { process_abandoned_streams(); - if(worker->stats.req_done == worker->stats.req_todo) { - worker->schedule_terminate(); - } - disconnect(); } @@ -215,6 +211,8 @@ void Client::process_abandoned_streams() worker->stats.req_failed += req_abandoned; worker->stats.req_error += req_abandoned; worker->stats.req_done += req_abandoned; + + req_done = req_todo; } void Client::report_progress() @@ -289,8 +287,8 @@ void Client::on_stream_close(int32_t stream_id, bool success) } report_progress(); streams.erase(stream_id); - if(worker->stats.req_done == worker->stats.req_todo) { - worker->schedule_terminate(); + if(req_done == req_todo) { + terminate_session(); return; } @@ -332,7 +330,7 @@ int Client::on_write() Worker::Worker(uint32_t id, SSL_CTX *ssl_ctx, size_t req_todo, size_t nclients, Config *config) : stats{0}, evbase(event_base_new()), ssl_ctx(ssl_ctx), config(config), - term_timer(nullptr), id(id) + id(id) { stats.req_todo = req_todo; progress_interval = std::max((size_t)1, req_todo / 10); @@ -352,9 +350,6 @@ Worker::Worker(uint32_t id, SSL_CTX *ssl_ctx, size_t req_todo, size_t nclients, Worker::~Worker() { - if(term_timer) { - event_free(term_timer); - } event_base_free(evbase); } @@ -369,39 +364,6 @@ void Worker::run() event_base_loop(evbase, 0); } -namespace { -void term_timeout_cb(evutil_socket_t fd, short what, void *arg) -{ - auto worker = static_cast(arg); - worker->terminate_session(); -} -} // namespace - -void Worker::schedule_terminate() -{ - if(term_timer) { - return; - } - - term_timer = evtimer_new(evbase, term_timeout_cb, this); - timeval timeout = { 0, 0 }; - evtimer_add(term_timer, &timeout); -} - -void Worker::terminate_session() -{ - for(auto& client : clients) { - if(client->session == nullptr) { - client->disconnect(); - continue; - } - client->terminate_session(); - if(client->on_write() != 0) { - client->disconnect(); - } - } -} - namespace { void debug_nextproto_error() { diff --git a/src/h2load.h b/src/h2load.h index 15e44d0b..713d30b3 100644 --- a/src/h2load.h +++ b/src/h2load.h @@ -118,7 +118,6 @@ struct Worker { event_base *evbase; SSL_CTX *ssl_ctx; Config *config; - event *term_timer; size_t progress_interval; uint32_t id; @@ -126,8 +125,6 @@ struct Worker { Config *config); ~Worker(); void run(); - void schedule_terminate(); - void terminate_session(); }; struct Stream { @@ -148,8 +145,7 @@ struct Client { size_t req_todo; // The number of requests this client has issued so far. size_t req_started; - // The number of requests this client has issued and got response so - // far. + // The number of requests this client has done so far. size_t req_done; Client(Worker *worker, size_t req_todo);