h2load: Make shutdown sequence simpler
This commit is contained in:
parent
62ede05c09
commit
1e86635572
|
@ -168,10 +168,6 @@ void Client::fail()
|
||||||
{
|
{
|
||||||
process_abandoned_streams();
|
process_abandoned_streams();
|
||||||
|
|
||||||
if(worker->stats.req_done == worker->stats.req_todo) {
|
|
||||||
worker->schedule_terminate();
|
|
||||||
}
|
|
||||||
|
|
||||||
disconnect();
|
disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -215,6 +211,8 @@ void Client::process_abandoned_streams()
|
||||||
worker->stats.req_failed += req_abandoned;
|
worker->stats.req_failed += req_abandoned;
|
||||||
worker->stats.req_error += req_abandoned;
|
worker->stats.req_error += req_abandoned;
|
||||||
worker->stats.req_done += req_abandoned;
|
worker->stats.req_done += req_abandoned;
|
||||||
|
|
||||||
|
req_done = req_todo;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Client::report_progress()
|
void Client::report_progress()
|
||||||
|
@ -289,8 +287,8 @@ void Client::on_stream_close(int32_t stream_id, bool success)
|
||||||
}
|
}
|
||||||
report_progress();
|
report_progress();
|
||||||
streams.erase(stream_id);
|
streams.erase(stream_id);
|
||||||
if(worker->stats.req_done == worker->stats.req_todo) {
|
if(req_done == req_todo) {
|
||||||
worker->schedule_terminate();
|
terminate_session();
|
||||||
return;
|
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,
|
Worker::Worker(uint32_t id, SSL_CTX *ssl_ctx, size_t req_todo, size_t nclients,
|
||||||
Config *config)
|
Config *config)
|
||||||
: stats{0}, evbase(event_base_new()), ssl_ctx(ssl_ctx), 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;
|
stats.req_todo = req_todo;
|
||||||
progress_interval = std::max((size_t)1, req_todo / 10);
|
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()
|
Worker::~Worker()
|
||||||
{
|
{
|
||||||
if(term_timer) {
|
|
||||||
event_free(term_timer);
|
|
||||||
}
|
|
||||||
event_base_free(evbase);
|
event_base_free(evbase);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -369,39 +364,6 @@ void Worker::run()
|
||||||
event_base_loop(evbase, 0);
|
event_base_loop(evbase, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace {
|
|
||||||
void term_timeout_cb(evutil_socket_t fd, short what, void *arg)
|
|
||||||
{
|
|
||||||
auto worker = static_cast<Worker*>(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 {
|
namespace {
|
||||||
void debug_nextproto_error()
|
void debug_nextproto_error()
|
||||||
{
|
{
|
||||||
|
|
|
@ -118,7 +118,6 @@ struct Worker {
|
||||||
event_base *evbase;
|
event_base *evbase;
|
||||||
SSL_CTX *ssl_ctx;
|
SSL_CTX *ssl_ctx;
|
||||||
Config *config;
|
Config *config;
|
||||||
event *term_timer;
|
|
||||||
size_t progress_interval;
|
size_t progress_interval;
|
||||||
uint32_t id;
|
uint32_t id;
|
||||||
|
|
||||||
|
@ -126,8 +125,6 @@ struct Worker {
|
||||||
Config *config);
|
Config *config);
|
||||||
~Worker();
|
~Worker();
|
||||||
void run();
|
void run();
|
||||||
void schedule_terminate();
|
|
||||||
void terminate_session();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Stream {
|
struct Stream {
|
||||||
|
@ -148,8 +145,7 @@ struct Client {
|
||||||
size_t req_todo;
|
size_t req_todo;
|
||||||
// The number of requests this client has issued so far.
|
// The number of requests this client has issued so far.
|
||||||
size_t req_started;
|
size_t req_started;
|
||||||
// The number of requests this client has issued and got response so
|
// The number of requests this client has done so far.
|
||||||
// far.
|
|
||||||
size_t req_done;
|
size_t req_done;
|
||||||
|
|
||||||
Client(Worker *worker, size_t req_todo);
|
Client(Worker *worker, size_t req_todo);
|
||||||
|
|
Loading…
Reference in New Issue