2014-02-28 01:10:42 +01:00
|
|
|
/*
|
2014-03-30 12:09:21 +02:00
|
|
|
* nghttp2 - HTTP/2 C Library
|
2014-02-28 01:10:42 +01:00
|
|
|
*
|
|
|
|
* Copyright (c) 2014 Tatsuhiro Tsujikawa
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining
|
|
|
|
* a copy of this software and associated documentation files (the
|
|
|
|
* "Software"), to deal in the Software without restriction, including
|
|
|
|
* without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
|
|
* permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
* the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be
|
|
|
|
* included in all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
|
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
|
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
|
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
#include "h2load.h"
|
|
|
|
|
|
|
|
#include <getopt.h>
|
|
|
|
#include <signal.h>
|
2015-05-13 15:30:35 +02:00
|
|
|
#ifdef HAVE_NETINET_IN_H
|
2018-06-09 09:21:30 +02:00
|
|
|
# include <netinet/in.h>
|
2015-05-13 15:30:35 +02:00
|
|
|
#endif // HAVE_NETINET_IN_H
|
2014-02-28 01:10:42 +01:00
|
|
|
#include <netinet/tcp.h>
|
2015-03-26 11:53:42 +01:00
|
|
|
#include <sys/stat.h>
|
2015-05-13 15:30:35 +02:00
|
|
|
#ifdef HAVE_FCNTL_H
|
2018-06-09 09:21:30 +02:00
|
|
|
# include <fcntl.h>
|
2015-05-13 15:30:35 +02:00
|
|
|
#endif // HAVE_FCNTL_H
|
2014-02-28 01:10:42 +01:00
|
|
|
|
|
|
|
#include <cstdio>
|
|
|
|
#include <cassert>
|
|
|
|
#include <cstdlib>
|
|
|
|
#include <iostream>
|
2015-01-31 10:13:07 +01:00
|
|
|
#include <iomanip>
|
2014-10-20 22:59:55 +02:00
|
|
|
#include <fstream>
|
2014-02-28 01:10:42 +01:00
|
|
|
#include <chrono>
|
2014-03-03 17:12:11 +01:00
|
|
|
#include <thread>
|
2014-05-26 16:29:28 +02:00
|
|
|
#include <future>
|
2016-01-06 14:43:09 +01:00
|
|
|
#include <random>
|
2014-02-28 01:10:42 +01:00
|
|
|
|
|
|
|
#include <openssl/err.h>
|
|
|
|
|
2019-06-08 15:05:25 +02:00
|
|
|
#include <ngtcp2/ngtcp2.h>
|
|
|
|
|
2018-11-23 12:44:36 +01:00
|
|
|
#include "url-parser/url_parser.h"
|
2014-02-28 01:10:42 +01:00
|
|
|
|
2015-09-14 15:33:48 +02:00
|
|
|
#include "h2load_http1_session.h"
|
2014-02-28 01:10:42 +01:00
|
|
|
#include "h2load_http2_session.h"
|
2019-06-08 15:05:25 +02:00
|
|
|
#include "h2load_http3_session.h"
|
|
|
|
#include "h2load_quic.h"
|
2017-04-01 07:47:36 +02:00
|
|
|
#include "tls.h"
|
2014-02-28 01:10:42 +01:00
|
|
|
#include "http2.h"
|
|
|
|
#include "util.h"
|
2015-02-05 15:21:53 +01:00
|
|
|
#include "template.h"
|
2014-02-28 01:10:42 +01:00
|
|
|
|
2015-03-26 11:53:42 +01:00
|
|
|
#ifndef O_BINARY
|
2018-06-09 09:21:30 +02:00
|
|
|
# define O_BINARY (0)
|
2015-03-26 11:53:42 +01:00
|
|
|
#endif // O_BINARY
|
|
|
|
|
2014-02-28 01:10:42 +01:00
|
|
|
using namespace nghttp2;
|
|
|
|
|
|
|
|
namespace h2load {
|
|
|
|
|
2015-12-01 14:29:30 +01:00
|
|
|
namespace {
|
|
|
|
bool recorded(const std::chrono::steady_clock::time_point &t) {
|
|
|
|
return std::chrono::steady_clock::duration::zero() != t.time_since_epoch();
|
|
|
|
}
|
|
|
|
} // namespace
|
|
|
|
|
2014-02-28 01:10:42 +01:00
|
|
|
Config::Config()
|
2017-04-01 07:47:36 +02:00
|
|
|
: ciphers(tls::DEFAULT_CIPHER_LIST),
|
2019-08-08 02:59:21 +02:00
|
|
|
tls13_ciphers("TLS_AES_128_GCM_SHA256:TLS_AES_256_GCM_SHA384:TLS_"
|
|
|
|
"CHACHA20_POLY1305_SHA256:TLS_AES_128_CCM_SHA256"),
|
2019-07-24 16:14:33 +02:00
|
|
|
groups("P-256:X25519:P-384:P-521"),
|
2017-01-09 06:47:32 +01:00
|
|
|
data_length(-1),
|
2016-01-27 13:14:07 +01:00
|
|
|
addrs(nullptr),
|
|
|
|
nreqs(1),
|
|
|
|
nclients(1),
|
|
|
|
nthreads(1),
|
2016-03-02 13:18:42 +01:00
|
|
|
max_concurrent_streams(1),
|
2016-01-27 13:14:07 +01:00
|
|
|
window_bits(30),
|
|
|
|
connection_window_bits(30),
|
|
|
|
rate(0),
|
|
|
|
rate_period(1.0),
|
2017-07-28 23:08:20 +02:00
|
|
|
duration(0.0),
|
|
|
|
warm_up_time(0.0),
|
2016-01-27 13:14:07 +01:00
|
|
|
conn_active_timeout(0.),
|
|
|
|
conn_inactivity_timeout(0.),
|
|
|
|
no_tls_proto(PROTO_HTTP2),
|
2016-10-06 15:20:10 +02:00
|
|
|
header_table_size(4_k),
|
|
|
|
encoder_header_table_size(4_k),
|
2016-01-27 13:14:07 +01:00
|
|
|
data_fd(-1),
|
2018-11-23 04:46:11 +01:00
|
|
|
log_fd(-1),
|
2016-01-27 13:14:07 +01:00
|
|
|
port(0),
|
|
|
|
default_port(0),
|
2019-12-21 03:38:27 +01:00
|
|
|
connect_to_port(0),
|
2016-01-27 13:14:07 +01:00
|
|
|
verbose(false),
|
2016-02-25 16:00:24 +01:00
|
|
|
timing_script(false),
|
|
|
|
base_uri_unix(false),
|
|
|
|
unix_addr{} {}
|
2015-03-26 11:53:42 +01:00
|
|
|
|
|
|
|
Config::~Config() {
|
2016-05-06 16:38:15 +02:00
|
|
|
if (addrs) {
|
|
|
|
if (base_uri_unix) {
|
|
|
|
delete addrs;
|
|
|
|
} else {
|
|
|
|
freeaddrinfo(addrs);
|
|
|
|
}
|
2016-01-19 11:24:15 +01:00
|
|
|
}
|
2014-11-27 15:39:04 +01:00
|
|
|
|
2015-03-26 11:53:42 +01:00
|
|
|
if (data_fd != -1) {
|
|
|
|
close(data_fd);
|
|
|
|
}
|
|
|
|
}
|
2014-02-28 01:10:42 +01:00
|
|
|
|
2015-08-08 17:51:58 +02:00
|
|
|
bool Config::is_rate_mode() const { return (this->rate != 0); }
|
2017-07-28 23:08:20 +02:00
|
|
|
bool Config::is_timing_based_mode() const { return (this->duration > 0); }
|
2015-07-31 19:49:59 +02:00
|
|
|
bool Config::has_base_uri() const { return (!this->base_uri.empty()); }
|
2019-06-08 15:05:25 +02:00
|
|
|
bool Config::is_quic() const {
|
|
|
|
return !npn_list.empty() && npn_list[0] == NGTCP2_ALPN_H3;
|
|
|
|
}
|
2014-02-28 01:10:42 +01:00
|
|
|
Config config;
|
|
|
|
|
2016-01-07 14:21:39 +01:00
|
|
|
namespace {
|
|
|
|
constexpr size_t MAX_SAMPLES = 1000000;
|
|
|
|
} // namespace
|
2016-01-05 14:36:37 +01:00
|
|
|
|
2015-12-01 14:29:30 +01:00
|
|
|
Stats::Stats(size_t req_todo, size_t nclients)
|
2016-01-27 13:14:07 +01:00
|
|
|
: req_todo(req_todo),
|
|
|
|
req_started(0),
|
|
|
|
req_done(0),
|
|
|
|
req_success(0),
|
|
|
|
req_status_success(0),
|
|
|
|
req_failed(0),
|
|
|
|
req_error(0),
|
|
|
|
req_timedout(0),
|
|
|
|
bytes_total(0),
|
|
|
|
bytes_head(0),
|
|
|
|
bytes_head_decomp(0),
|
|
|
|
bytes_body(0),
|
2016-01-07 14:41:37 +01:00
|
|
|
status() {}
|
2015-01-31 10:13:07 +01:00
|
|
|
|
2016-01-06 15:10:46 +01:00
|
|
|
Stream::Stream() : req_stat{}, status_success(-1) {}
|
2014-02-28 01:10:42 +01:00
|
|
|
|
2016-01-06 14:43:09 +01:00
|
|
|
namespace {
|
|
|
|
std::random_device rd;
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
std::mt19937 gen(rd());
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
namespace {
|
2017-08-14 13:25:02 +02:00
|
|
|
void sampling_init(Sampling &smp, size_t max_samples) {
|
2016-01-06 14:43:09 +01:00
|
|
|
smp.n = 0;
|
2017-08-14 13:25:02 +02:00
|
|
|
smp.max_samples = max_samples;
|
2016-01-06 14:43:09 +01:00
|
|
|
}
|
|
|
|
} // namespace
|
|
|
|
|
2014-12-27 18:59:06 +01:00
|
|
|
namespace {
|
|
|
|
void writecb(struct ev_loop *loop, ev_io *w, int revents) {
|
|
|
|
auto client = static_cast<Client *>(w->data);
|
2015-08-18 07:52:22 +02:00
|
|
|
client->restart_timeout();
|
2015-01-04 17:56:02 +01:00
|
|
|
auto rv = client->do_write();
|
|
|
|
if (rv == Client::ERR_CONNECT_FAIL) {
|
|
|
|
client->disconnect();
|
2015-09-28 16:50:44 +02:00
|
|
|
// Try next address
|
|
|
|
client->current_addr = nullptr;
|
2015-01-04 17:56:02 +01:00
|
|
|
rv = client->connect();
|
|
|
|
if (rv != 0) {
|
|
|
|
client->fail();
|
2017-08-08 00:58:12 +02:00
|
|
|
client->worker->free_client(client);
|
2016-01-05 15:25:09 +01:00
|
|
|
delete client;
|
2015-01-04 17:56:02 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (rv != 0) {
|
2014-12-27 18:59:06 +01:00
|
|
|
client->fail();
|
2017-08-08 00:58:12 +02:00
|
|
|
client->worker->free_client(client);
|
2016-01-05 15:25:09 +01:00
|
|
|
delete client;
|
2014-12-27 18:59:06 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} // namespace
|
|
|
|
|
2015-02-10 16:44:30 +01:00
|
|
|
namespace {
|
|
|
|
void readcb(struct ev_loop *loop, ev_io *w, int revents) {
|
|
|
|
auto client = static_cast<Client *>(w->data);
|
2015-08-18 07:52:22 +02:00
|
|
|
client->restart_timeout();
|
2015-02-10 16:44:30 +01:00
|
|
|
if (client->do_read() != 0) {
|
2016-03-02 14:24:14 +01:00
|
|
|
if (client->try_again_or_fail() == 0) {
|
|
|
|
return;
|
|
|
|
}
|
2017-08-08 00:58:12 +02:00
|
|
|
client->worker->free_client(client);
|
2016-01-05 15:25:09 +01:00
|
|
|
delete client;
|
2015-02-10 16:44:30 +01:00
|
|
|
return;
|
|
|
|
}
|
2015-03-28 11:00:59 +01:00
|
|
|
writecb(loop, &client->wev, revents);
|
|
|
|
// client->disconnect() and client->fail() may be called
|
2015-02-10 16:44:30 +01:00
|
|
|
}
|
|
|
|
} // namespace
|
|
|
|
|
2015-07-21 20:06:33 +02:00
|
|
|
namespace {
|
2015-10-05 17:27:00 +02:00
|
|
|
// Called every rate_period when rate mode is being used
|
|
|
|
void rate_period_timeout_w_cb(struct ev_loop *loop, ev_timer *w, int revents) {
|
2015-07-21 20:06:33 +02:00
|
|
|
auto worker = static_cast<Worker *>(w->data);
|
2015-07-22 01:53:46 +02:00
|
|
|
auto nclients_per_second = worker->rate;
|
2015-07-23 01:41:58 +02:00
|
|
|
auto conns_remaining = worker->nclients - worker->nconns_made;
|
|
|
|
auto nclients = std::min(nclients_per_second, conns_remaining);
|
2015-07-21 20:06:33 +02:00
|
|
|
|
2015-08-08 17:51:58 +02:00
|
|
|
for (size_t i = 0; i < nclients; ++i) {
|
2015-10-08 14:25:58 +02:00
|
|
|
auto req_todo = worker->nreqs_per_client;
|
|
|
|
if (worker->nreqs_rem > 0) {
|
|
|
|
++req_todo;
|
|
|
|
--worker->nreqs_rem;
|
|
|
|
}
|
2016-01-05 15:25:09 +01:00
|
|
|
auto client =
|
2018-10-15 16:02:44 +02:00
|
|
|
std::make_unique<Client>(worker->next_client_id++, worker, req_todo);
|
2016-01-05 15:25:09 +01:00
|
|
|
|
|
|
|
++worker->nconns_made;
|
|
|
|
|
2015-07-21 20:06:33 +02:00
|
|
|
if (client->connect() != 0) {
|
|
|
|
std::cerr << "client could not connect to host" << std::endl;
|
|
|
|
client->fail();
|
2016-01-05 15:25:09 +01:00
|
|
|
} else {
|
2017-08-03 22:15:14 +02:00
|
|
|
if (worker->config->is_timing_based_mode()) {
|
2017-08-08 00:58:12 +02:00
|
|
|
worker->clients.push_back(client.release());
|
|
|
|
} else {
|
|
|
|
client.release();
|
2017-08-03 22:15:14 +02:00
|
|
|
}
|
2015-07-21 20:06:33 +02:00
|
|
|
}
|
2016-01-05 15:56:31 +01:00
|
|
|
worker->report_rate_progress();
|
2015-07-21 20:06:33 +02:00
|
|
|
}
|
2017-08-03 22:15:14 +02:00
|
|
|
if (!worker->config->is_timing_based_mode()) {
|
|
|
|
if (worker->nconns_made >= worker->nclients) {
|
|
|
|
ev_timer_stop(worker->loop, w);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// To check whether all created clients are pushed correctly
|
|
|
|
assert(worker->nclients == worker->clients.size());
|
2015-07-21 20:06:33 +02:00
|
|
|
}
|
|
|
|
}
|
2017-08-23 12:19:00 +02:00
|
|
|
} // namespace
|
2015-07-21 20:06:33 +02:00
|
|
|
|
2017-07-28 23:08:20 +02:00
|
|
|
namespace {
|
|
|
|
// Called when the duration for infinite number of requests are over
|
|
|
|
void duration_timeout_cb(struct ev_loop *loop, ev_timer *w, int revents) {
|
|
|
|
auto worker = static_cast<Worker *>(w->data);
|
|
|
|
|
|
|
|
worker->current_phase = Phase::DURATION_OVER;
|
|
|
|
|
|
|
|
std::cout << "Main benchmark duration is over for thread #" << worker->id
|
|
|
|
<< ". Stopping all clients." << std::endl;
|
|
|
|
worker->stop_all_clients();
|
|
|
|
std::cout << "Stopped all clients for thread #" << worker->id << std::endl;
|
|
|
|
}
|
2017-08-23 12:19:00 +02:00
|
|
|
} // namespace
|
2017-07-28 23:08:20 +02:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
// Called when the warmup duration for infinite number of requests are over
|
|
|
|
void warmup_timeout_cb(struct ev_loop *loop, ev_timer *w, int revents) {
|
|
|
|
auto worker = static_cast<Worker *>(w->data);
|
|
|
|
|
|
|
|
std::cout << "Warm-up phase is over for thread #" << worker->id << "."
|
|
|
|
<< std::endl;
|
|
|
|
std::cout << "Main benchmark duration is started for thread #" << worker->id
|
|
|
|
<< "." << std::endl;
|
|
|
|
assert(worker->stats.req_started == 0);
|
|
|
|
assert(worker->stats.req_done == 0);
|
|
|
|
|
|
|
|
for (auto client : worker->clients) {
|
2017-08-08 00:58:12 +02:00
|
|
|
if (client) {
|
|
|
|
assert(client->req_todo == 0);
|
|
|
|
assert(client->req_left == 1);
|
|
|
|
assert(client->req_inflight == 0);
|
|
|
|
assert(client->req_started == 0);
|
|
|
|
assert(client->req_done == 0);
|
|
|
|
|
|
|
|
client->record_client_start_time();
|
|
|
|
client->clear_connect_times();
|
|
|
|
client->record_connect_start_time();
|
|
|
|
}
|
2017-07-28 23:08:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
worker->current_phase = Phase::MAIN_DURATION;
|
2017-08-23 12:19:00 +02:00
|
|
|
|
2017-07-28 23:08:20 +02:00
|
|
|
ev_timer_start(worker->loop, &worker->duration_watcher);
|
|
|
|
}
|
2015-07-21 20:06:33 +02:00
|
|
|
} // namespace
|
|
|
|
|
2015-08-18 07:52:22 +02:00
|
|
|
namespace {
|
2015-08-18 14:32:47 +02:00
|
|
|
// Called when an a connection has been inactive for a set period of time
|
2015-08-18 07:52:22 +02:00
|
|
|
// or a fixed amount of time after all requests have been made on a
|
|
|
|
// connection
|
|
|
|
void conn_timeout_cb(EV_P_ ev_timer *w, int revents) {
|
|
|
|
auto client = static_cast<Client *>(w->data);
|
|
|
|
|
|
|
|
ev_timer_stop(client->worker->loop, &client->conn_inactivity_watcher);
|
|
|
|
ev_timer_stop(client->worker->loop, &client->conn_active_watcher);
|
|
|
|
|
|
|
|
if (util::check_socket_connected(client->fd)) {
|
|
|
|
client->timeout();
|
|
|
|
}
|
|
|
|
}
|
2015-08-18 17:31:22 +02:00
|
|
|
} // namespace
|
2015-07-31 19:49:59 +02:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
bool check_stop_client_request_timeout(Client *client, ev_timer *w) {
|
2017-08-23 13:10:23 +02:00
|
|
|
if (client->req_left == 0) {
|
2015-07-31 19:49:59 +02:00
|
|
|
// no more requests to make, stop timer
|
|
|
|
ev_timer_stop(client->worker->loop, w);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
void client_request_timeout_cb(struct ev_loop *loop, ev_timer *w, int revents) {
|
|
|
|
auto client = static_cast<Client *>(w->data);
|
|
|
|
|
2017-08-23 13:10:23 +02:00
|
|
|
if (client->streams.size() >= (size_t)config.max_concurrent_streams) {
|
|
|
|
ev_timer_stop(client->worker->loop, w);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-10-29 14:31:03 +01:00
|
|
|
if (client->submit_request() != 0) {
|
|
|
|
ev_timer_stop(client->worker->loop, w);
|
|
|
|
client->process_request_failure();
|
|
|
|
return;
|
|
|
|
}
|
2015-07-31 19:49:59 +02:00
|
|
|
client->signal_write();
|
|
|
|
|
|
|
|
if (check_stop_client_request_timeout(client, w)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ev_tstamp duration =
|
|
|
|
config.timings[client->reqidx] - config.timings[client->reqidx - 1];
|
|
|
|
|
|
|
|
while (duration < 1e-9) {
|
2015-10-29 14:31:03 +01:00
|
|
|
if (client->submit_request() != 0) {
|
|
|
|
ev_timer_stop(client->worker->loop, w);
|
|
|
|
client->process_request_failure();
|
|
|
|
return;
|
|
|
|
}
|
2015-07-31 19:49:59 +02:00
|
|
|
client->signal_write();
|
|
|
|
if (check_stop_client_request_timeout(client, w)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
duration =
|
|
|
|
config.timings[client->reqidx] - config.timings[client->reqidx - 1];
|
|
|
|
}
|
|
|
|
|
|
|
|
client->request_timeout_watcher.repeat = duration;
|
|
|
|
ev_timer_again(client->worker->loop, &client->request_timeout_watcher);
|
|
|
|
}
|
2015-08-18 07:52:22 +02:00
|
|
|
} // namespace
|
|
|
|
|
2015-12-01 14:29:30 +01:00
|
|
|
Client::Client(uint32_t id, Worker *worker, size_t req_todo)
|
2016-06-12 11:50:52 +02:00
|
|
|
: wb(&worker->mcpool),
|
|
|
|
cstat{},
|
2016-01-27 13:14:07 +01:00
|
|
|
worker(worker),
|
|
|
|
ssl(nullptr),
|
2019-06-08 15:05:25 +02:00
|
|
|
quic{},
|
2016-01-27 13:14:07 +01:00
|
|
|
next_addr(config.addrs),
|
|
|
|
current_addr(nullptr),
|
|
|
|
reqidx(0),
|
|
|
|
state(CLIENT_IDLE),
|
|
|
|
req_todo(req_todo),
|
2017-01-25 16:16:12 +01:00
|
|
|
req_left(req_todo),
|
|
|
|
req_inflight(0),
|
2016-01-27 13:14:07 +01:00
|
|
|
req_started(0),
|
|
|
|
req_done(0),
|
|
|
|
id(id),
|
|
|
|
fd(-1),
|
2019-06-08 15:05:25 +02:00
|
|
|
local_addr{},
|
2016-06-12 10:42:12 +02:00
|
|
|
new_connection_requested(false),
|
|
|
|
final(false) {
|
2017-07-28 23:08:20 +02:00
|
|
|
if (req_todo == 0) { // this means infinite number of requests are to be made
|
|
|
|
// This ensures that number of requests are unbounded
|
|
|
|
// Just a positive number is fine, we chose the first positive number
|
|
|
|
req_left = 1;
|
|
|
|
}
|
2014-12-27 18:59:06 +01:00
|
|
|
ev_io_init(&wev, writecb, 0, EV_WRITE);
|
|
|
|
ev_io_init(&rev, readcb, 0, EV_READ);
|
|
|
|
|
|
|
|
wev.data = this;
|
|
|
|
rev.data = this;
|
2015-08-18 07:52:22 +02:00
|
|
|
|
2015-08-18 14:34:33 +02:00
|
|
|
ev_timer_init(&conn_inactivity_watcher, conn_timeout_cb, 0.,
|
|
|
|
worker->config->conn_inactivity_timeout);
|
2015-08-18 07:52:22 +02:00
|
|
|
conn_inactivity_watcher.data = this;
|
|
|
|
|
|
|
|
ev_timer_init(&conn_active_watcher, conn_timeout_cb,
|
2015-08-18 14:34:33 +02:00
|
|
|
worker->config->conn_active_timeout, 0.);
|
|
|
|
conn_active_watcher.data = this;
|
2015-07-31 19:49:59 +02:00
|
|
|
|
|
|
|
ev_timer_init(&request_timeout_watcher, client_request_timeout_cb, 0., 0.);
|
|
|
|
request_timeout_watcher.data = this;
|
2019-06-08 15:05:25 +02:00
|
|
|
|
|
|
|
ev_timer_init(&quic.pkt_timer, quic_pkt_timeout_cb, 0., 0.);
|
|
|
|
quic.pkt_timer.data = this;
|
2014-12-27 18:59:06 +01:00
|
|
|
}
|
2014-11-27 15:39:04 +01:00
|
|
|
|
2015-09-28 16:59:42 +02:00
|
|
|
Client::~Client() {
|
|
|
|
disconnect();
|
|
|
|
|
2019-06-08 15:05:25 +02:00
|
|
|
if (config.is_quic()) {
|
|
|
|
quic_free();
|
|
|
|
}
|
|
|
|
|
2015-09-28 16:59:42 +02:00
|
|
|
if (ssl) {
|
|
|
|
SSL_free(ssl);
|
|
|
|
}
|
2016-01-06 15:03:37 +01:00
|
|
|
|
2017-08-14 13:25:02 +02:00
|
|
|
worker->sample_client_stat(&cstat);
|
2016-01-06 15:03:37 +01:00
|
|
|
++worker->client_smp.n;
|
2015-09-28 16:59:42 +02:00
|
|
|
}
|
2014-02-28 01:10:42 +01:00
|
|
|
|
2014-12-27 18:59:06 +01:00
|
|
|
int Client::do_read() { return readfn(*this); }
|
|
|
|
int Client::do_write() { return writefn(*this); }
|
|
|
|
|
2015-09-28 16:50:44 +02:00
|
|
|
int Client::make_socket(addrinfo *addr) {
|
2019-06-08 15:05:25 +02:00
|
|
|
int rv;
|
|
|
|
|
|
|
|
if (config.is_quic()) {
|
|
|
|
fd = util::create_nonblock_udp_socket(addr->ai_family);
|
|
|
|
if (fd == -1) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = util::bind_any_addr_udp(fd, addr->ai_family);
|
|
|
|
if (rv != 0) {
|
|
|
|
close(fd);
|
|
|
|
fd = -1;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
socklen_t addrlen = sizeof(local_addr.su.storage);
|
|
|
|
rv = getsockname(fd, &local_addr.su.sa, &addrlen);
|
|
|
|
if (rv == -1) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
local_addr.len = addrlen;
|
|
|
|
|
|
|
|
if (quic_init(&local_addr.su.sa, local_addr.len, addr->ai_addr,
|
|
|
|
addr->ai_addrlen) != 0) {
|
|
|
|
std::cerr << "quic_init failed" << std::endl;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-09-28 16:50:44 +02:00
|
|
|
fd = util::create_nonblock_socket(addr->ai_family);
|
|
|
|
if (fd == -1) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (config.scheme == "https") {
|
2015-09-28 16:59:42 +02:00
|
|
|
if (!ssl) {
|
|
|
|
ssl = SSL_new(worker->ssl_ctx);
|
|
|
|
}
|
2015-09-28 16:50:44 +02:00
|
|
|
|
|
|
|
SSL_set_fd(ssl, fd);
|
|
|
|
SSL_set_connect_state(ssl);
|
|
|
|
}
|
|
|
|
|
2019-06-08 15:05:25 +02:00
|
|
|
if (ssl && !util::numeric_host(config.host.c_str())) {
|
|
|
|
SSL_set_tlsext_host_name(ssl, config.host.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = ::connect(fd, addr->ai_addr, addr->ai_addrlen);
|
2015-09-28 16:50:44 +02:00
|
|
|
if (rv != 0 && errno != EINPROGRESS) {
|
|
|
|
if (ssl) {
|
|
|
|
SSL_free(ssl);
|
|
|
|
ssl = nullptr;
|
|
|
|
}
|
|
|
|
close(fd);
|
|
|
|
fd = -1;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
int Client::connect() {
|
2015-09-28 16:50:44 +02:00
|
|
|
int rv;
|
|
|
|
|
2017-08-23 12:19:00 +02:00
|
|
|
if (!worker->config->is_timing_based_mode() ||
|
|
|
|
worker->current_phase == Phase::MAIN_DURATION) {
|
2017-07-28 23:08:20 +02:00
|
|
|
record_client_start_time();
|
|
|
|
clear_connect_times();
|
|
|
|
record_connect_start_time();
|
|
|
|
} else if (worker->current_phase == Phase::INITIAL_IDLE) {
|
|
|
|
worker->current_phase = Phase::WARM_UP;
|
2017-08-23 12:19:00 +02:00
|
|
|
std::cout << "Warm-up started for thread #" << worker->id << "."
|
|
|
|
<< std::endl;
|
2017-07-28 23:08:20 +02:00
|
|
|
ev_timer_start(worker->loop, &worker->warmup_watcher);
|
|
|
|
}
|
2015-04-30 00:29:37 +02:00
|
|
|
|
2015-10-10 10:52:51 +02:00
|
|
|
if (worker->config->conn_inactivity_timeout > 0.) {
|
2015-08-18 07:52:22 +02:00
|
|
|
ev_timer_again(worker->loop, &conn_inactivity_watcher);
|
|
|
|
}
|
|
|
|
|
2015-09-28 16:50:44 +02:00
|
|
|
if (current_addr) {
|
|
|
|
rv = make_socket(current_addr);
|
|
|
|
if (rv == -1) {
|
|
|
|
return -1;
|
2014-12-27 18:59:06 +01:00
|
|
|
}
|
2015-09-28 16:50:44 +02:00
|
|
|
} else {
|
2015-09-29 16:38:26 +02:00
|
|
|
addrinfo *addr = nullptr;
|
2015-09-28 16:50:44 +02:00
|
|
|
while (next_addr) {
|
|
|
|
addr = next_addr;
|
|
|
|
next_addr = next_addr->ai_next;
|
|
|
|
rv = make_socket(addr);
|
|
|
|
if (rv == 0) {
|
|
|
|
break;
|
2014-12-27 18:59:06 +01:00
|
|
|
}
|
|
|
|
}
|
2014-02-28 01:10:42 +01:00
|
|
|
|
2015-09-28 16:50:44 +02:00
|
|
|
if (fd == -1) {
|
|
|
|
return -1;
|
2014-02-28 01:10:42 +01:00
|
|
|
}
|
2014-12-27 18:59:06 +01:00
|
|
|
|
2015-09-29 16:38:26 +02:00
|
|
|
assert(addr);
|
|
|
|
|
2015-09-28 16:50:44 +02:00
|
|
|
current_addr = addr;
|
2014-02-28 01:10:42 +01:00
|
|
|
}
|
2014-12-27 18:59:06 +01:00
|
|
|
|
|
|
|
ev_io_set(&rev, fd, EV_READ);
|
|
|
|
ev_io_set(&wev, fd, EV_WRITE);
|
|
|
|
|
|
|
|
ev_io_start(worker->loop, &wev);
|
|
|
|
|
2019-06-08 15:05:25 +02:00
|
|
|
if (config.is_quic()) {
|
|
|
|
ev_io_start(worker->loop, &rev);
|
|
|
|
|
|
|
|
readfn = &Client::read_quic;
|
|
|
|
writefn = &Client::write_quic;
|
|
|
|
} else {
|
|
|
|
writefn = &Client::connected;
|
|
|
|
}
|
|
|
|
|
2014-02-28 01:10:42 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-08-18 07:52:22 +02:00
|
|
|
void Client::timeout() {
|
|
|
|
process_timedout_streams();
|
|
|
|
|
|
|
|
disconnect();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Client::restart_timeout() {
|
2015-10-10 10:52:51 +02:00
|
|
|
if (worker->config->conn_inactivity_timeout > 0.) {
|
2015-08-18 07:52:22 +02:00
|
|
|
ev_timer_again(worker->loop, &conn_inactivity_watcher);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-02 14:24:14 +01:00
|
|
|
int Client::try_again_or_fail() {
|
2014-06-26 16:20:12 +02:00
|
|
|
disconnect();
|
2015-09-28 16:50:44 +02:00
|
|
|
|
|
|
|
if (new_connection_requested) {
|
|
|
|
new_connection_requested = false;
|
2017-07-28 23:08:20 +02:00
|
|
|
|
2017-01-25 16:16:12 +01:00
|
|
|
if (req_left) {
|
2015-11-26 13:26:00 +01:00
|
|
|
|
2017-07-28 23:08:20 +02:00
|
|
|
if (worker->current_phase == Phase::MAIN_DURATION) {
|
|
|
|
// At the moment, we don't have a facility to re-start request
|
|
|
|
// already in in-flight. Make them fail.
|
|
|
|
worker->stats.req_failed += req_inflight;
|
|
|
|
worker->stats.req_error += req_inflight;
|
|
|
|
|
|
|
|
req_inflight = 0;
|
|
|
|
}
|
2015-11-26 13:26:00 +01:00
|
|
|
|
|
|
|
// Keep using current address
|
|
|
|
if (connect() == 0) {
|
2016-03-02 14:24:14 +01:00
|
|
|
return 0;
|
2015-11-26 13:26:00 +01:00
|
|
|
}
|
|
|
|
std::cerr << "client could not connect to host" << std::endl;
|
2015-09-28 16:50:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
process_abandoned_streams();
|
2016-03-02 14:24:14 +01:00
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Client::fail() {
|
|
|
|
disconnect();
|
|
|
|
|
|
|
|
process_abandoned_streams();
|
2014-06-26 16:20:12 +02:00
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
void Client::disconnect() {
|
2015-12-01 15:49:28 +01:00
|
|
|
record_client_end_time();
|
|
|
|
|
2019-06-08 15:05:25 +02:00
|
|
|
if (config.is_quic()) {
|
|
|
|
quic_close_connection();
|
|
|
|
}
|
|
|
|
|
|
|
|
ev_timer_stop(worker->loop, &quic.pkt_timer);
|
2015-08-18 07:52:22 +02:00
|
|
|
ev_timer_stop(worker->loop, &conn_inactivity_watcher);
|
|
|
|
ev_timer_stop(worker->loop, &conn_active_watcher);
|
2015-09-01 19:34:32 +02:00
|
|
|
ev_timer_stop(worker->loop, &request_timeout_watcher);
|
2014-02-28 01:10:42 +01:00
|
|
|
streams.clear();
|
|
|
|
session.reset();
|
2015-11-26 13:26:00 +01:00
|
|
|
wb.reset();
|
2014-02-28 01:10:42 +01:00
|
|
|
state = CLIENT_IDLE;
|
2014-12-27 18:59:06 +01:00
|
|
|
ev_io_stop(worker->loop, &wev);
|
|
|
|
ev_io_stop(worker->loop, &rev);
|
2014-11-27 15:39:04 +01:00
|
|
|
if (ssl) {
|
2017-01-02 03:48:38 +01:00
|
|
|
SSL_set_shutdown(ssl, SSL_get_shutdown(ssl) | SSL_RECEIVED_SHUTDOWN);
|
2015-01-09 01:15:01 +01:00
|
|
|
ERR_clear_error();
|
2015-09-28 16:59:42 +02:00
|
|
|
|
|
|
|
if (SSL_shutdown(ssl) != 1) {
|
|
|
|
SSL_free(ssl);
|
|
|
|
ssl = nullptr;
|
|
|
|
}
|
2014-02-28 01:10:42 +01:00
|
|
|
}
|
2014-11-27 15:39:04 +01:00
|
|
|
if (fd != -1) {
|
2014-02-28 01:10:42 +01:00
|
|
|
shutdown(fd, SHUT_WR);
|
|
|
|
close(fd);
|
2014-12-27 18:59:06 +01:00
|
|
|
fd = -1;
|
2014-02-28 01:10:42 +01:00
|
|
|
}
|
2016-06-12 10:42:12 +02:00
|
|
|
|
|
|
|
final = false;
|
2014-02-28 01:10:42 +01:00
|
|
|
}
|
|
|
|
|
2015-10-29 14:31:03 +01:00
|
|
|
int Client::submit_request() {
|
2016-01-05 14:36:37 +01:00
|
|
|
if (session->submit_request() != 0) {
|
2015-10-29 14:31:03 +01:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2017-07-28 23:08:20 +02:00
|
|
|
if (worker->current_phase != Phase::MAIN_DURATION) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-01-25 16:16:12 +01:00
|
|
|
++worker->stats.req_started;
|
2014-06-22 04:33:16 +02:00
|
|
|
++req_started;
|
2017-01-25 16:16:12 +01:00
|
|
|
++req_inflight;
|
2017-07-28 23:08:20 +02:00
|
|
|
if (!worker->config->is_timing_based_mode()) {
|
|
|
|
--req_left;
|
|
|
|
}
|
2015-08-18 07:52:22 +02:00
|
|
|
// if an active timeout is set and this is the last request to be submitted
|
|
|
|
// on this connection, start the active timeout.
|
2017-01-25 16:16:12 +01:00
|
|
|
if (worker->config->conn_active_timeout > 0. && req_left == 0) {
|
2015-08-18 07:52:22 +02:00
|
|
|
ev_timer_start(worker->loop, &conn_active_watcher);
|
|
|
|
}
|
2015-10-29 14:31:03 +01:00
|
|
|
|
|
|
|
return 0;
|
2015-08-18 07:52:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Client::process_timedout_streams() {
|
2017-07-28 23:08:20 +02:00
|
|
|
if (worker->current_phase != Phase::MAIN_DURATION) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-01-25 16:26:35 +01:00
|
|
|
for (auto &p : streams) {
|
|
|
|
auto &req_stat = p.second.req_stat;
|
2015-08-18 07:52:22 +02:00
|
|
|
if (!req_stat.completed) {
|
|
|
|
req_stat.stream_close_time = std::chrono::steady_clock::now();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-25 16:16:12 +01:00
|
|
|
worker->stats.req_timedout += req_inflight;
|
2015-08-18 07:52:22 +02:00
|
|
|
|
|
|
|
process_abandoned_streams();
|
2014-02-28 01:10:42 +01:00
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
void Client::process_abandoned_streams() {
|
2017-07-28 23:08:20 +02:00
|
|
|
if (worker->current_phase != Phase::MAIN_DURATION) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-01-25 16:16:12 +01:00
|
|
|
auto req_abandoned = req_inflight + req_left;
|
2014-06-22 04:33:16 +02:00
|
|
|
|
|
|
|
worker->stats.req_failed += req_abandoned;
|
|
|
|
worker->stats.req_error += req_abandoned;
|
2014-11-06 16:28:10 +01:00
|
|
|
|
2017-01-25 16:16:12 +01:00
|
|
|
req_inflight = 0;
|
|
|
|
req_left = 0;
|
2014-02-28 01:10:42 +01:00
|
|
|
}
|
|
|
|
|
2015-10-29 14:31:03 +01:00
|
|
|
void Client::process_request_failure() {
|
2017-07-28 23:08:20 +02:00
|
|
|
if (worker->current_phase != Phase::MAIN_DURATION) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-01-25 16:16:12 +01:00
|
|
|
worker->stats.req_failed += req_left;
|
|
|
|
worker->stats.req_error += req_left;
|
2015-10-29 14:31:03 +01:00
|
|
|
|
2017-01-25 16:16:12 +01:00
|
|
|
req_left = 0;
|
2015-10-29 14:31:03 +01:00
|
|
|
|
2017-01-25 16:16:12 +01:00
|
|
|
if (req_inflight == 0) {
|
2015-10-29 14:31:03 +01:00
|
|
|
terminate_session();
|
|
|
|
}
|
2017-08-23 12:19:00 +02:00
|
|
|
std::cout << "Process Request Failure:" << worker->stats.req_failed
|
|
|
|
<< std::endl;
|
2015-10-29 14:31:03 +01:00
|
|
|
}
|
|
|
|
|
2014-11-08 13:24:24 +01:00
|
|
|
namespace {
|
2014-11-27 15:39:04 +01:00
|
|
|
void print_server_tmp_key(SSL *ssl) {
|
2015-06-17 11:24:14 +02:00
|
|
|
// libressl does not have SSL_get_server_tmp_key
|
|
|
|
#if OPENSSL_VERSION_NUMBER >= 0x10002000L && defined(SSL_get_server_tmp_key)
|
2014-11-08 13:24:24 +01:00
|
|
|
EVP_PKEY *key;
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (!SSL_get_server_tmp_key(ssl, &key)) {
|
2014-11-08 13:24:24 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-02-06 15:27:15 +01:00
|
|
|
auto key_del = defer(EVP_PKEY_free, key);
|
2014-11-08 13:24:24 +01:00
|
|
|
|
|
|
|
std::cout << "Server Temp Key: ";
|
|
|
|
|
2017-01-08 09:58:19 +01:00
|
|
|
auto pkey_id = EVP_PKEY_id(key);
|
|
|
|
switch (pkey_id) {
|
2014-11-08 13:24:24 +01:00
|
|
|
case EVP_PKEY_RSA:
|
|
|
|
std::cout << "RSA " << EVP_PKEY_bits(key) << " bits" << std::endl;
|
|
|
|
break;
|
|
|
|
case EVP_PKEY_DH:
|
|
|
|
std::cout << "DH " << EVP_PKEY_bits(key) << " bits" << std::endl;
|
|
|
|
break;
|
|
|
|
case EVP_PKEY_EC: {
|
|
|
|
auto ec = EVP_PKEY_get1_EC_KEY(key);
|
2015-02-06 15:27:15 +01:00
|
|
|
auto ec_del = defer(EC_KEY_free, ec);
|
2014-11-08 13:24:24 +01:00
|
|
|
auto nid = EC_GROUP_get_curve_name(EC_KEY_get0_group(ec));
|
|
|
|
auto cname = EC_curve_nid2nist(nid);
|
2014-11-27 15:39:04 +01:00
|
|
|
if (!cname) {
|
2014-11-08 13:24:24 +01:00
|
|
|
cname = OBJ_nid2sn(nid);
|
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
std::cout << "ECDH " << cname << " " << EVP_PKEY_bits(key) << " bits"
|
|
|
|
<< std::endl;
|
2014-11-08 13:24:24 +01:00
|
|
|
break;
|
|
|
|
}
|
2017-01-08 09:58:19 +01:00
|
|
|
default:
|
|
|
|
std::cout << OBJ_nid2sn(pkey_id) << " " << EVP_PKEY_bits(key) << " bits"
|
|
|
|
<< std::endl;
|
|
|
|
break;
|
2014-11-08 13:24:24 +01:00
|
|
|
}
|
|
|
|
#endif // OPENSSL_VERSION_NUMBER >= 0x10002000L
|
|
|
|
}
|
|
|
|
} // namespace
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
void Client::report_tls_info() {
|
|
|
|
if (worker->id == 0 && !worker->tls_info_report_done) {
|
2014-11-08 13:24:24 +01:00
|
|
|
worker->tls_info_report_done = true;
|
|
|
|
auto cipher = SSL_get_current_cipher(ssl);
|
2017-04-01 07:47:36 +02:00
|
|
|
std::cout << "TLS Protocol: " << tls::get_tls_protocol(ssl) << "\n"
|
2014-11-08 13:24:24 +01:00
|
|
|
<< "Cipher: " << SSL_CIPHER_get_name(cipher) << std::endl;
|
|
|
|
print_server_tmp_key(ssl);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-14 15:33:48 +02:00
|
|
|
void Client::report_app_info() {
|
|
|
|
if (worker->id == 0 && !worker->app_info_report_done) {
|
|
|
|
worker->app_info_report_done = true;
|
|
|
|
std::cout << "Application protocol: " << selected_proto << std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-29 14:31:03 +01:00
|
|
|
void Client::terminate_session() {
|
2019-06-08 15:05:25 +02:00
|
|
|
if (config.is_quic()) {
|
|
|
|
quic.close_requested = true;
|
|
|
|
}
|
2015-10-29 14:31:03 +01:00
|
|
|
session->terminate();
|
|
|
|
// http1 session needs writecb to tear down session.
|
|
|
|
signal_write();
|
|
|
|
}
|
2014-02-28 01:10:42 +01:00
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
void Client::on_request(int32_t stream_id) { streams[stream_id] = Stream(); }
|
2014-02-28 01:10:42 +01:00
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
void Client::on_header(int32_t stream_id, const uint8_t *name, size_t namelen,
|
|
|
|
const uint8_t *value, size_t valuelen) {
|
2014-02-28 01:10:42 +01:00
|
|
|
auto itr = streams.find(stream_id);
|
2014-11-27 15:39:04 +01:00
|
|
|
if (itr == std::end(streams)) {
|
2014-02-28 01:10:42 +01:00
|
|
|
return;
|
|
|
|
}
|
2014-11-27 15:39:04 +01:00
|
|
|
auto &stream = (*itr).second;
|
2017-08-02 01:51:47 +02:00
|
|
|
|
2017-08-02 00:29:00 +02:00
|
|
|
if (worker->current_phase != Phase::MAIN_DURATION) {
|
|
|
|
// If the stream is for warm-up phase, then mark as a success
|
|
|
|
// But we do not update the count for 2xx, 3xx, etc status codes
|
|
|
|
// Same has been done in on_status_code function
|
|
|
|
stream.status_success = 1;
|
|
|
|
return;
|
|
|
|
}
|
2017-08-02 01:51:47 +02:00
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (stream.status_success == -1 && namelen == 7 &&
|
2015-02-20 15:57:40 +01:00
|
|
|
util::streq_l(":status", name, namelen)) {
|
2014-02-28 01:10:42 +01:00
|
|
|
int status = 0;
|
2014-11-27 15:39:04 +01:00
|
|
|
for (size_t i = 0; i < valuelen; ++i) {
|
|
|
|
if ('0' <= value[i] && value[i] <= '9') {
|
2014-02-28 01:10:42 +01:00
|
|
|
status *= 10;
|
|
|
|
status += value[i] - '0';
|
2014-11-27 15:39:04 +01:00
|
|
|
if (status > 999) {
|
2014-02-28 01:10:42 +01:00
|
|
|
stream.status_success = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2017-08-23 12:19:00 +02:00
|
|
|
|
2018-11-11 19:33:50 +01:00
|
|
|
stream.req_stat.status = status;
|
2014-11-27 15:39:04 +01:00
|
|
|
if (status >= 200 && status < 300) {
|
2014-02-28 01:10:42 +01:00
|
|
|
++worker->stats.status[2];
|
|
|
|
stream.status_success = 1;
|
2014-11-27 15:39:04 +01:00
|
|
|
} else if (status < 400) {
|
2014-02-28 01:10:42 +01:00
|
|
|
++worker->stats.status[3];
|
|
|
|
stream.status_success = 1;
|
2014-11-27 15:39:04 +01:00
|
|
|
} else if (status < 600) {
|
2014-02-28 01:10:42 +01:00
|
|
|
++worker->stats.status[status / 100];
|
|
|
|
stream.status_success = 0;
|
|
|
|
} else {
|
|
|
|
stream.status_success = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-14 15:33:48 +02:00
|
|
|
void Client::on_status_code(int32_t stream_id, uint16_t status) {
|
|
|
|
auto itr = streams.find(stream_id);
|
|
|
|
if (itr == std::end(streams)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
auto &stream = (*itr).second;
|
|
|
|
|
2017-08-02 00:29:00 +02:00
|
|
|
if (worker->current_phase != Phase::MAIN_DURATION) {
|
|
|
|
stream.status_success = 1;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-11-11 19:33:50 +01:00
|
|
|
stream.req_stat.status = status;
|
2015-09-14 15:33:48 +02:00
|
|
|
if (status >= 200 && status < 300) {
|
|
|
|
++worker->stats.status[2];
|
|
|
|
stream.status_success = 1;
|
|
|
|
} else if (status < 400) {
|
|
|
|
++worker->stats.status[3];
|
|
|
|
stream.status_success = 1;
|
|
|
|
} else if (status < 600) {
|
|
|
|
++worker->stats.status[status / 100];
|
|
|
|
stream.status_success = 0;
|
|
|
|
} else {
|
|
|
|
stream.status_success = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-05 14:36:37 +01:00
|
|
|
void Client::on_stream_close(int32_t stream_id, bool success, bool final) {
|
2017-07-28 23:08:20 +02:00
|
|
|
if (worker->current_phase == Phase::MAIN_DURATION) {
|
|
|
|
if (req_inflight > 0) {
|
|
|
|
--req_inflight;
|
|
|
|
}
|
|
|
|
auto req_stat = get_req_stat(stream_id);
|
|
|
|
if (!req_stat) {
|
|
|
|
return;
|
|
|
|
}
|
2017-01-25 16:16:12 +01:00
|
|
|
|
2017-07-28 23:08:20 +02:00
|
|
|
req_stat->stream_close_time = std::chrono::steady_clock::now();
|
|
|
|
if (success) {
|
|
|
|
req_stat->completed = true;
|
|
|
|
++worker->stats.req_success;
|
|
|
|
++cstat.req_success;
|
2016-01-05 14:36:37 +01:00
|
|
|
|
2017-07-28 23:08:20 +02:00
|
|
|
if (streams[stream_id].status_success == 1) {
|
|
|
|
++worker->stats.req_status_success;
|
|
|
|
} else {
|
|
|
|
++worker->stats.req_failed;
|
|
|
|
}
|
2016-01-05 14:36:37 +01:00
|
|
|
|
2017-08-23 12:18:27 +02:00
|
|
|
worker->sample_req_stat(req_stat);
|
2016-01-06 14:43:09 +01:00
|
|
|
|
2017-07-28 23:08:20 +02:00
|
|
|
// Count up in successful cases only
|
|
|
|
++worker->request_times_smp.n;
|
2015-10-29 13:15:22 +01:00
|
|
|
} else {
|
|
|
|
++worker->stats.req_failed;
|
2017-07-28 23:08:20 +02:00
|
|
|
++worker->stats.req_error;
|
2015-10-29 13:15:22 +01:00
|
|
|
}
|
2017-07-28 23:08:20 +02:00
|
|
|
++worker->stats.req_done;
|
2017-08-01 23:45:18 +02:00
|
|
|
++req_done;
|
2018-11-11 19:33:50 +01:00
|
|
|
|
2018-11-23 04:46:11 +01:00
|
|
|
if (worker->config->log_fd != -1) {
|
2018-11-11 19:33:50 +01:00
|
|
|
auto start = std::chrono::duration_cast<std::chrono::microseconds>(
|
|
|
|
req_stat->request_wall_time.time_since_epoch());
|
|
|
|
auto delta = std::chrono::duration_cast<std::chrono::microseconds>(
|
|
|
|
req_stat->stream_close_time - req_stat->request_time);
|
2018-11-23 04:46:11 +01:00
|
|
|
|
|
|
|
std::array<uint8_t, 256> buf;
|
|
|
|
auto p = std::begin(buf);
|
|
|
|
p = util::utos(p, start.count());
|
|
|
|
*p++ = '\t';
|
|
|
|
if (success) {
|
|
|
|
p = util::utos(p, req_stat->status);
|
|
|
|
} else {
|
|
|
|
*p++ = '-';
|
|
|
|
*p++ = '1';
|
2018-11-11 19:33:50 +01:00
|
|
|
}
|
2018-11-23 04:46:11 +01:00
|
|
|
*p++ = '\t';
|
|
|
|
p = util::utos(p, delta.count());
|
|
|
|
*p++ = '\n';
|
|
|
|
|
2018-11-23 06:39:51 +01:00
|
|
|
auto nwrite = static_cast<size_t>(std::distance(std::begin(buf), p));
|
2018-11-23 04:46:11 +01:00
|
|
|
assert(nwrite <= buf.size());
|
2018-11-23 06:39:51 +01:00
|
|
|
while (write(worker->config->log_fd, buf.data(), nwrite) == -1 &&
|
|
|
|
errno == EINTR)
|
|
|
|
;
|
2018-11-11 19:33:50 +01:00
|
|
|
}
|
2014-02-28 01:10:42 +01:00
|
|
|
}
|
2016-01-05 14:36:37 +01:00
|
|
|
|
2016-01-05 15:56:31 +01:00
|
|
|
worker->report_progress();
|
2014-02-28 01:10:42 +01:00
|
|
|
streams.erase(stream_id);
|
2017-01-25 16:16:12 +01:00
|
|
|
if (req_left == 0 && req_inflight == 0) {
|
2014-11-06 16:28:10 +01:00
|
|
|
terminate_session();
|
2014-02-28 01:10:42 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-08-23 13:10:23 +02:00
|
|
|
if (!final && req_left > 0) {
|
|
|
|
if (config.timing_script) {
|
|
|
|
if (!ev_is_active(&request_timeout_watcher)) {
|
|
|
|
ev_feed_event(worker->loop, &request_timeout_watcher, EV_TIMER);
|
|
|
|
}
|
|
|
|
} else if (submit_request() != 0) {
|
|
|
|
process_request_failure();
|
|
|
|
}
|
2014-02-28 01:10:42 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-05 14:36:37 +01:00
|
|
|
RequestStat *Client::get_req_stat(int32_t stream_id) {
|
|
|
|
auto it = streams.find(stream_id);
|
|
|
|
if (it == std::end(streams)) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return &(*it).second.req_stat;
|
|
|
|
}
|
|
|
|
|
2015-03-28 12:13:37 +01:00
|
|
|
int Client::connection_made() {
|
2014-12-27 18:59:06 +01:00
|
|
|
if (ssl) {
|
|
|
|
report_tls_info();
|
|
|
|
|
|
|
|
const unsigned char *next_proto = nullptr;
|
|
|
|
unsigned int next_proto_len;
|
|
|
|
|
2018-03-25 18:27:23 +02:00
|
|
|
#ifndef OPENSSL_NO_NEXTPROTONEG
|
2015-10-27 18:40:04 +01:00
|
|
|
SSL_get0_next_proto_negotiated(ssl, &next_proto, &next_proto_len);
|
2018-04-03 14:39:44 +02:00
|
|
|
#endif // !OPENSSL_NO_NEXTPROTONEG
|
2014-12-27 18:59:06 +01:00
|
|
|
#if OPENSSL_VERSION_NUMBER >= 0x10002000L
|
2015-10-27 18:40:04 +01:00
|
|
|
if (next_proto == nullptr) {
|
2014-12-27 18:59:06 +01:00
|
|
|
SSL_get0_alpn_selected(ssl, &next_proto, &next_proto_len);
|
2015-10-27 18:40:04 +01:00
|
|
|
}
|
|
|
|
#endif // OPENSSL_VERSION_NUMBER >= 0x10002000L
|
2015-09-14 15:33:48 +02:00
|
|
|
|
2015-10-27 18:40:04 +01:00
|
|
|
if (next_proto) {
|
2016-03-24 16:02:07 +01:00
|
|
|
auto proto = StringRef{next_proto, next_proto_len};
|
2019-06-08 15:05:25 +02:00
|
|
|
if (config.is_quic()) {
|
|
|
|
if (util::streq(StringRef{&NGTCP2_ALPN_H3[1]}, proto)) {
|
|
|
|
auto s = std::make_unique<Http3Session>(this);
|
|
|
|
if (s->init_conn() == -1) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
session = std::move(s);
|
|
|
|
}
|
|
|
|
} else if (util::check_h2_is_selected(proto)) {
|
2018-10-15 16:02:44 +02:00
|
|
|
session = std::make_unique<Http2Session>(this);
|
2016-03-24 17:41:06 +01:00
|
|
|
} else if (util::streq(NGHTTP2_H1_1, proto)) {
|
2018-10-15 16:02:44 +02:00
|
|
|
session = std::make_unique<Http1Session>(this);
|
2015-09-14 15:33:48 +02:00
|
|
|
}
|
2015-10-27 18:40:04 +01:00
|
|
|
|
|
|
|
// Just assign next_proto to selected_proto anyway to show the
|
|
|
|
// negotiation result.
|
2016-03-24 16:02:07 +01:00
|
|
|
selected_proto = proto.str();
|
2015-10-27 18:40:04 +01:00
|
|
|
} else {
|
|
|
|
std::cout << "No protocol negotiated. Fallback behaviour may be activated"
|
|
|
|
<< std::endl;
|
2014-12-27 18:59:06 +01:00
|
|
|
|
2015-09-14 15:33:48 +02:00
|
|
|
for (const auto &proto : config.npn_list) {
|
2016-03-24 17:41:06 +01:00
|
|
|
if (util::streq(NGHTTP2_H1_1_ALPN, StringRef{proto})) {
|
2015-09-14 15:33:48 +02:00
|
|
|
std::cout
|
|
|
|
<< "Server does not support NPN/ALPN. Falling back to HTTP/1.1."
|
|
|
|
<< std::endl;
|
2018-10-15 16:02:44 +02:00
|
|
|
session = std::make_unique<Http1Session>(this);
|
2016-03-24 17:41:06 +01:00
|
|
|
selected_proto = NGHTTP2_H1_1.str();
|
2015-09-14 15:33:48 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2015-10-27 18:40:04 +01:00
|
|
|
}
|
2015-09-14 15:33:48 +02:00
|
|
|
|
2015-10-27 18:40:04 +01:00
|
|
|
if (!selected_proto.empty()) {
|
|
|
|
report_app_info();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!session) {
|
|
|
|
std::cout
|
|
|
|
<< "No supported protocol was negotiated. Supported protocols were:"
|
|
|
|
<< std::endl;
|
|
|
|
for (const auto &proto : config.npn_list) {
|
|
|
|
std::cout << proto.substr(1) << std::endl;
|
2015-09-14 15:33:48 +02:00
|
|
|
}
|
2015-10-27 18:40:04 +01:00
|
|
|
disconnect();
|
|
|
|
return -1;
|
2014-12-27 18:59:06 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
switch (config.no_tls_proto) {
|
|
|
|
case Config::PROTO_HTTP2:
|
2018-10-15 16:02:44 +02:00
|
|
|
session = std::make_unique<Http2Session>(this);
|
2015-09-14 15:33:48 +02:00
|
|
|
selected_proto = NGHTTP2_CLEARTEXT_PROTO_VERSION_ID;
|
|
|
|
break;
|
|
|
|
case Config::PROTO_HTTP1_1:
|
2018-10-15 16:02:44 +02:00
|
|
|
session = std::make_unique<Http1Session>(this);
|
2016-03-24 17:41:06 +01:00
|
|
|
selected_proto = NGHTTP2_H1_1.str();
|
2014-12-27 18:59:06 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
// unreachable
|
|
|
|
assert(0);
|
|
|
|
}
|
2015-10-27 18:40:04 +01:00
|
|
|
|
|
|
|
report_app_info();
|
2014-12-27 18:59:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
state = CLIENT_CONNECTED;
|
|
|
|
|
2014-02-28 01:10:42 +01:00
|
|
|
session->on_connect();
|
|
|
|
|
2015-12-01 14:29:30 +01:00
|
|
|
record_connect_time();
|
2015-05-03 09:47:32 +02:00
|
|
|
|
2015-07-31 19:49:59 +02:00
|
|
|
if (!config.timing_script) {
|
2017-08-04 20:20:00 +02:00
|
|
|
auto nreq = config.is_timing_based_mode()
|
|
|
|
? std::max(req_left, session->max_concurrent_streams())
|
|
|
|
: std::min(req_left, session->max_concurrent_streams());
|
2015-07-31 19:49:59 +02:00
|
|
|
for (; nreq > 0; --nreq) {
|
2015-10-29 14:31:03 +01:00
|
|
|
if (submit_request() != 0) {
|
|
|
|
process_request_failure();
|
|
|
|
break;
|
|
|
|
}
|
2015-07-31 19:49:59 +02:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
|
|
|
|
ev_tstamp duration = config.timings[reqidx];
|
2014-12-27 18:59:06 +01:00
|
|
|
|
2015-07-31 19:49:59 +02:00
|
|
|
while (duration < 1e-9) {
|
2015-10-29 14:31:03 +01:00
|
|
|
if (submit_request() != 0) {
|
|
|
|
process_request_failure();
|
|
|
|
break;
|
|
|
|
}
|
2015-07-31 19:49:59 +02:00
|
|
|
duration = config.timings[reqidx];
|
2015-11-23 12:05:40 +01:00
|
|
|
if (reqidx == 0) {
|
|
|
|
// if reqidx wraps around back to 0, we uses up all lines and
|
|
|
|
// should break
|
2015-11-23 10:58:38 +01:00
|
|
|
break;
|
2015-11-23 12:05:40 +01:00
|
|
|
}
|
2015-07-31 19:49:59 +02:00
|
|
|
}
|
|
|
|
|
2015-11-23 12:05:40 +01:00
|
|
|
if (duration >= 1e-9) {
|
|
|
|
// double check since we may have break due to reqidx wraps
|
|
|
|
// around back to 0
|
2015-11-23 10:58:38 +01:00
|
|
|
request_timeout_watcher.repeat = duration;
|
|
|
|
ev_timer_again(worker->loop, &request_timeout_watcher);
|
|
|
|
}
|
2015-07-31 19:49:59 +02:00
|
|
|
}
|
2014-12-27 18:59:06 +01:00
|
|
|
signal_write();
|
|
|
|
|
|
|
|
return 0;
|
2014-02-28 01:10:42 +01:00
|
|
|
}
|
|
|
|
|
2014-12-27 18:59:06 +01:00
|
|
|
int Client::on_read(const uint8_t *data, size_t len) {
|
|
|
|
auto rv = session->on_read(data, len);
|
|
|
|
if (rv != 0) {
|
2014-02-28 01:10:42 +01:00
|
|
|
return -1;
|
|
|
|
}
|
2017-07-28 23:08:20 +02:00
|
|
|
if (worker->current_phase == Phase::MAIN_DURATION) {
|
|
|
|
worker->stats.bytes_total += len;
|
|
|
|
}
|
2014-12-27 18:59:06 +01:00
|
|
|
signal_write();
|
|
|
|
return 0;
|
|
|
|
}
|
2014-02-28 01:10:42 +01:00
|
|
|
|
2014-12-27 18:59:06 +01:00
|
|
|
int Client::on_write() {
|
2016-06-12 11:50:52 +02:00
|
|
|
if (wb.rleft() >= BACKOFF_WRITE_BUFFER_THRES) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-12-27 18:59:06 +01:00
|
|
|
if (session->on_write() != 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
2014-02-28 01:10:42 +01:00
|
|
|
}
|
|
|
|
|
2014-12-27 18:59:06 +01:00
|
|
|
int Client::read_clear() {
|
2015-06-21 07:32:47 +02:00
|
|
|
uint8_t buf[8_k];
|
2014-02-28 01:10:42 +01:00
|
|
|
|
2014-12-27 18:59:06 +01:00
|
|
|
for (;;) {
|
|
|
|
ssize_t nread;
|
|
|
|
while ((nread = read(fd, buf, sizeof(buf))) == -1 && errno == EINTR)
|
|
|
|
;
|
|
|
|
if (nread == -1) {
|
|
|
|
if (errno == EAGAIN || errno == EWOULDBLOCK) {
|
|
|
|
return 0;
|
|
|
|
}
|
2015-01-10 08:02:15 +01:00
|
|
|
return -1;
|
2014-12-27 18:59:06 +01:00
|
|
|
}
|
2014-06-22 04:33:16 +02:00
|
|
|
|
2014-12-27 18:59:06 +01:00
|
|
|
if (nread == 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
2014-06-22 04:33:16 +02:00
|
|
|
|
2014-12-27 18:59:06 +01:00
|
|
|
if (on_read(buf, nread) != 0) {
|
|
|
|
return -1;
|
2014-06-22 04:33:16 +02:00
|
|
|
}
|
2014-02-28 01:10:42 +01:00
|
|
|
}
|
2014-12-27 18:59:06 +01:00
|
|
|
|
|
|
|
return 0;
|
2014-02-28 01:10:42 +01:00
|
|
|
}
|
|
|
|
|
2014-12-27 18:59:06 +01:00
|
|
|
int Client::write_clear() {
|
2016-06-12 11:50:52 +02:00
|
|
|
std::array<struct iovec, 2> iov;
|
|
|
|
|
2014-12-27 18:59:06 +01:00
|
|
|
for (;;) {
|
|
|
|
if (on_write() != 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
2016-06-12 11:50:52 +02:00
|
|
|
|
|
|
|
auto iovcnt = wb.riovec(iov.data(), iov.size());
|
|
|
|
|
|
|
|
if (iovcnt == 0) {
|
2014-12-27 18:59:06 +01:00
|
|
|
break;
|
2014-02-28 01:10:42 +01:00
|
|
|
}
|
2016-06-12 11:50:52 +02:00
|
|
|
|
|
|
|
ssize_t nwrite;
|
|
|
|
while ((nwrite = writev(fd, iov.data(), iovcnt)) == -1 && errno == EINTR)
|
|
|
|
;
|
|
|
|
|
|
|
|
if (nwrite == -1) {
|
|
|
|
if (errno == EAGAIN || errno == EWOULDBLOCK) {
|
|
|
|
ev_io_start(worker->loop, &wev);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
wb.drain(nwrite);
|
2014-02-28 01:10:42 +01:00
|
|
|
}
|
2014-12-27 18:59:06 +01:00
|
|
|
|
|
|
|
ev_io_stop(worker->loop, &wev);
|
|
|
|
|
|
|
|
return 0;
|
2014-02-28 01:10:42 +01:00
|
|
|
}
|
|
|
|
|
2014-12-27 18:59:06 +01:00
|
|
|
int Client::connected() {
|
2015-01-04 17:56:02 +01:00
|
|
|
if (!util::check_socket_connected(fd)) {
|
|
|
|
return ERR_CONNECT_FAIL;
|
|
|
|
}
|
2014-12-27 18:59:06 +01:00
|
|
|
ev_io_start(worker->loop, &rev);
|
|
|
|
ev_io_stop(worker->loop, &wev);
|
|
|
|
|
|
|
|
if (ssl) {
|
|
|
|
readfn = &Client::tls_handshake;
|
|
|
|
writefn = &Client::tls_handshake;
|
|
|
|
|
|
|
|
return do_write();
|
|
|
|
}
|
|
|
|
|
|
|
|
readfn = &Client::read_clear;
|
|
|
|
writefn = &Client::write_clear;
|
|
|
|
|
2015-03-28 12:13:37 +01:00
|
|
|
if (connection_made() != 0) {
|
2014-12-27 18:59:06 +01:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2014-02-28 01:10:42 +01:00
|
|
|
}
|
|
|
|
|
2014-12-27 18:59:06 +01:00
|
|
|
int Client::tls_handshake() {
|
2015-01-09 01:10:59 +01:00
|
|
|
ERR_clear_error();
|
|
|
|
|
2014-12-27 18:59:06 +01:00
|
|
|
auto rv = SSL_do_handshake(ssl);
|
2014-02-28 01:10:42 +01:00
|
|
|
|
2015-09-29 16:31:50 +02:00
|
|
|
if (rv <= 0) {
|
2014-12-27 18:59:06 +01:00
|
|
|
auto err = SSL_get_error(ssl, rv);
|
|
|
|
switch (err) {
|
|
|
|
case SSL_ERROR_WANT_READ:
|
|
|
|
ev_io_stop(worker->loop, &wev);
|
|
|
|
return 0;
|
|
|
|
case SSL_ERROR_WANT_WRITE:
|
|
|
|
ev_io_start(worker->loop, &wev);
|
|
|
|
return 0;
|
|
|
|
default:
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ev_io_stop(worker->loop, &wev);
|
|
|
|
|
|
|
|
readfn = &Client::read_tls;
|
|
|
|
writefn = &Client::write_tls;
|
|
|
|
|
2015-03-28 12:13:37 +01:00
|
|
|
if (connection_made() != 0) {
|
2014-12-27 18:59:06 +01:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int Client::read_tls() {
|
2015-06-21 07:32:47 +02:00
|
|
|
uint8_t buf[8_k];
|
2015-01-09 01:10:59 +01:00
|
|
|
|
|
|
|
ERR_clear_error();
|
|
|
|
|
2014-12-27 18:59:06 +01:00
|
|
|
for (;;) {
|
|
|
|
auto rv = SSL_read(ssl, buf, sizeof(buf));
|
|
|
|
|
2015-09-29 16:31:50 +02:00
|
|
|
if (rv <= 0) {
|
2014-12-27 18:59:06 +01:00
|
|
|
auto err = SSL_get_error(ssl, rv);
|
|
|
|
switch (err) {
|
|
|
|
case SSL_ERROR_WANT_READ:
|
|
|
|
return 0;
|
|
|
|
case SSL_ERROR_WANT_WRITE:
|
2015-01-09 01:10:59 +01:00
|
|
|
// renegotiation started
|
|
|
|
return -1;
|
2014-04-21 14:35:45 +02:00
|
|
|
default:
|
2014-12-27 18:59:06 +01:00
|
|
|
return -1;
|
2014-04-21 14:35:45 +02:00
|
|
|
}
|
2014-02-28 01:10:42 +01:00
|
|
|
}
|
2014-12-27 18:59:06 +01:00
|
|
|
|
|
|
|
if (on_read(buf, rv) != 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
2014-02-28 01:10:42 +01:00
|
|
|
}
|
2014-12-27 18:59:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int Client::write_tls() {
|
2015-01-09 01:10:59 +01:00
|
|
|
ERR_clear_error();
|
|
|
|
|
2016-06-12 11:50:52 +02:00
|
|
|
struct iovec iov;
|
2014-12-27 18:59:06 +01:00
|
|
|
|
2016-06-12 11:50:52 +02:00
|
|
|
for (;;) {
|
2014-12-27 18:59:06 +01:00
|
|
|
if (on_write() != 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
2016-06-12 11:50:52 +02:00
|
|
|
|
|
|
|
auto iovcnt = wb.riovec(&iov, 1);
|
|
|
|
|
|
|
|
if (iovcnt == 0) {
|
2014-12-27 18:59:06 +01:00
|
|
|
break;
|
2014-02-28 01:10:42 +01:00
|
|
|
}
|
2016-06-12 11:50:52 +02:00
|
|
|
|
|
|
|
auto rv = SSL_write(ssl, iov.iov_base, iov.iov_len);
|
|
|
|
|
|
|
|
if (rv <= 0) {
|
|
|
|
auto err = SSL_get_error(ssl, rv);
|
|
|
|
switch (err) {
|
|
|
|
case SSL_ERROR_WANT_READ:
|
|
|
|
// renegotiation started
|
|
|
|
return -1;
|
|
|
|
case SSL_ERROR_WANT_WRITE:
|
|
|
|
ev_io_start(worker->loop, &wev);
|
|
|
|
return 0;
|
|
|
|
default:
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
wb.drain(rv);
|
2014-02-28 01:10:42 +01:00
|
|
|
}
|
2014-12-27 18:59:06 +01:00
|
|
|
|
|
|
|
ev_io_stop(worker->loop, &wev);
|
|
|
|
|
|
|
|
return 0;
|
2014-02-28 01:10:42 +01:00
|
|
|
}
|
|
|
|
|
2019-06-08 15:05:25 +02:00
|
|
|
int Client::write_udp(const sockaddr *addr, socklen_t addrlen,
|
|
|
|
const uint8_t *data, size_t datalen) {
|
|
|
|
auto nwrite = sendto(fd, data, datalen, MSG_DONTWAIT, addr, addrlen);
|
|
|
|
if (nwrite < 0) {
|
|
|
|
std::cerr << "sendto: errno=" << errno << std::endl;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-01-31 10:13:07 +01:00
|
|
|
void Client::record_request_time(RequestStat *req_stat) {
|
|
|
|
req_stat->request_time = std::chrono::steady_clock::now();
|
2018-11-11 19:33:50 +01:00
|
|
|
req_stat->request_wall_time = std::chrono::system_clock::now();
|
2015-01-31 10:13:07 +01:00
|
|
|
}
|
|
|
|
|
2015-12-01 14:29:30 +01:00
|
|
|
void Client::record_connect_start_time() {
|
|
|
|
cstat.connect_start_time = std::chrono::steady_clock::now();
|
2015-04-30 00:29:37 +02:00
|
|
|
}
|
|
|
|
|
2015-12-01 14:29:30 +01:00
|
|
|
void Client::record_connect_time() {
|
|
|
|
cstat.connect_time = std::chrono::steady_clock::now();
|
2015-04-30 00:29:37 +02:00
|
|
|
}
|
|
|
|
|
2015-09-12 04:18:54 +02:00
|
|
|
void Client::record_ttfb() {
|
2015-12-01 14:29:30 +01:00
|
|
|
if (recorded(cstat.ttfb)) {
|
2015-09-12 04:18:54 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-12-01 14:29:30 +01:00
|
|
|
cstat.ttfb = std::chrono::steady_clock::now();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Client::clear_connect_times() {
|
|
|
|
cstat.connect_start_time = std::chrono::steady_clock::time_point();
|
|
|
|
cstat.connect_time = std::chrono::steady_clock::time_point();
|
|
|
|
cstat.ttfb = std::chrono::steady_clock::time_point();
|
2015-04-30 00:29:37 +02:00
|
|
|
}
|
|
|
|
|
2015-12-01 15:49:28 +01:00
|
|
|
void Client::record_client_start_time() {
|
|
|
|
// Record start time only once at the very first connection is going
|
|
|
|
// to be made.
|
|
|
|
if (recorded(cstat.client_start_time)) {
|
|
|
|
return;
|
|
|
|
}
|
2017-08-23 12:19:00 +02:00
|
|
|
|
2015-12-01 15:49:28 +01:00
|
|
|
cstat.client_start_time = std::chrono::steady_clock::now();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Client::record_client_end_time() {
|
|
|
|
// Unlike client_start_time, we overwrite client_end_time. This
|
|
|
|
// handles multiple connect/disconnect for HTTP/1.1 benchmark.
|
|
|
|
cstat.client_end_time = std::chrono::steady_clock::now();
|
|
|
|
}
|
|
|
|
|
2014-12-27 18:59:06 +01:00
|
|
|
void Client::signal_write() { ev_io_start(worker->loop, &wev); }
|
|
|
|
|
2015-09-28 16:57:58 +02:00
|
|
|
void Client::try_new_connection() { new_connection_requested = true; }
|
|
|
|
|
2016-05-06 16:40:55 +02:00
|
|
|
namespace {
|
|
|
|
int get_ev_loop_flags() {
|
|
|
|
if (ev_supported_backends() & ~ev_recommended_backends() & EVBACKEND_KQUEUE) {
|
|
|
|
return ev_recommended_backends() | EVBACKEND_KQUEUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
} // namespace
|
|
|
|
|
2014-12-27 18:59:06 +01:00
|
|
|
Worker::Worker(uint32_t id, SSL_CTX *ssl_ctx, size_t req_todo, size_t nclients,
|
2016-01-07 14:41:37 +01:00
|
|
|
size_t rate, size_t max_samples, Config *config)
|
2016-01-27 13:14:07 +01:00
|
|
|
: stats(req_todo, nclients),
|
2016-05-06 16:40:55 +02:00
|
|
|
loop(ev_loop_new(get_ev_loop_flags())),
|
2016-01-27 13:14:07 +01:00
|
|
|
ssl_ctx(ssl_ctx),
|
|
|
|
config(config),
|
|
|
|
id(id),
|
|
|
|
tls_info_report_done(false),
|
|
|
|
app_info_report_done(false),
|
|
|
|
nconns_made(0),
|
|
|
|
nclients(nclients),
|
|
|
|
nreqs_per_client(req_todo / nclients),
|
|
|
|
nreqs_rem(req_todo % nclients),
|
|
|
|
rate(rate),
|
|
|
|
max_samples(max_samples),
|
2018-11-23 04:46:11 +01:00
|
|
|
next_client_id(0) {
|
2017-07-28 23:08:20 +02:00
|
|
|
if (!config->is_rate_mode() && !config->is_timing_based_mode()) {
|
2016-01-05 15:56:31 +01:00
|
|
|
progress_interval = std::max(static_cast<size_t>(1), req_todo / 10);
|
|
|
|
} else {
|
|
|
|
progress_interval = std::max(static_cast<size_t>(1), nclients / 10);
|
|
|
|
}
|
2014-12-27 18:59:06 +01:00
|
|
|
|
2017-07-28 23:08:20 +02:00
|
|
|
// Below timeout is not needed in case of timing-based benchmarking
|
2015-10-05 17:27:00 +02:00
|
|
|
// create timer that will go off every rate_period
|
|
|
|
ev_timer_init(&timeout_watcher, rate_period_timeout_w_cb, 0.,
|
|
|
|
config->rate_period);
|
2015-08-11 16:44:22 +02:00
|
|
|
timeout_watcher.data = this;
|
|
|
|
|
2017-08-03 22:15:14 +02:00
|
|
|
if (config->is_timing_based_mode()) {
|
|
|
|
stats.req_stats.reserve(std::max(req_todo, max_samples));
|
|
|
|
stats.client_stats.reserve(std::max(nclients, max_samples));
|
|
|
|
} else {
|
|
|
|
stats.req_stats.reserve(std::min(req_todo, max_samples));
|
|
|
|
stats.client_stats.reserve(std::min(nclients, max_samples));
|
|
|
|
}
|
2016-01-07 14:41:37 +01:00
|
|
|
|
2017-08-14 13:25:02 +02:00
|
|
|
sampling_init(request_times_smp, max_samples);
|
|
|
|
sampling_init(client_smp, max_samples);
|
2017-07-28 23:08:20 +02:00
|
|
|
|
2017-08-08 23:26:37 +02:00
|
|
|
ev_timer_init(&duration_watcher, duration_timeout_cb, config->duration, 0.);
|
|
|
|
duration_watcher.data = this;
|
2017-07-28 23:08:20 +02:00
|
|
|
|
2017-08-08 23:26:37 +02:00
|
|
|
ev_timer_init(&warmup_watcher, warmup_timeout_cb, config->warm_up_time, 0.);
|
|
|
|
warmup_watcher.data = this;
|
|
|
|
|
|
|
|
if (config->is_timing_based_mode()) {
|
2017-08-02 02:22:20 +02:00
|
|
|
current_phase = Phase::INITIAL_IDLE;
|
2017-08-02 01:51:47 +02:00
|
|
|
} else {
|
|
|
|
current_phase = Phase::MAIN_DURATION;
|
2017-07-28 23:08:20 +02:00
|
|
|
}
|
2014-02-28 01:10:42 +01:00
|
|
|
}
|
|
|
|
|
2014-12-27 18:59:06 +01:00
|
|
|
Worker::~Worker() {
|
2015-08-11 16:51:08 +02:00
|
|
|
ev_timer_stop(loop, &timeout_watcher);
|
2017-08-08 23:26:37 +02:00
|
|
|
ev_timer_stop(loop, &duration_watcher);
|
|
|
|
ev_timer_stop(loop, &warmup_watcher);
|
2014-12-27 18:59:06 +01:00
|
|
|
ev_loop_destroy(loop);
|
|
|
|
}
|
|
|
|
|
2017-07-28 23:08:20 +02:00
|
|
|
void Worker::stop_all_clients() {
|
|
|
|
for (auto client : clients) {
|
2017-08-08 00:58:12 +02:00
|
|
|
if (client && client->session) {
|
2017-07-28 23:08:20 +02:00
|
|
|
client->terminate_session();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-08 23:26:37 +02:00
|
|
|
void Worker::free_client(Client *deleted_client) {
|
|
|
|
for (auto &client : clients) {
|
2017-08-08 00:58:12 +02:00
|
|
|
if (client == deleted_client) {
|
|
|
|
client->req_todo = client->req_done;
|
|
|
|
stats.req_todo += client->req_todo;
|
|
|
|
auto index = &client - &clients[0];
|
|
|
|
clients[index] = NULL;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-27 18:59:06 +01:00
|
|
|
void Worker::run() {
|
2017-07-28 23:08:20 +02:00
|
|
|
if (!config->is_rate_mode() && !config->is_timing_based_mode()) {
|
2016-01-05 15:25:09 +01:00
|
|
|
for (size_t i = 0; i < nclients; ++i) {
|
|
|
|
auto req_todo = nreqs_per_client;
|
|
|
|
if (nreqs_rem > 0) {
|
|
|
|
++req_todo;
|
|
|
|
--nreqs_rem;
|
|
|
|
}
|
2017-07-28 23:08:20 +02:00
|
|
|
|
2018-10-15 16:02:44 +02:00
|
|
|
auto client = std::make_unique<Client>(next_client_id++, this, req_todo);
|
2015-07-21 20:06:33 +02:00
|
|
|
if (client->connect() != 0) {
|
|
|
|
std::cerr << "client could not connect to host" << std::endl;
|
|
|
|
client->fail();
|
2016-01-05 15:25:09 +01:00
|
|
|
} else {
|
|
|
|
client.release();
|
2015-07-21 20:06:33 +02:00
|
|
|
}
|
2014-12-27 18:59:06 +01:00
|
|
|
}
|
2017-08-23 12:19:00 +02:00
|
|
|
} else if (config->is_rate_mode()) {
|
2015-07-21 20:28:12 +02:00
|
|
|
ev_timer_again(loop, &timeout_watcher);
|
2015-07-24 23:34:53 +02:00
|
|
|
|
2015-10-05 17:27:00 +02:00
|
|
|
// call callback so that we don't waste the first rate_period
|
|
|
|
rate_period_timeout_w_cb(loop, &timeout_watcher, 0);
|
2017-07-28 23:08:20 +02:00
|
|
|
} else {
|
|
|
|
// call the callback to start for one single time
|
|
|
|
rate_period_timeout_w_cb(loop, &timeout_watcher, 0);
|
2014-02-28 01:10:42 +01:00
|
|
|
}
|
2014-12-27 18:59:06 +01:00
|
|
|
ev_run(loop, 0);
|
2014-02-28 01:10:42 +01:00
|
|
|
}
|
|
|
|
|
2017-08-14 13:25:02 +02:00
|
|
|
namespace {
|
|
|
|
template <typename Stats, typename Stat>
|
|
|
|
void sample(Sampling &smp, Stats &stats, Stat *s) {
|
|
|
|
++smp.n;
|
|
|
|
if (stats.size() < smp.max_samples) {
|
|
|
|
stats.push_back(*s);
|
|
|
|
return;
|
|
|
|
}
|
2017-09-20 15:08:08 +02:00
|
|
|
auto d = std::uniform_int_distribution<unsigned long>(0, smp.n - 1);
|
2017-08-14 13:25:02 +02:00
|
|
|
auto i = d(gen);
|
|
|
|
if (i < smp.max_samples) {
|
|
|
|
stats[i] = *s;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} // namespace
|
|
|
|
|
2016-01-05 14:36:37 +01:00
|
|
|
void Worker::sample_req_stat(RequestStat *req_stat) {
|
2017-08-14 13:25:02 +02:00
|
|
|
sample(request_times_smp, stats.req_stats, req_stat);
|
2016-01-05 14:36:37 +01:00
|
|
|
}
|
|
|
|
|
2016-01-06 15:03:37 +01:00
|
|
|
void Worker::sample_client_stat(ClientStat *cstat) {
|
2017-08-14 13:25:02 +02:00
|
|
|
sample(client_smp, stats.client_stats, cstat);
|
2016-01-06 15:03:37 +01:00
|
|
|
}
|
|
|
|
|
2016-01-05 15:56:31 +01:00
|
|
|
void Worker::report_progress() {
|
2017-08-23 12:19:00 +02:00
|
|
|
if (id != 0 || config->is_rate_mode() || stats.req_done % progress_interval ||
|
|
|
|
config->is_timing_based_mode()) {
|
2016-01-05 15:56:31 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2015-01-31 10:13:07 +01:00
|
|
|
namespace {
|
2015-05-04 04:48:21 +02:00
|
|
|
// Returns percentage of number of samples within mean +/- sd.
|
2015-12-01 15:49:28 +01:00
|
|
|
double within_sd(const std::vector<double> &samples, double mean, double sd) {
|
2015-05-04 04:48:21 +02:00
|
|
|
if (samples.size() == 0) {
|
|
|
|
return 0.0;
|
|
|
|
}
|
|
|
|
auto lower = mean - sd;
|
|
|
|
auto upper = mean + sd;
|
|
|
|
auto m = std::count_if(
|
|
|
|
std::begin(samples), std::end(samples),
|
2015-12-01 15:49:28 +01:00
|
|
|
[&lower, &upper](double t) { return lower <= t && t <= upper; });
|
2015-05-04 04:48:21 +02:00
|
|
|
return (m / static_cast<double>(samples.size())) * 100;
|
2015-01-31 10:13:07 +01:00
|
|
|
}
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
namespace {
|
2015-05-04 04:48:21 +02:00
|
|
|
// Computes statistics using |samples|. The min, max, mean, sd, and
|
|
|
|
// percentage of number of samples within mean +/- sd are computed.
|
2016-01-05 14:36:37 +01:00
|
|
|
// If |sampling| is true, this computes sample variance. Otherwise,
|
|
|
|
// population variance.
|
|
|
|
SDStat compute_time_stat(const std::vector<double> &samples,
|
|
|
|
bool sampling = false) {
|
2015-06-09 17:28:27 +02:00
|
|
|
if (samples.empty()) {
|
2015-12-01 15:49:28 +01:00
|
|
|
return {0.0, 0.0, 0.0, 0.0, 0.0};
|
2015-05-04 04:48:21 +02:00
|
|
|
}
|
|
|
|
// standard deviation calculated using Rapid calculation method:
|
2016-01-05 14:36:37 +01:00
|
|
|
// https://en.wikipedia.org/wiki/Standard_deviation#Rapid_calculation_methods
|
2015-05-04 04:48:21 +02:00
|
|
|
double a = 0, q = 0;
|
2015-01-31 10:13:07 +01:00
|
|
|
size_t n = 0;
|
2015-12-01 15:49:28 +01:00
|
|
|
double sum = 0;
|
|
|
|
auto res = SDStat{std::numeric_limits<double>::max(),
|
|
|
|
std::numeric_limits<double>::min()};
|
2015-05-04 04:48:21 +02:00
|
|
|
for (const auto &t : samples) {
|
|
|
|
++n;
|
|
|
|
res.min = std::min(res.min, t);
|
|
|
|
res.max = std::max(res.max, t);
|
2015-12-01 15:49:28 +01:00
|
|
|
sum += t;
|
2015-01-31 10:13:07 +01:00
|
|
|
|
2015-12-01 15:49:28 +01:00
|
|
|
auto na = a + (t - a) / n;
|
|
|
|
q += (t - a) * (t - na);
|
2015-05-04 04:48:21 +02:00
|
|
|
a = na;
|
|
|
|
}
|
2015-04-30 00:29:37 +02:00
|
|
|
|
2015-06-09 17:29:03 +02:00
|
|
|
assert(n > 0);
|
2015-12-01 15:49:28 +01:00
|
|
|
res.mean = sum / n;
|
2016-01-05 14:36:37 +01:00
|
|
|
res.sd = sqrt(q / (sampling && n > 1 ? n - 1 : n));
|
2015-05-04 04:48:21 +02:00
|
|
|
res.within_sd = within_sd(samples, res.mean, res.sd);
|
2015-04-30 00:29:37 +02:00
|
|
|
|
2015-05-04 04:48:21 +02:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
namespace {
|
2015-12-01 15:49:28 +01:00
|
|
|
SDStats
|
2015-05-04 04:48:21 +02:00
|
|
|
process_time_stats(const std::vector<std::unique_ptr<Worker>> &workers) {
|
2016-01-05 14:36:37 +01:00
|
|
|
auto request_times_sampling = false;
|
2016-01-07 14:41:37 +01:00
|
|
|
auto client_times_sampling = false;
|
2015-12-01 14:29:30 +01:00
|
|
|
size_t nrequest_times = 0;
|
2016-01-07 14:41:37 +01:00
|
|
|
size_t nclient_times = 0;
|
2015-05-04 04:48:21 +02:00
|
|
|
for (const auto &w : workers) {
|
|
|
|
nrequest_times += w->stats.req_stats.size();
|
2017-08-14 13:25:02 +02:00
|
|
|
request_times_sampling = w->request_times_smp.n > w->stats.req_stats.size();
|
2016-01-07 14:41:37 +01:00
|
|
|
|
|
|
|
nclient_times += w->stats.client_stats.size();
|
2017-08-14 13:25:02 +02:00
|
|
|
client_times_sampling = w->client_smp.n > w->stats.client_stats.size();
|
2015-05-04 04:48:21 +02:00
|
|
|
}
|
|
|
|
|
2015-12-01 15:49:28 +01:00
|
|
|
std::vector<double> request_times;
|
2015-05-04 04:48:21 +02:00
|
|
|
request_times.reserve(nrequest_times);
|
2015-12-01 14:29:30 +01:00
|
|
|
|
2015-12-01 15:49:28 +01:00
|
|
|
std::vector<double> connect_times, ttfb_times, rps_values;
|
2016-01-07 14:41:37 +01:00
|
|
|
connect_times.reserve(nclient_times);
|
|
|
|
ttfb_times.reserve(nclient_times);
|
|
|
|
rps_values.reserve(nclient_times);
|
2015-01-31 10:13:07 +01:00
|
|
|
|
|
|
|
for (const auto &w : workers) {
|
|
|
|
for (const auto &req_stat : w->stats.req_stats) {
|
|
|
|
if (!req_stat.completed) {
|
|
|
|
continue;
|
|
|
|
}
|
2015-05-04 04:48:21 +02:00
|
|
|
request_times.push_back(
|
2015-12-01 15:49:28 +01:00
|
|
|
std::chrono::duration_cast<std::chrono::duration<double>>(
|
2016-10-15 11:36:04 +02:00
|
|
|
req_stat.stream_close_time - req_stat.request_time)
|
|
|
|
.count());
|
2015-04-30 00:29:37 +02:00
|
|
|
}
|
2015-05-04 04:48:21 +02:00
|
|
|
|
|
|
|
const auto &stat = w->stats;
|
2015-12-01 14:29:30 +01:00
|
|
|
|
|
|
|
for (const auto &cstat : stat.client_stats) {
|
2015-12-01 15:49:28 +01:00
|
|
|
if (recorded(cstat.client_start_time) &&
|
|
|
|
recorded(cstat.client_end_time)) {
|
|
|
|
auto t = std::chrono::duration_cast<std::chrono::duration<double>>(
|
2016-10-15 11:36:04 +02:00
|
|
|
cstat.client_end_time - cstat.client_start_time)
|
|
|
|
.count();
|
2015-12-01 15:49:28 +01:00
|
|
|
if (t > 1e-9) {
|
|
|
|
rps_values.push_back(cstat.req_success / t);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-01 14:29:30 +01:00
|
|
|
// We will get connect event before FFTB.
|
|
|
|
if (!recorded(cstat.connect_start_time) ||
|
|
|
|
!recorded(cstat.connect_time)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2015-05-04 04:48:21 +02:00
|
|
|
connect_times.push_back(
|
2015-12-01 15:49:28 +01:00
|
|
|
std::chrono::duration_cast<std::chrono::duration<double>>(
|
2016-10-15 11:36:04 +02:00
|
|
|
cstat.connect_time - cstat.connect_start_time)
|
|
|
|
.count());
|
2015-12-01 14:29:30 +01:00
|
|
|
|
|
|
|
if (!recorded(cstat.ttfb)) {
|
|
|
|
continue;
|
|
|
|
}
|
2015-05-04 04:48:21 +02:00
|
|
|
|
|
|
|
ttfb_times.push_back(
|
2015-12-01 15:49:28 +01:00
|
|
|
std::chrono::duration_cast<std::chrono::duration<double>>(
|
2016-10-15 11:36:04 +02:00
|
|
|
cstat.ttfb - cstat.connect_start_time)
|
|
|
|
.count());
|
2015-01-31 10:13:07 +01:00
|
|
|
}
|
|
|
|
}
|
2015-05-04 04:48:21 +02:00
|
|
|
|
2016-01-05 14:36:37 +01:00
|
|
|
return {compute_time_stat(request_times, request_times_sampling),
|
2016-01-07 14:41:37 +01:00
|
|
|
compute_time_stat(connect_times, client_times_sampling),
|
|
|
|
compute_time_stat(ttfb_times, client_times_sampling),
|
|
|
|
compute_time_stat(rps_values, client_times_sampling)};
|
2015-01-31 10:13:07 +01:00
|
|
|
}
|
|
|
|
} // namespace
|
|
|
|
|
2014-02-28 01:10:42 +01:00
|
|
|
namespace {
|
2014-11-27 15:39:04 +01:00
|
|
|
void resolve_host() {
|
2016-01-19 11:24:15 +01:00
|
|
|
if (config.base_uri_unix) {
|
2018-10-15 16:02:44 +02:00
|
|
|
auto res = std::make_unique<addrinfo>();
|
2016-01-19 11:24:15 +01:00
|
|
|
res->ai_family = config.unix_addr.sun_family;
|
|
|
|
res->ai_socktype = SOCK_STREAM;
|
|
|
|
res->ai_addrlen = sizeof(config.unix_addr);
|
|
|
|
res->ai_addr =
|
|
|
|
static_cast<struct sockaddr *>(static_cast<void *>(&config.unix_addr));
|
|
|
|
|
|
|
|
config.addrs = res.release();
|
|
|
|
return;
|
|
|
|
};
|
|
|
|
|
2014-02-28 01:10:42 +01:00
|
|
|
int rv;
|
2015-07-19 10:55:37 +02:00
|
|
|
addrinfo hints{}, *res;
|
2014-02-28 01:10:42 +01:00
|
|
|
|
|
|
|
hints.ai_family = AF_UNSPEC;
|
|
|
|
hints.ai_socktype = SOCK_STREAM;
|
|
|
|
hints.ai_protocol = 0;
|
|
|
|
hints.ai_flags = AI_ADDRCONFIG;
|
|
|
|
|
2019-12-12 17:33:34 +01:00
|
|
|
const auto &resolve_host =
|
|
|
|
config.connect_to_host.empty() ? config.host : config.connect_to_host;
|
2019-12-21 03:38:27 +01:00
|
|
|
auto port =
|
|
|
|
config.connect_to_port == 0 ? config.port : config.connect_to_port;
|
2019-12-12 17:33:34 +01:00
|
|
|
|
2019-12-21 03:38:27 +01:00
|
|
|
rv =
|
|
|
|
getaddrinfo(resolve_host.c_str(), util::utos(port).c_str(), &hints, &res);
|
2014-11-27 15:39:04 +01:00
|
|
|
if (rv != 0) {
|
|
|
|
std::cerr << "getaddrinfo() failed: " << gai_strerror(rv) << std::endl;
|
2014-02-28 01:10:42 +01:00
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
2014-11-27 15:39:04 +01:00
|
|
|
if (res == nullptr) {
|
2014-02-28 01:10:42 +01:00
|
|
|
std::cerr << "No address returned" << std::endl;
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
config.addrs = res;
|
|
|
|
}
|
|
|
|
} // namespace
|
|
|
|
|
2014-03-14 15:15:01 +01:00
|
|
|
namespace {
|
2014-11-27 15:39:04 +01:00
|
|
|
std::string get_reqline(const char *uri, const http_parser_url &u) {
|
2014-03-14 15:15:01 +01:00
|
|
|
std::string reqline;
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (util::has_uri_field(u, UF_PATH)) {
|
2016-03-08 13:38:15 +01:00
|
|
|
reqline = util::get_uri_field(uri, u, UF_PATH).str();
|
2014-03-14 15:15:01 +01:00
|
|
|
} else {
|
|
|
|
reqline = "/";
|
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (util::has_uri_field(u, UF_QUERY)) {
|
2015-11-27 16:03:16 +01:00
|
|
|
reqline += '?';
|
2014-03-14 15:15:01 +01:00
|
|
|
reqline += util::get_uri_field(uri, u, UF_QUERY);
|
|
|
|
}
|
|
|
|
|
|
|
|
return reqline;
|
|
|
|
}
|
|
|
|
} // namespace
|
|
|
|
|
2018-04-03 14:33:09 +02:00
|
|
|
#ifndef OPENSSL_NO_NEXTPROTONEG
|
2014-02-28 01:10:42 +01:00
|
|
|
namespace {
|
2014-11-27 15:39:04 +01:00
|
|
|
int client_select_next_proto_cb(SSL *ssl, unsigned char **out,
|
|
|
|
unsigned char *outlen, const unsigned char *in,
|
|
|
|
unsigned int inlen, void *arg) {
|
2015-09-14 15:33:48 +02:00
|
|
|
if (util::select_protocol(const_cast<const unsigned char **>(out), outlen, in,
|
|
|
|
inlen, config.npn_list)) {
|
2014-02-28 01:10:42 +01:00
|
|
|
return SSL_TLSEXT_ERR_OK;
|
|
|
|
}
|
2015-11-05 13:26:38 +01:00
|
|
|
|
|
|
|
// OpenSSL will terminate handshake with fatal alert if we return
|
|
|
|
// NOACK. So there is no way to fallback.
|
|
|
|
return SSL_TLSEXT_ERR_NOACK;
|
2014-02-28 01:10:42 +01:00
|
|
|
}
|
|
|
|
} // namespace
|
2018-04-03 14:33:09 +02:00
|
|
|
#endif // !OPENSSL_NO_NEXTPROTONEG
|
2014-02-28 01:10:42 +01:00
|
|
|
|
2019-06-08 15:05:25 +02:00
|
|
|
namespace {
|
|
|
|
int quic_transport_params_add_cb(SSL *ssl, unsigned int ext_type,
|
|
|
|
unsigned int content,
|
|
|
|
const unsigned char **out, size_t *outlen,
|
|
|
|
X509 *x, size_t chainidx, int *al,
|
|
|
|
void *add_arg) {
|
|
|
|
auto c = static_cast<Client *>(SSL_get_app_data(ssl));
|
|
|
|
auto conn = c->quic.conn;
|
|
|
|
|
|
|
|
ngtcp2_transport_params params;
|
|
|
|
|
|
|
|
ngtcp2_conn_get_local_transport_params(conn, ¶ms);
|
|
|
|
|
|
|
|
constexpr size_t bufsize = 128;
|
|
|
|
auto buf = std::make_unique<uint8_t[]>(bufsize);
|
|
|
|
|
|
|
|
auto nwrite = ngtcp2_encode_transport_params(
|
|
|
|
buf.get(), bufsize, NGTCP2_TRANSPORT_PARAMS_TYPE_CLIENT_HELLO, ¶ms);
|
|
|
|
if (nwrite < 0) {
|
|
|
|
std::cerr << "ngtcp2_encode_transport_params: " << ngtcp2_strerror(nwrite)
|
|
|
|
<< std::endl;
|
|
|
|
*al = SSL_AD_INTERNAL_ERROR;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
*out = buf.release();
|
|
|
|
*outlen = static_cast<size_t>(nwrite);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
void quic_transport_params_free_cb(SSL *ssl, unsigned int ext_type,
|
|
|
|
unsigned int context,
|
|
|
|
const unsigned char *out, void *add_arg) {
|
|
|
|
delete[] const_cast<unsigned char *>(out);
|
|
|
|
}
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
int quic_transport_params_parse_cb(SSL *ssl, unsigned int ext_type,
|
|
|
|
unsigned int context,
|
|
|
|
const unsigned char *in, size_t inlen,
|
|
|
|
X509 *x, size_t chainidx, int *al,
|
|
|
|
void *parse_arg) {
|
|
|
|
auto c = static_cast<Client *>(SSL_get_app_data(ssl));
|
|
|
|
auto conn = c->quic.conn;
|
|
|
|
|
|
|
|
int rv;
|
|
|
|
ngtcp2_transport_params params;
|
|
|
|
|
|
|
|
rv = ngtcp2_decode_transport_params(
|
|
|
|
¶ms, NGTCP2_TRANSPORT_PARAMS_TYPE_ENCRYPTED_EXTENSIONS, in, inlen);
|
|
|
|
if (rv != 0) {
|
|
|
|
std::cerr << "ngtcp2_decode_transport_params: " << ngtcp2_strerror(rv)
|
|
|
|
<< std::endl;
|
|
|
|
*al = SSL_AD_ILLEGAL_PARAMETER;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = ngtcp2_conn_set_remote_transport_params(conn, ¶ms);
|
|
|
|
if (rv != 0) {
|
|
|
|
std::cerr << "ngtcp2_conn_set_remote_transport_params: "
|
|
|
|
<< ngtcp2_strerror(rv) << std::endl;
|
|
|
|
*al = SSL_AD_ILLEGAL_PARAMETER;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
} // namespace
|
|
|
|
|
2016-01-19 11:24:15 +01:00
|
|
|
namespace {
|
|
|
|
constexpr char UNIX_PATH_PREFIX[] = "unix:";
|
|
|
|
} // namespace
|
|
|
|
|
2015-07-31 19:49:59 +02:00
|
|
|
namespace {
|
2016-03-25 15:18:31 +01:00
|
|
|
bool parse_base_uri(const StringRef &base_uri) {
|
2015-07-31 19:49:59 +02:00
|
|
|
http_parser_url u{};
|
|
|
|
if (http_parser_parse_url(base_uri.c_str(), base_uri.size(), 0, &u) != 0 ||
|
|
|
|
!util::has_uri_field(u, UF_SCHEMA) || !util::has_uri_field(u, UF_HOST)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-03-08 13:38:15 +01:00
|
|
|
config.scheme = util::get_uri_field(base_uri.c_str(), u, UF_SCHEMA).str();
|
|
|
|
config.host = util::get_uri_field(base_uri.c_str(), u, UF_HOST).str();
|
2015-07-31 19:49:59 +02:00
|
|
|
config.default_port = util::get_default_port(base_uri.c_str(), u);
|
|
|
|
if (util::has_uri_field(u, UF_PORT)) {
|
|
|
|
config.port = u.port;
|
|
|
|
} else {
|
|
|
|
config.port = config.default_port;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
} // namespace
|
2014-10-22 15:42:40 +02:00
|
|
|
namespace {
|
2015-07-19 11:35:14 +02:00
|
|
|
// Use std::vector<std::string>::iterator explicitly, without that,
|
|
|
|
// http_parser_url u{} fails with clang-3.4.
|
|
|
|
std::vector<std::string> parse_uris(std::vector<std::string>::iterator first,
|
|
|
|
std::vector<std::string>::iterator last) {
|
2014-10-22 15:42:40 +02:00
|
|
|
std::vector<std::string> reqlines;
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (first == last) {
|
2014-10-22 15:42:40 +02:00
|
|
|
std::cerr << "no URI available" << std::endl;
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
2015-07-31 19:49:59 +02:00
|
|
|
if (!config.has_base_uri()) {
|
2014-10-22 15:42:40 +02:00
|
|
|
|
2016-03-25 15:18:31 +01:00
|
|
|
if (!parse_base_uri(StringRef{*first})) {
|
2015-07-31 19:49:59 +02:00
|
|
|
std::cerr << "invalid URI: " << *first << std::endl;
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
2015-07-19 11:37:41 +02:00
|
|
|
|
2015-07-31 19:49:59 +02:00
|
|
|
config.base_uri = *first;
|
2014-10-22 15:42:40 +02:00
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
for (; first != last; ++first) {
|
2015-07-19 10:55:37 +02:00
|
|
|
http_parser_url u{};
|
2014-10-22 15:42:40 +02:00
|
|
|
|
|
|
|
auto uri = (*first).c_str();
|
|
|
|
|
2015-07-19 11:37:41 +02:00
|
|
|
if (http_parser_parse_url(uri, (*first).size(), 0, &u) != 0) {
|
2014-10-22 15:42:40 +02:00
|
|
|
std::cerr << "invalid URI: " << uri << std::endl;
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
reqlines.push_back(get_reqline(uri, u));
|
|
|
|
}
|
|
|
|
|
|
|
|
return reqlines;
|
|
|
|
}
|
|
|
|
} // namespace
|
|
|
|
|
2014-10-22 15:51:00 +02:00
|
|
|
namespace {
|
2014-11-27 15:39:04 +01:00
|
|
|
std::vector<std::string> read_uri_from_file(std::istream &infile) {
|
2014-10-22 15:51:00 +02:00
|
|
|
std::vector<std::string> uris;
|
|
|
|
std::string line_uri;
|
2014-11-27 15:39:04 +01:00
|
|
|
while (std::getline(infile, line_uri)) {
|
2014-10-22 15:51:00 +02:00
|
|
|
uris.push_back(line_uri);
|
|
|
|
}
|
|
|
|
|
|
|
|
return uris;
|
|
|
|
}
|
|
|
|
} // namespace
|
|
|
|
|
2015-07-31 19:49:59 +02:00
|
|
|
namespace {
|
|
|
|
void read_script_from_file(std::istream &infile,
|
|
|
|
std::vector<ev_tstamp> &timings,
|
|
|
|
std::vector<std::string> &uris) {
|
|
|
|
std::string script_line;
|
|
|
|
int line_count = 0;
|
|
|
|
while (std::getline(infile, script_line)) {
|
|
|
|
line_count++;
|
|
|
|
if (script_line.empty()) {
|
|
|
|
std::cerr << "Empty line detected at line " << line_count
|
|
|
|
<< ". Ignoring and continuing." << std::endl;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::size_t pos = script_line.find("\t");
|
|
|
|
if (pos == std::string::npos) {
|
|
|
|
std::cerr << "Invalid line format detected, no tab character at line "
|
|
|
|
<< line_count << ". \n\t" << script_line << std::endl;
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *start = script_line.c_str();
|
|
|
|
char *end;
|
|
|
|
auto v = std::strtod(start, &end);
|
|
|
|
|
2015-09-01 19:13:51 +02:00
|
|
|
errno = 0;
|
|
|
|
if (v < 0.0 || !std::isfinite(v) || end == start || errno != 0) {
|
|
|
|
auto error = errno;
|
2015-07-31 19:49:59 +02:00
|
|
|
std::cerr << "Time value error at line " << line_count << ". \n\t"
|
2015-09-01 19:13:51 +02:00
|
|
|
<< "value = " << script_line.substr(0, pos) << std::endl;
|
|
|
|
if (error != 0) {
|
|
|
|
std::cerr << "\t" << strerror(error) << std::endl;
|
|
|
|
}
|
2015-07-31 19:49:59 +02:00
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
timings.push_back(v / 1000.0);
|
|
|
|
uris.push_back(script_line.substr(pos + 1, script_line.size()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} // namespace
|
|
|
|
|
2015-10-09 14:36:28 +02:00
|
|
|
namespace {
|
|
|
|
std::unique_ptr<Worker> create_worker(uint32_t id, SSL_CTX *ssl_ctx,
|
|
|
|
size_t nreqs, size_t nclients,
|
2016-01-07 14:41:37 +01:00
|
|
|
size_t rate, size_t max_samples) {
|
2015-10-09 14:36:28 +02:00
|
|
|
std::stringstream rate_report;
|
|
|
|
if (config.is_rate_mode() && nclients > rate) {
|
|
|
|
rate_report << "Up to " << rate << " client(s) will be created every "
|
2015-10-10 04:36:13 +02:00
|
|
|
<< util::duration_str(config.rate_period) << " ";
|
2015-10-09 14:36:28 +02:00
|
|
|
}
|
|
|
|
|
2017-07-28 23:08:20 +02:00
|
|
|
if (config.is_timing_based_mode()) {
|
|
|
|
std::cout << "spawning thread #" << id << ": " << nclients
|
|
|
|
<< " total client(s). Timing-based test with "
|
2017-08-23 12:19:00 +02:00
|
|
|
<< config.warm_up_time << "s of warm-up time and "
|
2017-07-28 23:08:20 +02:00
|
|
|
<< config.duration << "s of main duration for measurements."
|
|
|
|
<< std::endl;
|
|
|
|
} else {
|
|
|
|
std::cout << "spawning thread #" << id << ": " << nclients
|
|
|
|
<< " total client(s). " << rate_report.str() << nreqs
|
|
|
|
<< " total requests" << std::endl;
|
|
|
|
}
|
2015-10-09 14:36:28 +02:00
|
|
|
|
2017-07-28 23:08:20 +02:00
|
|
|
if (config.is_rate_mode()) {
|
2018-10-15 16:02:44 +02:00
|
|
|
return std::make_unique<Worker>(id, ssl_ctx, nreqs, nclients, rate,
|
|
|
|
max_samples, &config);
|
2017-07-28 23:08:20 +02:00
|
|
|
} else {
|
|
|
|
// Here rate is same as client because the rate_timeout callback
|
|
|
|
// will be called only once
|
2018-10-15 16:02:44 +02:00
|
|
|
return std::make_unique<Worker>(id, ssl_ctx, nreqs, nclients, nclients,
|
|
|
|
max_samples, &config);
|
2017-07-28 23:08:20 +02:00
|
|
|
}
|
2015-10-09 14:36:28 +02:00
|
|
|
}
|
|
|
|
} // namespace
|
|
|
|
|
2016-10-06 15:20:10 +02:00
|
|
|
namespace {
|
|
|
|
int parse_header_table_size(uint32_t &dst, const char *opt,
|
|
|
|
const char *optarg) {
|
|
|
|
auto n = util::parse_uint_with_unit(optarg);
|
|
|
|
if (n == -1) {
|
|
|
|
std::cerr << "--" << opt << ": Bad option value: " << optarg << std::endl;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (n > std::numeric_limits<uint32_t>::max()) {
|
|
|
|
std::cerr << "--" << opt
|
|
|
|
<< ": Value too large. It should be less than or equal to "
|
|
|
|
<< std::numeric_limits<uint32_t>::max() << std::endl;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
dst = n;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
} // namespace
|
|
|
|
|
2014-02-28 01:10:42 +01:00
|
|
|
namespace {
|
2014-11-27 15:39:04 +01:00
|
|
|
void print_version(std::ostream &out) {
|
2014-02-28 01:10:42 +01:00
|
|
|
out << "h2load nghttp2/" NGHTTP2_VERSION << std::endl;
|
|
|
|
}
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
namespace {
|
2014-11-27 15:39:04 +01:00
|
|
|
void print_usage(std::ostream &out) {
|
2015-01-09 16:37:42 +01:00
|
|
|
out << R"(Usage: h2load [OPTIONS]... [URI]...
|
2017-12-17 05:23:37 +01:00
|
|
|
benchmarking tool for HTTP/2 server)"
|
2016-10-15 11:36:04 +02:00
|
|
|
<< std::endl;
|
2014-02-28 01:10:42 +01:00
|
|
|
}
|
|
|
|
} // namespace
|
|
|
|
|
2015-09-14 15:33:48 +02:00
|
|
|
namespace {
|
2017-12-17 05:23:37 +01:00
|
|
|
constexpr char DEFAULT_NPN_LIST[] = "h2,h2-16,h2-14,http/1.1";
|
2015-09-14 15:33:48 +02:00
|
|
|
} // namespace
|
|
|
|
|
2014-02-28 01:10:42 +01:00
|
|
|
namespace {
|
2014-11-27 15:39:04 +01:00
|
|
|
void print_help(std::ostream &out) {
|
2014-02-28 01:10:42 +01:00
|
|
|
print_usage(out);
|
2014-03-13 17:06:47 +01:00
|
|
|
|
2015-08-14 16:22:26 +02:00
|
|
|
auto config = Config();
|
|
|
|
|
2014-03-13 17:06:47 +01:00
|
|
|
out << R"(
|
2015-01-15 16:00:38 +01:00
|
|
|
<URI> Specify URI to access. Multiple URIs can be specified.
|
|
|
|
URIs are used in this order for each client. All URIs
|
|
|
|
are used, then first URI is used and then 2nd URI, and
|
|
|
|
so on. The scheme, host and port in the subsequent
|
|
|
|
URIs, if present, are ignored. Those in the first URI
|
2015-08-19 14:19:42 +02:00
|
|
|
are used solely. Definition of a base URI overrides all
|
2015-07-31 19:49:59 +02:00
|
|
|
scheme, host or port values.
|
2014-03-13 17:06:47 +01:00
|
|
|
Options:
|
2015-01-15 16:00:38 +01:00
|
|
|
-n, --requests=<N>
|
2015-10-08 14:25:58 +02:00
|
|
|
Number of requests across all clients. If it is used
|
|
|
|
with --timing-script-file option, this option specifies
|
|
|
|
the number of requests each client performs rather than
|
2017-08-23 13:35:01 +02:00
|
|
|
the number of requests across all clients. This option
|
|
|
|
is ignored if timing-based benchmarking is enabled (see
|
|
|
|
--duration option).
|
2016-10-15 11:36:04 +02:00
|
|
|
Default: )"
|
|
|
|
<< config.nreqs << R"(
|
2015-01-15 16:00:38 +01:00
|
|
|
-c, --clients=<N>
|
2015-10-08 14:25:58 +02:00
|
|
|
Number of concurrent clients. With -r option, this
|
|
|
|
specifies the maximum number of connections to be made.
|
2018-06-09 09:02:26 +02:00
|
|
|
Default: )"
|
|
|
|
<< config.nclients << R"(
|
2015-01-15 16:00:38 +01:00
|
|
|
-t, --threads=<N>
|
|
|
|
Number of native threads.
|
2018-06-09 09:02:26 +02:00
|
|
|
Default: )"
|
|
|
|
<< config.nthreads << R"(
|
2015-07-20 16:50:05 +02:00
|
|
|
-i, --input-file=<PATH>
|
2015-05-12 16:24:18 +02:00
|
|
|
Path of a file with multiple URIs are separated by EOLs.
|
2015-01-15 16:00:38 +01:00
|
|
|
This option will disable URIs getting from command-line.
|
2015-07-20 16:50:05 +02:00
|
|
|
If '-' is given as <PATH>, URIs will be read from stdin.
|
2015-01-15 16:00:38 +01:00
|
|
|
URIs are used in this order for each client. All URIs
|
|
|
|
are used, then first URI is used and then 2nd URI, and
|
|
|
|
so on. The scheme, host and port in the subsequent
|
|
|
|
URIs, if present, are ignored. Those in the first URI
|
2015-08-19 14:19:42 +02:00
|
|
|
are used solely. Definition of a base URI overrides all
|
2015-07-31 19:49:59 +02:00
|
|
|
scheme, host or port values.
|
2016-01-06 15:16:53 +01:00
|
|
|
-m, --max-concurrent-streams=<N>
|
|
|
|
Max concurrent streams to issue per session. When
|
|
|
|
http/1.1 is used, this specifies the number of HTTP
|
|
|
|
pipelining requests in-flight.
|
|
|
|
Default: 1
|
2014-03-13 17:06:47 +01:00
|
|
|
-w, --window-bits=<N>
|
2015-01-15 16:00:38 +01:00
|
|
|
Sets the stream level initial window size to (2**<N>)-1.
|
2016-10-15 11:36:04 +02:00
|
|
|
Default: )"
|
|
|
|
<< config.window_bits << R"(
|
2014-03-13 17:06:47 +01:00
|
|
|
-W, --connection-window-bits=<N>
|
2015-01-15 16:00:38 +01:00
|
|
|
Sets the connection level initial window size to
|
2017-12-17 05:23:37 +01:00
|
|
|
(2**<N>)-1.
|
2018-06-09 09:02:26 +02:00
|
|
|
Default: )"
|
|
|
|
<< config.connection_window_bits << R"(
|
2014-10-21 23:25:38 +02:00
|
|
|
-H, --header=<HEADER>
|
2015-01-15 16:00:38 +01:00
|
|
|
Add/Override a header to the requests.
|
2015-07-08 16:14:41 +02:00
|
|
|
--ciphers=<SUITE>
|
2019-08-08 02:59:21 +02:00
|
|
|
Set allowed cipher list for TLSv1.2 or ealier. The
|
|
|
|
format of the string is described in OpenSSL ciphers(1).
|
2017-01-09 06:47:32 +01:00
|
|
|
Default: )"
|
|
|
|
<< config.ciphers << R"(
|
2019-08-08 02:59:21 +02:00
|
|
|
--tls13-ciphers=<SUITE>
|
|
|
|
Set allowed cipher list for TLSv1.3. The format of the
|
|
|
|
string is described in OpenSSL ciphers(1).
|
|
|
|
Default: )"
|
|
|
|
<< config.tls13_ciphers << R"(
|
2014-04-21 14:35:45 +02:00
|
|
|
-p, --no-tls-proto=<PROTOID>
|
2015-01-15 16:00:38 +01:00
|
|
|
Specify ALPN identifier of the protocol to be used when
|
2017-12-17 05:23:37 +01:00
|
|
|
accessing http URI without SSL/TLS.
|
2018-06-09 09:02:26 +02:00
|
|
|
Available protocols: )"
|
|
|
|
<< NGHTTP2_CLEARTEXT_PROTO_VERSION_ID << R"( and )" << NGHTTP2_H1_1 << R"(
|
2016-10-15 11:36:04 +02:00
|
|
|
Default: )"
|
|
|
|
<< NGHTTP2_CLEARTEXT_PROTO_VERSION_ID << R"(
|
2015-07-20 16:50:05 +02:00
|
|
|
-d, --data=<PATH>
|
2015-03-26 11:53:42 +01:00
|
|
|
Post FILE to server. The request method is changed to
|
2016-06-12 11:56:32 +02:00
|
|
|
POST. For http/1.1 connection, if -d is used, the
|
|
|
|
maximum number of in-flight pipelined requests is set to
|
|
|
|
1.
|
2015-07-13 20:28:15 +02:00
|
|
|
-r, --rate=<N>
|
2015-08-08 16:44:47 +02:00
|
|
|
Specifies the fixed rate at which connections are
|
2015-07-19 10:27:38 +02:00
|
|
|
created. The rate must be a positive integer,
|
|
|
|
representing the number of connections to be made per
|
2015-10-08 14:25:58 +02:00
|
|
|
rate period. The maximum number of connections to be
|
|
|
|
made is given in -c option. This rate will be
|
|
|
|
distributed among threads as evenly as possible. For
|
|
|
|
example, with -t2 and -r4, each thread gets 2
|
|
|
|
connections per period. When the rate is 0, the program
|
|
|
|
will run as it normally does, creating connections at
|
|
|
|
whatever variable rate it wants. The default value for
|
2018-04-27 17:28:02 +02:00
|
|
|
this option is 0. -r and -D are mutually exclusive.
|
2015-10-10 04:36:13 +02:00
|
|
|
--rate-period=<DURATION>
|
|
|
|
Specifies the time period between creating connections.
|
|
|
|
The period must be a positive number, representing the
|
|
|
|
length of the period in time. This option is ignored if
|
|
|
|
the rate option is not used. The default value for this
|
|
|
|
option is 1s.
|
2017-07-28 23:08:20 +02:00
|
|
|
-D, --duration=<N>
|
|
|
|
Specifies the main duration for the measurements in case
|
2018-04-27 17:28:02 +02:00
|
|
|
of timing-based benchmarking. -D and -r are mutually
|
|
|
|
exclusive.
|
2017-07-28 23:08:20 +02:00
|
|
|
--warm-up-time=<DURATION>
|
|
|
|
Specifies the time period before starting the actual
|
|
|
|
measurements, in case of timing-based benchmarking.
|
|
|
|
Needs to provided along with -D option.
|
2015-10-10 10:52:51 +02:00
|
|
|
-T, --connection-active-timeout=<DURATION>
|
2015-08-18 14:32:47 +02:00
|
|
|
Specifies the maximum time that h2load is willing to
|
|
|
|
keep a connection open, regardless of the activity on
|
2015-10-10 10:52:51 +02:00
|
|
|
said connection. <DURATION> must be a positive integer,
|
|
|
|
specifying the amount of time to wait. When no timeout
|
|
|
|
value is set (either active or inactive), h2load will
|
|
|
|
keep a connection open indefinitely, waiting for a
|
2015-08-18 07:52:22 +02:00
|
|
|
response.
|
2015-10-10 10:52:51 +02:00
|
|
|
-N, --connection-inactivity-timeout=<DURATION>
|
2015-08-18 14:32:47 +02:00
|
|
|
Specifies the amount of time that h2load is willing to
|
2015-10-10 10:52:51 +02:00
|
|
|
wait to see activity on a given connection. <DURATION>
|
|
|
|
must be a positive integer, specifying the amount of
|
|
|
|
time to wait. When no timeout value is set (either
|
|
|
|
active or inactive), h2load will keep a connection open
|
2015-08-18 07:52:22 +02:00
|
|
|
indefinitely, waiting for a response.
|
2015-07-31 19:49:59 +02:00
|
|
|
--timing-script-file=<PATH>
|
2015-10-10 04:16:36 +02:00
|
|
|
Path of a file containing one or more lines separated by
|
|
|
|
EOLs. Each script line is composed of two tab-separated
|
|
|
|
fields. The first field represents the time offset from
|
|
|
|
the start of execution, expressed as a positive value of
|
|
|
|
milliseconds with microsecond resolution. The second
|
|
|
|
field represents the URI. This option will disable URIs
|
|
|
|
getting from command-line. If '-' is given as <PATH>,
|
|
|
|
script lines will be read from stdin. Script lines are
|
|
|
|
used in order for each client. If -n is given, it must
|
|
|
|
be less than or equal to the number of script lines,
|
|
|
|
larger values are clamped to the number of script lines.
|
|
|
|
If -n is not given, the number of requests will default
|
|
|
|
to the number of script lines. The scheme, host and
|
|
|
|
port defined in the first URI are used solely. Values
|
|
|
|
contained in other URIs, if present, are ignored.
|
|
|
|
Definition of a base URI overrides all scheme, host or
|
|
|
|
port values.
|
2016-01-19 11:24:15 +01:00
|
|
|
-B, --base-uri=(<URI>|unix:<PATH>)
|
2015-08-18 17:31:22 +02:00
|
|
|
Specify URI from which the scheme, host and port will be
|
|
|
|
used for all requests. The base URI overrides all
|
|
|
|
values defined either at the command line or inside
|
2016-01-19 11:24:15 +01:00
|
|
|
input files. If argument starts with "unix:", then the
|
|
|
|
rest of the argument will be treated as UNIX domain
|
|
|
|
socket path. The connection is made through that path
|
|
|
|
instead of TCP. In this case, scheme is inferred from
|
|
|
|
the first URI appeared in the command line or inside
|
|
|
|
input files as usual.
|
2015-09-14 15:33:48 +02:00
|
|
|
--npn-list=<LIST>
|
|
|
|
Comma delimited list of ALPN protocol identifier sorted
|
|
|
|
in the order of preference. That means most desirable
|
|
|
|
protocol comes first. This is used in both ALPN and
|
|
|
|
NPN. The parameter must be delimited by a single comma
|
|
|
|
only and any white spaces are treated as a part of
|
|
|
|
protocol string.
|
2018-06-09 09:02:26 +02:00
|
|
|
Default: )"
|
|
|
|
<< DEFAULT_NPN_LIST << R"(
|
2015-11-26 13:33:27 +01:00
|
|
|
--h1 Short hand for --npn-list=http/1.1
|
|
|
|
--no-tls-proto=http/1.1, which effectively force
|
|
|
|
http/1.1 for both http and https URI.
|
2016-10-06 15:20:10 +02:00
|
|
|
--header-table-size=<SIZE>
|
|
|
|
Specify decoder header table size.
|
2016-10-15 11:36:04 +02:00
|
|
|
Default: )"
|
|
|
|
<< util::utos_unit(config.header_table_size) << R"(
|
2016-10-06 15:20:10 +02:00
|
|
|
--encoder-header-table-size=<SIZE>
|
|
|
|
Specify encoder header table size. The decoder (server)
|
|
|
|
specifies the maximum dynamic table size it accepts.
|
|
|
|
Then the negotiated dynamic table size is the minimum of
|
|
|
|
this option value and the value which server specified.
|
2016-10-15 11:36:04 +02:00
|
|
|
Default: )"
|
|
|
|
<< util::utos_unit(config.encoder_header_table_size) << R"(
|
2018-11-11 19:33:50 +01:00
|
|
|
--log-file=<PATH>
|
|
|
|
Write per-request information to a file as tab-separated
|
|
|
|
columns: start time as microseconds since epoch; HTTP
|
|
|
|
status code; microseconds until end of response. More
|
|
|
|
columns may be added later. Rows are ordered by end-of-
|
|
|
|
response time when using one worker thread, but may
|
|
|
|
appear slightly out of order with multiple threads due
|
|
|
|
to buffering. Status code is -1 for failed streams.
|
2019-12-21 03:38:27 +01:00
|
|
|
--connect-to=<HOST>[:<PORT>]
|
|
|
|
Host and port to connect instead of using the authority
|
|
|
|
in <URI>.
|
2019-07-24 16:14:33 +02:00
|
|
|
--groups=<GROUPS>
|
|
|
|
Specify the supported groups.
|
|
|
|
Default: )"
|
|
|
|
<< config.groups << R"(
|
2015-01-15 16:00:38 +01:00
|
|
|
-v, --verbose
|
|
|
|
Output debug information.
|
|
|
|
--version Display version information and exit.
|
2015-10-10 04:36:13 +02:00
|
|
|
-h, --help Display this help and exit.
|
|
|
|
|
|
|
|
--
|
|
|
|
|
2016-10-06 15:20:10 +02:00
|
|
|
The <SIZE> argument is an integer and an optional unit (e.g., 10K is
|
|
|
|
10 * 1024). Units are K, M and G (powers of 1024).
|
|
|
|
|
2015-10-10 04:36:13 +02:00
|
|
|
The <DURATION> argument is an integer and an optional unit (e.g., 1s
|
|
|
|
is 1 second and 500ms is 500 milliseconds). Units are h, m, s or ms
|
|
|
|
(hours, minutes, seconds and milliseconds, respectively). If a unit
|
2018-06-09 09:02:26 +02:00
|
|
|
is omitted, a second is used as unit.)"
|
|
|
|
<< std::endl;
|
2014-02-28 01:10:42 +01:00
|
|
|
}
|
|
|
|
} // namespace
|
|
|
|
|
2019-08-25 03:20:10 +02:00
|
|
|
extern ngtcp2_crypto_ctx in_crypto_ctx;
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
int main(int argc, char **argv) {
|
2017-04-01 07:47:36 +02:00
|
|
|
tls::libssl_init();
|
2015-09-29 16:31:50 +02:00
|
|
|
|
2015-05-22 17:23:38 +02:00
|
|
|
#ifndef NOTHREADS
|
2017-04-01 07:47:36 +02:00
|
|
|
tls::LibsslGlobalLock lock;
|
2015-05-22 17:23:38 +02:00
|
|
|
#endif // NOTHREADS
|
|
|
|
|
2015-03-26 11:53:42 +01:00
|
|
|
std::string datafile;
|
2018-11-23 04:46:11 +01:00
|
|
|
std::string logfile;
|
2015-08-13 14:09:40 +02:00
|
|
|
bool nreqs_set_manually = false;
|
2014-11-27 15:39:04 +01:00
|
|
|
while (1) {
|
2014-04-30 09:08:21 +02:00
|
|
|
static int flag = 0;
|
2017-01-09 11:28:00 +01:00
|
|
|
constexpr static option long_options[] = {
|
2014-11-27 15:39:04 +01:00
|
|
|
{"requests", required_argument, nullptr, 'n'},
|
|
|
|
{"clients", required_argument, nullptr, 'c'},
|
2015-03-26 11:53:42 +01:00
|
|
|
{"data", required_argument, nullptr, 'd'},
|
2014-11-27 15:39:04 +01:00
|
|
|
{"threads", required_argument, nullptr, 't'},
|
|
|
|
{"max-concurrent-streams", required_argument, nullptr, 'm'},
|
|
|
|
{"window-bits", required_argument, nullptr, 'w'},
|
|
|
|
{"connection-window-bits", required_argument, nullptr, 'W'},
|
|
|
|
{"input-file", required_argument, nullptr, 'i'},
|
|
|
|
{"header", required_argument, nullptr, 'H'},
|
|
|
|
{"no-tls-proto", required_argument, nullptr, 'p'},
|
|
|
|
{"verbose", no_argument, nullptr, 'v'},
|
|
|
|
{"help", no_argument, nullptr, 'h'},
|
|
|
|
{"version", no_argument, &flag, 1},
|
2015-07-08 16:14:41 +02:00
|
|
|
{"ciphers", required_argument, &flag, 2},
|
2015-07-13 20:28:15 +02:00
|
|
|
{"rate", required_argument, nullptr, 'r'},
|
2015-08-18 07:52:22 +02:00
|
|
|
{"connection-active-timeout", required_argument, nullptr, 'T'},
|
|
|
|
{"connection-inactivity-timeout", required_argument, nullptr, 'N'},
|
2017-07-28 23:31:13 +02:00
|
|
|
{"duration", required_argument, nullptr, 'D'},
|
2015-07-31 19:49:59 +02:00
|
|
|
{"timing-script-file", required_argument, &flag, 3},
|
|
|
|
{"base-uri", required_argument, nullptr, 'B'},
|
2015-09-14 15:33:48 +02:00
|
|
|
{"npn-list", required_argument, &flag, 4},
|
2015-10-05 17:27:00 +02:00
|
|
|
{"rate-period", required_argument, &flag, 5},
|
2015-11-26 13:33:27 +01:00
|
|
|
{"h1", no_argument, &flag, 6},
|
2016-10-06 15:20:10 +02:00
|
|
|
{"header-table-size", required_argument, &flag, 7},
|
|
|
|
{"encoder-header-table-size", required_argument, &flag, 8},
|
2017-07-28 23:08:20 +02:00
|
|
|
{"warm-up-time", required_argument, &flag, 9},
|
2018-11-11 19:33:50 +01:00
|
|
|
{"log-file", required_argument, &flag, 10},
|
2019-12-12 17:33:34 +01:00
|
|
|
{"connect-to", required_argument, &flag, 11},
|
2019-07-24 16:14:33 +02:00
|
|
|
{"groups", required_argument, &flag, 12},
|
2019-08-08 02:59:21 +02:00
|
|
|
{"tls13-ciphers", required_argument, &flag, 13},
|
2014-11-27 15:39:04 +01:00
|
|
|
{nullptr, 0, nullptr, 0}};
|
2014-02-28 01:10:42 +01:00
|
|
|
int option_index = 0;
|
2017-08-23 12:19:00 +02:00
|
|
|
auto c = getopt_long(argc, argv,
|
|
|
|
"hvW:c:d:m:n:p:t:w:H:i:r:T:N:D:B:", long_options,
|
|
|
|
&option_index);
|
2014-11-27 15:39:04 +01:00
|
|
|
if (c == -1) {
|
2014-02-28 01:10:42 +01:00
|
|
|
break;
|
|
|
|
}
|
2014-11-27 15:39:04 +01:00
|
|
|
switch (c) {
|
2014-02-28 01:10:42 +01:00
|
|
|
case 'n':
|
|
|
|
config.nreqs = strtoul(optarg, nullptr, 10);
|
2015-08-13 14:09:40 +02:00
|
|
|
nreqs_set_manually = true;
|
2014-02-28 01:10:42 +01:00
|
|
|
break;
|
|
|
|
case 'c':
|
|
|
|
config.nclients = strtoul(optarg, nullptr, 10);
|
|
|
|
break;
|
2015-03-26 11:53:42 +01:00
|
|
|
case 'd':
|
|
|
|
datafile = optarg;
|
|
|
|
break;
|
2014-02-28 01:10:42 +01:00
|
|
|
case 't':
|
2014-04-23 17:47:26 +02:00
|
|
|
#ifdef NOTHREADS
|
2014-11-27 15:39:04 +01:00
|
|
|
std::cerr << "-t: WARNING: Threading disabled at build time, "
|
|
|
|
<< "no threads created." << std::endl;
|
2014-04-23 17:47:26 +02:00
|
|
|
#else
|
2014-03-03 17:12:11 +01:00
|
|
|
config.nthreads = strtoul(optarg, nullptr, 10);
|
2014-05-14 16:22:23 +02:00
|
|
|
#endif // NOTHREADS
|
2014-02-28 01:10:42 +01:00
|
|
|
break;
|
|
|
|
case 'm':
|
2016-01-06 15:16:53 +01:00
|
|
|
config.max_concurrent_streams = strtoul(optarg, nullptr, 10);
|
2014-02-28 01:10:42 +01:00
|
|
|
break;
|
|
|
|
case 'w':
|
|
|
|
case 'W': {
|
|
|
|
errno = 0;
|
|
|
|
char *endptr = nullptr;
|
|
|
|
auto n = strtoul(optarg, &endptr, 10);
|
2014-11-27 15:39:04 +01:00
|
|
|
if (errno == 0 && *endptr == '\0' && n < 31) {
|
|
|
|
if (c == 'w') {
|
2014-02-28 01:10:42 +01:00
|
|
|
config.window_bits = n;
|
|
|
|
} else {
|
|
|
|
config.connection_window_bits = n;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
std::cerr << "-" << static_cast<char>(c)
|
|
|
|
<< ": specify the integer in the range [0, 30], inclusive"
|
|
|
|
<< std::endl;
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2014-10-18 00:25:59 +02:00
|
|
|
case 'H': {
|
|
|
|
char *header = optarg;
|
|
|
|
// Skip first possible ':' in the header name
|
2014-11-27 15:39:04 +01:00
|
|
|
char *value = strchr(optarg + 1, ':');
|
|
|
|
if (!value || (header[0] == ':' && header + 1 == value)) {
|
|
|
|
std::cerr << "-H: invalid header: " << optarg << std::endl;
|
2014-10-18 00:25:59 +02:00
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
*value = 0;
|
|
|
|
value++;
|
2014-11-27 15:39:04 +01:00
|
|
|
while (isspace(*value)) {
|
|
|
|
value++;
|
|
|
|
}
|
|
|
|
if (*value == 0) {
|
2014-10-18 00:25:59 +02:00
|
|
|
// This could also be a valid case for suppressing a header
|
|
|
|
// similar to curl
|
|
|
|
std::cerr << "-H: invalid header - value missing: " << optarg
|
|
|
|
<< std::endl;
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
// Note that there is no processing currently to handle multiple
|
|
|
|
// message-header fields with the same field name
|
|
|
|
config.custom_headers.emplace_back(header, value);
|
2014-10-22 15:53:54 +02:00
|
|
|
util::inp_strlower(config.custom_headers.back().name);
|
2014-10-18 00:25:59 +02:00
|
|
|
break;
|
|
|
|
}
|
2015-07-31 19:49:59 +02:00
|
|
|
case 'i':
|
|
|
|
config.ifile = optarg;
|
2014-10-22 00:29:36 +02:00
|
|
|
break;
|
2016-03-24 17:41:06 +01:00
|
|
|
case 'p': {
|
|
|
|
auto proto = StringRef{optarg};
|
|
|
|
if (util::strieq(StringRef::from_lit(NGHTTP2_CLEARTEXT_PROTO_VERSION_ID),
|
|
|
|
proto)) {
|
2014-04-21 14:35:45 +02:00
|
|
|
config.no_tls_proto = Config::PROTO_HTTP2;
|
2016-03-24 17:41:06 +01:00
|
|
|
} else if (util::strieq(NGHTTP2_H1_1, proto)) {
|
2015-09-14 15:33:48 +02:00
|
|
|
config.no_tls_proto = Config::PROTO_HTTP1_1;
|
2014-04-21 14:35:45 +02:00
|
|
|
} else {
|
2016-03-24 17:41:06 +01:00
|
|
|
std::cerr << "-p: unsupported protocol " << proto << std::endl;
|
2014-04-21 14:35:45 +02:00
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
break;
|
2016-03-24 17:41:06 +01:00
|
|
|
}
|
2015-07-13 20:28:15 +02:00
|
|
|
case 'r':
|
|
|
|
config.rate = strtoul(optarg, nullptr, 10);
|
2015-08-08 17:51:58 +02:00
|
|
|
if (config.rate == 0) {
|
2015-07-13 20:28:15 +02:00
|
|
|
std::cerr << "-r: the rate at which connections are made "
|
2015-07-14 20:16:37 +02:00
|
|
|
<< "must be positive." << std::endl;
|
2015-07-13 20:28:15 +02:00
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
break;
|
2015-08-18 07:52:22 +02:00
|
|
|
case 'T':
|
2015-10-10 10:52:51 +02:00
|
|
|
config.conn_active_timeout = util::parse_duration_with_unit(optarg);
|
|
|
|
if (!std::isfinite(config.conn_active_timeout)) {
|
|
|
|
std::cerr << "-T: bad value for the conn_active_timeout wait time: "
|
|
|
|
<< optarg << std::endl;
|
2015-08-18 07:52:22 +02:00
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'N':
|
2015-10-10 10:52:51 +02:00
|
|
|
config.conn_inactivity_timeout = util::parse_duration_with_unit(optarg);
|
|
|
|
if (!std::isfinite(config.conn_inactivity_timeout)) {
|
|
|
|
std::cerr << "-N: bad value for the conn_inactivity_timeout wait time: "
|
|
|
|
<< optarg << std::endl;
|
2015-08-18 07:52:22 +02:00
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
break;
|
2016-01-19 11:24:15 +01:00
|
|
|
case 'B': {
|
2016-03-25 15:18:31 +01:00
|
|
|
auto arg = StringRef{optarg};
|
2016-01-19 11:24:15 +01:00
|
|
|
config.base_uri = "";
|
|
|
|
config.base_uri_unix = false;
|
|
|
|
|
2016-03-25 15:18:31 +01:00
|
|
|
if (util::istarts_with_l(arg, UNIX_PATH_PREFIX)) {
|
2016-01-19 11:24:15 +01:00
|
|
|
// UNIX domain socket path
|
|
|
|
sockaddr_un un;
|
|
|
|
|
2016-03-25 15:18:31 +01:00
|
|
|
auto path = StringRef{std::begin(arg) + str_size(UNIX_PATH_PREFIX),
|
|
|
|
std::end(arg)};
|
2016-01-19 11:24:15 +01:00
|
|
|
|
2016-03-25 15:18:31 +01:00
|
|
|
if (path.size() == 0 || path.size() + 1 > sizeof(un.sun_path)) {
|
|
|
|
std::cerr << "--base-uri: invalid UNIX domain socket path: " << arg
|
2016-01-19 11:24:15 +01:00
|
|
|
<< std::endl;
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
config.base_uri_unix = true;
|
|
|
|
|
|
|
|
auto &unix_addr = config.unix_addr;
|
2016-03-25 15:18:31 +01:00
|
|
|
std::copy(std::begin(path), std::end(path), unix_addr.sun_path);
|
|
|
|
unix_addr.sun_path[path.size()] = '\0';
|
2016-01-19 11:24:15 +01:00
|
|
|
unix_addr.sun_family = AF_UNIX;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-03-25 15:18:31 +01:00
|
|
|
if (!parse_base_uri(arg)) {
|
|
|
|
std::cerr << "--base-uri: invalid base URI: " << arg << std::endl;
|
2015-07-31 19:49:59 +02:00
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
2016-01-19 11:24:15 +01:00
|
|
|
|
2016-03-25 15:18:31 +01:00
|
|
|
config.base_uri = arg.str();
|
2015-07-31 19:49:59 +02:00
|
|
|
break;
|
2016-01-19 11:24:15 +01:00
|
|
|
}
|
2017-07-28 23:08:20 +02:00
|
|
|
case 'D':
|
|
|
|
config.duration = strtoul(optarg, nullptr, 10);
|
|
|
|
if (config.duration == 0) {
|
|
|
|
std::cerr << "-D: the main duration for timing-based benchmarking "
|
|
|
|
<< "must be positive." << std::endl;
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
break;
|
2014-02-28 01:10:42 +01:00
|
|
|
case 'v':
|
|
|
|
config.verbose = true;
|
|
|
|
break;
|
|
|
|
case 'h':
|
|
|
|
print_help(std::cout);
|
|
|
|
exit(EXIT_SUCCESS);
|
|
|
|
case '?':
|
|
|
|
util::show_candidates(argv[optind - 1], long_options);
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
case 0:
|
2014-11-27 15:39:04 +01:00
|
|
|
switch (flag) {
|
2014-02-28 01:10:42 +01:00
|
|
|
case 1:
|
|
|
|
// version option
|
|
|
|
print_version(std::cout);
|
|
|
|
exit(EXIT_SUCCESS);
|
2015-07-08 16:14:41 +02:00
|
|
|
case 2:
|
|
|
|
// ciphers option
|
|
|
|
config.ciphers = optarg;
|
|
|
|
break;
|
2015-07-31 19:49:59 +02:00
|
|
|
case 3:
|
2015-09-14 15:33:48 +02:00
|
|
|
// timing-script option
|
2015-07-31 19:49:59 +02:00
|
|
|
config.ifile = optarg;
|
|
|
|
config.timing_script = true;
|
|
|
|
break;
|
2015-09-14 15:33:48 +02:00
|
|
|
case 4:
|
|
|
|
// npn-list option
|
2016-03-24 13:05:02 +01:00
|
|
|
config.npn_list = util::parse_config_str_list(StringRef{optarg});
|
2015-09-14 15:33:48 +02:00
|
|
|
break;
|
2015-10-10 04:36:13 +02:00
|
|
|
case 5:
|
2015-10-05 17:27:00 +02:00
|
|
|
// rate-period
|
2015-10-10 04:36:13 +02:00
|
|
|
config.rate_period = util::parse_duration_with_unit(optarg);
|
|
|
|
if (!std::isfinite(config.rate_period)) {
|
|
|
|
std::cerr << "--rate-period: value error " << optarg << std::endl;
|
2015-10-05 17:27:00 +02:00
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
break;
|
2015-11-26 13:33:27 +01:00
|
|
|
case 6:
|
|
|
|
// --h1
|
2016-03-24 13:05:02 +01:00
|
|
|
config.npn_list =
|
|
|
|
util::parse_config_str_list(StringRef::from_lit("http/1.1"));
|
2015-11-26 13:33:27 +01:00
|
|
|
config.no_tls_proto = Config::PROTO_HTTP1_1;
|
|
|
|
break;
|
2016-10-06 15:20:10 +02:00
|
|
|
case 7:
|
|
|
|
// --header-table-size
|
|
|
|
if (parse_header_table_size(config.header_table_size,
|
|
|
|
"header-table-size", optarg) != 0) {
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 8:
|
|
|
|
// --encoder-header-table-size
|
|
|
|
if (parse_header_table_size(config.encoder_header_table_size,
|
|
|
|
"encoder-header-table-size", optarg) != 0) {
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
break;
|
2017-07-28 23:08:20 +02:00
|
|
|
case 9:
|
|
|
|
// --warm-up-time
|
|
|
|
config.warm_up_time = util::parse_duration_with_unit(optarg);
|
|
|
|
if (!std::isfinite(config.warm_up_time)) {
|
|
|
|
std::cerr << "--warm-up-time: value error " << optarg << std::endl;
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
break;
|
2018-11-11 19:33:50 +01:00
|
|
|
case 10:
|
|
|
|
// --log-file
|
2018-11-23 04:46:11 +01:00
|
|
|
logfile = optarg;
|
2018-11-11 19:33:50 +01:00
|
|
|
break;
|
2019-12-21 03:38:27 +01:00
|
|
|
case 11: {
|
2019-12-12 17:33:34 +01:00
|
|
|
// --connect-to
|
2019-12-21 03:38:27 +01:00
|
|
|
auto p = util::split_hostport(StringRef{optarg});
|
|
|
|
int64_t port = 0;
|
|
|
|
if (p.first.empty() ||
|
|
|
|
(!p.second.empty() && (port = util::parse_uint(p.second)) == -1)) {
|
|
|
|
std::cerr << "--connect-to: Invalid value " << optarg << std::endl;
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
config.connect_to_host = p.first.str();
|
|
|
|
config.connect_to_port = port;
|
2019-12-12 17:33:34 +01:00
|
|
|
break;
|
2015-10-05 17:27:00 +02:00
|
|
|
}
|
2019-07-24 16:14:33 +02:00
|
|
|
case 12:
|
|
|
|
// --groups
|
|
|
|
config.groups = optarg;
|
|
|
|
break;
|
2019-08-08 02:59:21 +02:00
|
|
|
case 13:
|
|
|
|
// --tls13-ciphers
|
|
|
|
config.tls13_ciphers = optarg;
|
|
|
|
break;
|
2019-12-21 03:38:27 +01:00
|
|
|
}
|
2014-02-28 01:10:42 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (argc == optind) {
|
|
|
|
if (config.ifile.empty()) {
|
2014-10-22 00:29:36 +02:00
|
|
|
std::cerr << "no URI or input file given" << std::endl;
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
2014-02-28 01:10:42 +01:00
|
|
|
}
|
|
|
|
|
2015-08-19 17:05:06 +02:00
|
|
|
if (config.nclients == 0) {
|
|
|
|
std::cerr << "-c: the number of clients must be strictly greater than 0."
|
|
|
|
<< std::endl;
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
2015-09-14 15:33:48 +02:00
|
|
|
if (config.npn_list.empty()) {
|
2016-03-24 13:05:02 +01:00
|
|
|
config.npn_list =
|
|
|
|
util::parse_config_str_list(StringRef::from_lit(DEFAULT_NPN_LIST));
|
2015-09-14 15:33:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// serialize the APLN tokens
|
|
|
|
for (auto &proto : config.npn_list) {
|
|
|
|
proto.insert(proto.begin(), static_cast<unsigned char>(proto.size()));
|
|
|
|
}
|
|
|
|
|
2015-08-19 17:05:06 +02:00
|
|
|
std::vector<std::string> reqlines;
|
|
|
|
|
|
|
|
if (config.ifile.empty()) {
|
|
|
|
std::vector<std::string> uris;
|
|
|
|
std::copy(&argv[optind], &argv[argc], std::back_inserter(uris));
|
|
|
|
reqlines = parse_uris(std::begin(uris), std::end(uris));
|
|
|
|
} else {
|
|
|
|
std::vector<std::string> uris;
|
2015-10-08 14:25:58 +02:00
|
|
|
if (!config.timing_script) {
|
|
|
|
if (config.ifile == "-") {
|
2015-08-19 17:05:06 +02:00
|
|
|
uris = read_uri_from_file(std::cin);
|
|
|
|
} else {
|
2015-10-08 14:25:58 +02:00
|
|
|
std::ifstream infile(config.ifile);
|
|
|
|
if (!infile) {
|
|
|
|
std::cerr << "cannot read input file: " << config.ifile << std::endl;
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
2015-08-19 17:05:06 +02:00
|
|
|
|
|
|
|
uris = read_uri_from_file(infile);
|
2015-10-08 14:25:58 +02:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (config.ifile == "-") {
|
|
|
|
read_script_from_file(std::cin, config.timings, uris);
|
2015-08-19 17:05:06 +02:00
|
|
|
} else {
|
2015-10-08 14:25:58 +02:00
|
|
|
std::ifstream infile(config.ifile);
|
|
|
|
if (!infile) {
|
|
|
|
std::cerr << "cannot read input file: " << config.ifile << std::endl;
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
2015-08-19 17:05:06 +02:00
|
|
|
read_script_from_file(infile, config.timings, uris);
|
2015-10-08 14:25:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (nreqs_set_manually) {
|
|
|
|
if (config.nreqs > uris.size()) {
|
|
|
|
std::cerr << "-n: the number of requests must be less than or equal "
|
|
|
|
"to the number of timing script entries. Setting number "
|
2016-10-15 11:36:04 +02:00
|
|
|
"of requests to "
|
|
|
|
<< uris.size() << std::endl;
|
2015-10-08 14:25:58 +02:00
|
|
|
|
|
|
|
config.nreqs = uris.size();
|
2015-08-19 17:05:06 +02:00
|
|
|
}
|
2015-10-08 14:25:58 +02:00
|
|
|
} else {
|
|
|
|
config.nreqs = uris.size();
|
2015-08-19 17:05:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
reqlines = parse_uris(std::begin(uris), std::end(uris));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (reqlines.empty()) {
|
|
|
|
std::cerr << "No URI given" << std::endl;
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
2018-04-27 17:28:02 +02:00
|
|
|
if (config.is_timing_based_mode() && config.is_rate_mode()) {
|
|
|
|
std::cerr << "-r, -D: they are mutually exclusive." << std::endl;
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
2017-07-28 23:08:20 +02:00
|
|
|
if (config.nreqs == 0 && !config.is_timing_based_mode()) {
|
2017-08-23 13:35:01 +02:00
|
|
|
std::cerr << "-n: the number of requests must be strictly greater than 0 "
|
|
|
|
"if timing-based test is not being run."
|
|
|
|
<< std::endl;
|
2014-02-28 01:10:42 +01:00
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (config.max_concurrent_streams == 0) {
|
2014-02-28 01:10:42 +01:00
|
|
|
std::cerr << "-m: the max concurrent streams must be strictly greater "
|
2014-11-27 15:39:04 +01:00
|
|
|
<< "than 0." << std::endl;
|
2014-02-28 01:10:42 +01:00
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (config.nthreads == 0) {
|
2014-03-03 17:12:11 +01:00
|
|
|
std::cerr << "-t: the number of threads must be strictly greater than 0."
|
|
|
|
<< std::endl;
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
if (config.nthreads > std::thread::hardware_concurrency()) {
|
2014-03-03 17:12:11 +01:00
|
|
|
std::cerr << "-t: warning: the number of threads is greater than hardware "
|
2014-11-27 15:39:04 +01:00
|
|
|
<< "cores." << std::endl;
|
2014-03-03 17:12:11 +01:00
|
|
|
}
|
|
|
|
|
2015-10-08 14:25:58 +02:00
|
|
|
// With timing script, we don't distribute config.nreqs to each
|
|
|
|
// client or thread.
|
2017-08-23 12:19:00 +02:00
|
|
|
if (!config.timing_script && config.nreqs < config.nclients &&
|
|
|
|
!config.is_timing_based_mode()) {
|
2015-10-08 14:25:58 +02:00
|
|
|
std::cerr << "-n, -c: the number of requests must be greater than or "
|
|
|
|
<< "equal to the clients." << std::endl;
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
2015-07-13 20:28:15 +02:00
|
|
|
|
2015-10-08 14:25:58 +02:00
|
|
|
if (config.nclients < config.nthreads) {
|
|
|
|
std::cerr << "-c, -t: the number of clients must be greater than or equal "
|
2017-08-23 12:19:00 +02:00
|
|
|
<< "to the number of threads." << std::endl;
|
2015-10-08 14:25:58 +02:00
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
2017-07-28 23:08:20 +02:00
|
|
|
if (config.is_timing_based_mode()) {
|
2017-08-23 13:35:01 +02:00
|
|
|
config.nreqs = 0;
|
2017-07-28 23:08:20 +02:00
|
|
|
}
|
|
|
|
|
2015-10-08 14:25:58 +02:00
|
|
|
if (config.is_rate_mode()) {
|
2015-08-08 17:51:58 +02:00
|
|
|
if (config.rate < config.nthreads) {
|
|
|
|
std::cerr << "-r, -t: the connection rate must be greater than or equal "
|
|
|
|
<< "to the number of threads." << std::endl;
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
2015-07-13 20:28:15 +02:00
|
|
|
|
2015-10-08 14:25:58 +02:00
|
|
|
if (config.rate > config.nclients) {
|
|
|
|
std::cerr << "-r, -c: the connection rate must be smaller than or equal "
|
2016-10-15 11:36:04 +02:00
|
|
|
"to the number of clients."
|
|
|
|
<< std::endl;
|
2015-08-13 14:09:40 +02:00
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
2015-07-23 20:01:09 +02:00
|
|
|
}
|
|
|
|
|
2015-03-26 11:53:42 +01:00
|
|
|
if (!datafile.empty()) {
|
|
|
|
config.data_fd = open(datafile.c_str(), O_RDONLY | O_BINARY);
|
|
|
|
if (config.data_fd == -1) {
|
|
|
|
std::cerr << "-d: Could not open file " << datafile << std::endl;
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
struct stat data_stat;
|
|
|
|
if (fstat(config.data_fd, &data_stat) == -1) {
|
|
|
|
std::cerr << "-d: Could not stat file " << datafile << std::endl;
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
config.data_length = data_stat.st_size;
|
|
|
|
}
|
|
|
|
|
2018-11-23 04:46:11 +01:00
|
|
|
if (!logfile.empty()) {
|
|
|
|
config.log_fd = open(logfile.c_str(), O_WRONLY | O_CREAT | O_APPEND,
|
|
|
|
S_IRUSR | S_IWUSR | S_IRGRP);
|
|
|
|
if (config.log_fd == -1) {
|
|
|
|
std::cerr << "--log-file: Could not open file " << logfile << std::endl;
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-19 10:55:37 +02:00
|
|
|
struct sigaction act {};
|
2014-02-28 01:10:42 +01:00
|
|
|
act.sa_handler = SIG_IGN;
|
|
|
|
sigaction(SIGPIPE, &act, nullptr);
|
2014-03-04 13:29:42 +01:00
|
|
|
|
2014-03-14 15:15:01 +01:00
|
|
|
auto ssl_ctx = SSL_CTX_new(SSLv23_client_method());
|
2014-11-27 15:39:04 +01:00
|
|
|
if (!ssl_ctx) {
|
2014-03-14 15:15:01 +01:00
|
|
|
std::cerr << "Failed to create SSL_CTX: "
|
|
|
|
<< ERR_error_string(ERR_get_error(), nullptr) << std::endl;
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
2014-12-12 17:37:57 +01:00
|
|
|
|
2015-06-22 16:26:45 +02:00
|
|
|
auto ssl_opts = (SSL_OP_ALL & ~SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS) |
|
|
|
|
SSL_OP_NO_SSLv2 | SSL_OP_NO_SSLv3 | SSL_OP_NO_COMPRESSION |
|
|
|
|
SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION;
|
|
|
|
|
|
|
|
SSL_CTX_set_options(ssl_ctx, ssl_opts);
|
2014-12-12 17:37:57 +01:00
|
|
|
SSL_CTX_set_mode(ssl_ctx, SSL_MODE_AUTO_RETRY);
|
|
|
|
SSL_CTX_set_mode(ssl_ctx, SSL_MODE_RELEASE_BUFFERS);
|
|
|
|
|
2019-06-08 15:05:25 +02:00
|
|
|
if (config.is_quic()) {
|
|
|
|
SSL_CTX_set_min_proto_version(ssl_ctx, TLS1_3_VERSION);
|
|
|
|
SSL_CTX_set_max_proto_version(ssl_ctx, TLS1_3_VERSION);
|
|
|
|
|
|
|
|
SSL_CTX_clear_options(ssl_ctx, SSL_OP_ENABLE_MIDDLEBOX_COMPAT);
|
|
|
|
SSL_CTX_set_mode(ssl_ctx, SSL_MODE_QUIC_HACK);
|
|
|
|
|
|
|
|
if (SSL_CTX_add_custom_ext(
|
|
|
|
ssl_ctx, NGTCP2_TLSEXT_QUIC_TRANSPORT_PARAMETERS,
|
|
|
|
SSL_EXT_CLIENT_HELLO | SSL_EXT_TLS1_3_ENCRYPTED_EXTENSIONS,
|
|
|
|
quic_transport_params_add_cb, quic_transport_params_free_cb,
|
|
|
|
nullptr, quic_transport_params_parse_cb, nullptr) != 1) {
|
|
|
|
std::cerr << "SSL_CTX_add_custom_ext(NGTCP2_TLSEXT_QUIC_TRANSPORT_"
|
|
|
|
"PARAMETERS) failed: "
|
|
|
|
<< ERR_error_string(ERR_get_error(), nullptr) << std::endl;
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
} else if (nghttp2::tls::ssl_ctx_set_proto_versions(
|
|
|
|
ssl_ctx, nghttp2::tls::NGHTTP2_TLS_MIN_VERSION,
|
|
|
|
nghttp2::tls::NGHTTP2_TLS_MAX_VERSION) != 0) {
|
2017-02-14 16:40:43 +01:00
|
|
|
std::cerr << "Could not set TLS versions" << std::endl;
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
2017-01-09 06:47:32 +01:00
|
|
|
if (SSL_CTX_set_cipher_list(ssl_ctx, config.ciphers.c_str()) == 0) {
|
|
|
|
std::cerr << "SSL_CTX_set_cipher_list with " << config.ciphers
|
2015-07-08 16:14:41 +02:00
|
|
|
<< " failed: " << ERR_error_string(ERR_get_error(), nullptr)
|
|
|
|
<< std::endl;
|
2014-12-12 17:37:57 +01:00
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
2019-08-08 02:59:21 +02:00
|
|
|
if (SSL_CTX_set_ciphersuites(ssl_ctx, config.tls13_ciphers.c_str()) == 0) {
|
|
|
|
std::cerr << "SSL_CTX_set_ciphersuites with " << config.tls13_ciphers
|
|
|
|
<< " failed: " << ERR_error_string(ERR_get_error(), nullptr)
|
|
|
|
<< std::endl;
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
2019-07-24 16:14:33 +02:00
|
|
|
|
|
|
|
if (SSL_CTX_set1_groups_list(ssl_ctx, config.groups.c_str()) != 1) {
|
|
|
|
std::cerr << "SSL_CTX_set1_groups_list failed" << std::endl;
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
2019-06-08 15:05:25 +02:00
|
|
|
|
2018-03-25 18:27:23 +02:00
|
|
|
#ifndef OPENSSL_NO_NEXTPROTONEG
|
2014-11-27 15:39:04 +01:00
|
|
|
SSL_CTX_set_next_proto_select_cb(ssl_ctx, client_select_next_proto_cb,
|
|
|
|
nullptr);
|
2018-04-03 14:39:44 +02:00
|
|
|
#endif // !OPENSSL_NO_NEXTPROTONEG
|
2014-03-14 15:15:01 +01:00
|
|
|
|
2014-11-21 17:13:18 +01:00
|
|
|
#if OPENSSL_VERSION_NUMBER >= 0x10002000L
|
2015-09-14 15:33:48 +02:00
|
|
|
std::vector<unsigned char> proto_list;
|
|
|
|
for (const auto &proto : config.npn_list) {
|
|
|
|
std::copy_n(proto.c_str(), proto.size(), std::back_inserter(proto_list));
|
|
|
|
}
|
|
|
|
|
2014-11-21 17:13:18 +01:00
|
|
|
SSL_CTX_set_alpn_protos(ssl_ctx, proto_list.data(), proto_list.size());
|
|
|
|
#endif // OPENSSL_VERSION_NUMBER >= 0x10002000L
|
|
|
|
|
2015-09-14 15:33:48 +02:00
|
|
|
std::string user_agent = "h2load nghttp2/" NGHTTP2_VERSION;
|
2014-03-14 15:15:01 +01:00
|
|
|
Headers shared_nva;
|
|
|
|
shared_nva.emplace_back(":scheme", config.scheme);
|
2014-11-27 15:39:04 +01:00
|
|
|
if (config.port != config.default_port) {
|
2014-03-14 15:15:01 +01:00
|
|
|
shared_nva.emplace_back(":authority",
|
2014-10-22 15:42:40 +02:00
|
|
|
config.host + ":" + util::utos(config.port));
|
2014-02-28 01:10:42 +01:00
|
|
|
} else {
|
2014-03-14 15:15:01 +01:00
|
|
|
shared_nva.emplace_back(":authority", config.host);
|
2014-02-28 01:10:42 +01:00
|
|
|
}
|
2015-03-26 11:53:42 +01:00
|
|
|
shared_nva.emplace_back(":method", config.data_fd == -1 ? "GET" : "POST");
|
2015-09-14 15:33:48 +02:00
|
|
|
shared_nva.emplace_back("user-agent", user_agent);
|
2014-02-28 01:10:42 +01:00
|
|
|
|
2019-12-21 02:55:37 +01:00
|
|
|
// list header fields that can be overridden.
|
2015-11-18 14:25:02 +01:00
|
|
|
auto override_hdrs = make_array<std::string>(":authority", ":host", ":method",
|
|
|
|
":scheme", "user-agent");
|
2014-10-21 23:25:38 +02:00
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
for (auto &kv : config.custom_headers) {
|
|
|
|
if (std::find(std::begin(override_hdrs), std::end(override_hdrs),
|
|
|
|
kv.name) != std::end(override_hdrs)) {
|
2014-10-21 23:25:38 +02:00
|
|
|
// override header
|
2014-11-27 15:39:04 +01:00
|
|
|
for (auto &nv : shared_nva) {
|
|
|
|
if ((nv.name == ":authority" && kv.name == ":host") ||
|
|
|
|
(nv.name == kv.name)) {
|
2014-10-22 15:53:54 +02:00
|
|
|
nv.value = kv.value;
|
2014-10-18 00:25:59 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// add additional headers
|
2014-10-22 15:53:54 +02:00
|
|
|
shared_nva.push_back(kv);
|
2014-10-18 00:25:59 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-12 10:52:47 +02:00
|
|
|
std::string content_length_str;
|
|
|
|
if (config.data_fd != -1) {
|
|
|
|
content_length_str = util::utos(config.data_length);
|
|
|
|
}
|
|
|
|
|
2015-11-18 14:25:02 +01:00
|
|
|
auto method_it =
|
|
|
|
std::find_if(std::begin(shared_nva), std::end(shared_nva),
|
|
|
|
[](const Header &nv) { return nv.name == ":method"; });
|
|
|
|
assert(method_it != std::end(shared_nva));
|
|
|
|
|
|
|
|
config.h1reqs.reserve(reqlines.size());
|
|
|
|
config.nva.reserve(reqlines.size());
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
for (auto &req : reqlines) {
|
2015-09-14 15:33:48 +02:00
|
|
|
// For HTTP/1.1
|
2015-11-18 14:25:02 +01:00
|
|
|
auto h1req = (*method_it).value;
|
2015-11-27 16:03:16 +01:00
|
|
|
h1req += ' ';
|
2015-11-18 14:25:02 +01:00
|
|
|
h1req += req;
|
2015-09-14 15:33:48 +02:00
|
|
|
h1req += " HTTP/1.1\r\n";
|
2015-11-18 14:25:02 +01:00
|
|
|
for (auto &nv : shared_nva) {
|
|
|
|
if (nv.name == ":authority") {
|
|
|
|
h1req += "Host: ";
|
|
|
|
h1req += nv.value;
|
|
|
|
h1req += "\r\n";
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (nv.name[0] == ':') {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
h1req += nv.name;
|
|
|
|
h1req += ": ";
|
|
|
|
h1req += nv.value;
|
|
|
|
h1req += "\r\n";
|
|
|
|
}
|
2016-06-12 10:52:47 +02:00
|
|
|
|
|
|
|
if (!content_length_str.empty()) {
|
2016-06-12 10:42:12 +02:00
|
|
|
h1req += "Content-Length: ";
|
2016-06-12 10:52:47 +02:00
|
|
|
h1req += content_length_str;
|
2016-06-12 10:42:12 +02:00
|
|
|
h1req += "\r\n";
|
|
|
|
}
|
2015-09-14 15:33:48 +02:00
|
|
|
h1req += "\r\n";
|
2015-11-18 14:25:02 +01:00
|
|
|
|
|
|
|
config.h1reqs.push_back(std::move(h1req));
|
2015-09-14 15:33:48 +02:00
|
|
|
|
2014-03-14 15:15:01 +01:00
|
|
|
// For nghttp2
|
|
|
|
std::vector<nghttp2_nv> nva;
|
2016-06-12 10:52:47 +02:00
|
|
|
// 2 for :path, and possible content-length
|
|
|
|
nva.reserve(2 + shared_nva.size());
|
2014-02-28 01:10:42 +01:00
|
|
|
|
2014-03-14 15:15:01 +01:00
|
|
|
nva.push_back(http2::make_nv_ls(":path", req));
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
for (auto &nv : shared_nva) {
|
2014-04-03 04:22:11 +02:00
|
|
|
nva.push_back(http2::make_nv(nv.name, nv.value, false));
|
2014-02-28 01:10:42 +01:00
|
|
|
}
|
2014-03-14 15:15:01 +01:00
|
|
|
|
2016-06-12 10:52:47 +02:00
|
|
|
if (!content_length_str.empty()) {
|
|
|
|
nva.push_back(http2::make_nv(StringRef::from_lit("content-length"),
|
|
|
|
StringRef{content_length_str}));
|
|
|
|
}
|
|
|
|
|
2014-03-14 15:15:01 +01:00
|
|
|
config.nva.push_back(std::move(nva));
|
2014-02-28 01:10:42 +01:00
|
|
|
}
|
|
|
|
|
2015-10-17 05:04:06 +02:00
|
|
|
// Don't DOS our server!
|
|
|
|
if (config.host == "nghttp2.org") {
|
|
|
|
std::cerr << "Using h2load against public server " << config.host
|
|
|
|
<< " should be prohibited." << std::endl;
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
2019-08-25 03:20:10 +02:00
|
|
|
ngtcp2_crypto_ctx_initial(&in_crypto_ctx);
|
|
|
|
|
2014-02-28 01:10:42 +01:00
|
|
|
resolve_host();
|
|
|
|
|
2015-10-09 14:36:28 +02:00
|
|
|
std::cout << "starting benchmark..." << std::endl;
|
|
|
|
|
|
|
|
std::vector<std::unique_ptr<Worker>> workers;
|
|
|
|
workers.reserve(config.nthreads);
|
|
|
|
|
|
|
|
#ifndef NOTHREADS
|
2015-10-08 14:25:58 +02:00
|
|
|
size_t nreqs_per_thread = 0;
|
|
|
|
ssize_t nreqs_rem = 0;
|
2014-06-06 16:11:08 +02:00
|
|
|
|
2015-10-08 14:25:58 +02:00
|
|
|
if (!config.timing_script) {
|
|
|
|
nreqs_per_thread = config.nreqs / config.nthreads;
|
|
|
|
nreqs_rem = config.nreqs % config.nthreads;
|
2015-07-22 01:53:46 +02:00
|
|
|
}
|
|
|
|
|
2014-03-03 17:12:11 +01:00
|
|
|
size_t nclients_per_thread = config.nclients / config.nthreads;
|
|
|
|
ssize_t nclients_rem = config.nclients % config.nthreads;
|
2014-02-28 01:10:42 +01:00
|
|
|
|
2015-08-08 17:51:58 +02:00
|
|
|
size_t rate_per_thread = config.rate / config.nthreads;
|
|
|
|
ssize_t rate_per_thread_rem = config.rate % config.nthreads;
|
2015-07-22 01:53:46 +02:00
|
|
|
|
2016-01-07 14:41:37 +01:00
|
|
|
size_t max_samples_per_thread =
|
|
|
|
std::max(static_cast<size_t>(256), MAX_SAMPLES / config.nthreads);
|
|
|
|
|
2015-10-09 14:36:28 +02:00
|
|
|
std::mutex mu;
|
|
|
|
std::condition_variable cv;
|
|
|
|
auto ready = false;
|
2014-02-28 01:10:42 +01:00
|
|
|
|
2015-07-21 20:06:33 +02:00
|
|
|
std::vector<std::future<void>> futures;
|
2015-10-09 14:36:28 +02:00
|
|
|
for (size_t i = 0; i < config.nthreads; ++i) {
|
2015-10-08 14:25:58 +02:00
|
|
|
auto rate = rate_per_thread;
|
|
|
|
if (rate_per_thread_rem > 0) {
|
|
|
|
--rate_per_thread_rem;
|
|
|
|
++rate;
|
|
|
|
}
|
|
|
|
auto nclients = nclients_per_thread;
|
|
|
|
if (nclients_rem > 0) {
|
|
|
|
--nclients_rem;
|
|
|
|
++nclients;
|
|
|
|
}
|
|
|
|
|
2015-08-08 17:51:58 +02:00
|
|
|
size_t nreqs;
|
2015-10-08 14:25:58 +02:00
|
|
|
if (config.timing_script) {
|
|
|
|
// With timing script, each client issues config.nreqs requests.
|
|
|
|
// We divide nreqs by number of clients in Worker ctor to
|
|
|
|
// distribute requests to those clients evenly, so multiply
|
|
|
|
// config.nreqs here by config.nclients.
|
|
|
|
nreqs = config.nreqs * nclients;
|
2015-08-08 17:51:58 +02:00
|
|
|
} else {
|
2015-10-08 14:25:58 +02:00
|
|
|
nreqs = nreqs_per_thread;
|
|
|
|
if (nreqs_rem > 0) {
|
|
|
|
--nreqs_rem;
|
|
|
|
++nreqs;
|
2015-10-05 17:27:00 +02:00
|
|
|
}
|
2015-10-08 14:25:58 +02:00
|
|
|
}
|
2015-10-05 17:27:00 +02:00
|
|
|
|
2016-01-07 14:41:37 +01:00
|
|
|
workers.push_back(create_worker(i, ssl_ctx, nreqs, nclients, rate,
|
|
|
|
max_samples_per_thread));
|
2015-07-23 20:21:12 +02:00
|
|
|
auto &worker = workers.back();
|
2015-07-21 20:06:33 +02:00
|
|
|
futures.push_back(
|
2015-10-09 14:36:28 +02:00
|
|
|
std::async(std::launch::async, [&worker, &mu, &cv, &ready]() {
|
|
|
|
{
|
|
|
|
std::unique_lock<std::mutex> ulk(mu);
|
|
|
|
cv.wait(ulk, [&ready] { return ready; });
|
|
|
|
}
|
|
|
|
worker->run();
|
|
|
|
}));
|
2015-07-21 20:06:33 +02:00
|
|
|
}
|
2015-10-05 17:27:00 +02:00
|
|
|
|
2015-10-08 14:25:58 +02:00
|
|
|
{
|
2015-10-09 14:36:28 +02:00
|
|
|
std::lock_guard<std::mutex> lg(mu);
|
|
|
|
ready = true;
|
|
|
|
cv.notify_all();
|
2015-07-23 18:37:44 +02:00
|
|
|
}
|
2015-10-05 17:27:00 +02:00
|
|
|
|
2015-10-09 14:36:28 +02:00
|
|
|
auto start = std::chrono::steady_clock::now();
|
2014-03-03 17:12:11 +01:00
|
|
|
|
2015-07-21 20:06:33 +02:00
|
|
|
for (auto &fut : futures) {
|
|
|
|
fut.get();
|
|
|
|
}
|
2015-10-09 14:36:28 +02:00
|
|
|
|
|
|
|
#else // NOTHREADS
|
|
|
|
auto rate = config.rate;
|
|
|
|
auto nclients = config.nclients;
|
|
|
|
auto nreqs =
|
|
|
|
config.timing_script ? config.nreqs * config.nclients : config.nreqs;
|
|
|
|
|
2016-01-07 14:41:37 +01:00
|
|
|
workers.push_back(
|
|
|
|
create_worker(0, ssl_ctx, nreqs, nclients, rate, MAX_SAMPLES));
|
2015-10-09 14:36:28 +02:00
|
|
|
|
|
|
|
auto start = std::chrono::steady_clock::now();
|
|
|
|
|
|
|
|
workers.back()->run();
|
2014-10-05 07:25:15 +02:00
|
|
|
#endif // NOTHREADS
|
2014-03-03 17:12:11 +01:00
|
|
|
|
2014-02-28 01:10:42 +01:00
|
|
|
auto end = std::chrono::steady_clock::now();
|
2015-01-31 10:13:07 +01:00
|
|
|
auto duration =
|
|
|
|
std::chrono::duration_cast<std::chrono::microseconds>(end - start);
|
|
|
|
|
2015-12-01 14:29:30 +01:00
|
|
|
Stats stats(0, 0);
|
2015-07-23 20:21:12 +02:00
|
|
|
for (const auto &w : workers) {
|
2015-01-31 10:13:07 +01:00
|
|
|
const auto &s = w->stats;
|
|
|
|
|
|
|
|
stats.req_todo += s.req_todo;
|
|
|
|
stats.req_started += s.req_started;
|
|
|
|
stats.req_done += s.req_done;
|
2015-08-18 07:52:22 +02:00
|
|
|
stats.req_timedout += s.req_timedout;
|
2015-01-31 10:13:07 +01:00
|
|
|
stats.req_success += s.req_success;
|
|
|
|
stats.req_status_success += s.req_status_success;
|
|
|
|
stats.req_failed += s.req_failed;
|
|
|
|
stats.req_error += s.req_error;
|
|
|
|
stats.bytes_total += s.bytes_total;
|
|
|
|
stats.bytes_head += s.bytes_head;
|
2015-11-03 17:03:35 +01:00
|
|
|
stats.bytes_head_decomp += s.bytes_head_decomp;
|
2015-01-31 10:13:07 +01:00
|
|
|
stats.bytes_body += s.bytes_body;
|
|
|
|
|
|
|
|
for (size_t i = 0; i < stats.status.size(); ++i) {
|
|
|
|
stats.status[i] += s.status[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-23 20:21:12 +02:00
|
|
|
auto ts = process_time_stats(workers);
|
2014-02-28 01:10:42 +01:00
|
|
|
|
|
|
|
// Requests which have not been issued due to connection errors, are
|
|
|
|
// counted towards req_failed and req_error.
|
2015-01-31 10:13:07 +01:00
|
|
|
auto req_not_issued =
|
2017-07-28 23:08:20 +02:00
|
|
|
(stats.req_todo - stats.req_status_success - stats.req_failed);
|
2015-01-31 10:13:07 +01:00
|
|
|
stats.req_failed += req_not_issued;
|
|
|
|
stats.req_error += req_not_issued;
|
|
|
|
|
|
|
|
// UI is heavily inspired by weighttp[1] and wrk[2]
|
|
|
|
//
|
|
|
|
// [1] https://github.com/lighttpd/weighttp
|
|
|
|
// [2] https://github.com/wg/wrk
|
2015-07-13 20:28:15 +02:00
|
|
|
double rps = 0;
|
2015-01-31 10:13:07 +01:00
|
|
|
int64_t bps = 0;
|
|
|
|
if (duration.count() > 0) {
|
2017-07-28 23:08:20 +02:00
|
|
|
if (config.is_timing_based_mode()) {
|
|
|
|
// we only want to consider the main duration if warm-up is given
|
|
|
|
rps = stats.req_success / config.duration;
|
|
|
|
bps = stats.bytes_total / config.duration;
|
|
|
|
} else {
|
|
|
|
auto secd = std::chrono::duration_cast<
|
2017-08-23 12:19:00 +02:00
|
|
|
std::chrono::duration<double, std::chrono::seconds::period>>(
|
|
|
|
duration);
|
2017-07-28 23:08:20 +02:00
|
|
|
rps = stats.req_success / secd.count();
|
|
|
|
bps = stats.bytes_total / secd.count();
|
|
|
|
}
|
2015-01-31 10:13:07 +01:00
|
|
|
}
|
|
|
|
|
2015-11-03 17:03:35 +01:00
|
|
|
double header_space_savings = 0.;
|
|
|
|
if (stats.bytes_head_decomp > 0) {
|
|
|
|
header_space_savings =
|
|
|
|
1. - static_cast<double>(stats.bytes_head) / stats.bytes_head_decomp;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::cout << std::fixed << std::setprecision(2) << R"(
|
2016-10-15 11:36:04 +02:00
|
|
|
finished in )"
|
|
|
|
<< util::format_duration(duration) << ", " << rps << " req/s, "
|
2016-01-11 10:12:31 +01:00
|
|
|
<< util::utos_funit(bps) << R"(B/s
|
2018-06-09 09:02:26 +02:00
|
|
|
requests: )" << stats.req_todo
|
|
|
|
<< " total, " << stats.req_started << " started, " << stats.req_done
|
|
|
|
<< " done, " << stats.req_status_success << " succeeded, "
|
|
|
|
<< stats.req_failed << " failed, " << stats.req_error
|
|
|
|
<< " errored, " << stats.req_timedout << R"( timeout
|
|
|
|
status codes: )"
|
|
|
|
<< stats.status[2] << " 2xx, " << stats.status[3] << " 3xx, "
|
|
|
|
<< stats.status[4] << " 4xx, " << stats.status[5] << R"( 5xx
|
2016-10-15 11:36:04 +02:00
|
|
|
traffic: )" << util::utos_funit(stats.bytes_total)
|
|
|
|
<< "B (" << stats.bytes_total << ") total, "
|
|
|
|
<< util::utos_funit(stats.bytes_head) << "B (" << stats.bytes_head
|
|
|
|
<< ") headers (space savings " << header_space_savings * 100
|
|
|
|
<< "%), " << util::utos_funit(stats.bytes_body) << "B ("
|
|
|
|
<< stats.bytes_body << R"() data
|
2015-01-31 10:13:07 +01:00
|
|
|
min max mean sd +/- sd
|
2018-06-09 09:02:26 +02:00
|
|
|
time for request: )"
|
|
|
|
<< std::setw(10) << util::format_duration(ts.request.min) << " "
|
|
|
|
<< std::setw(10) << util::format_duration(ts.request.max) << " "
|
|
|
|
<< std::setw(10) << util::format_duration(ts.request.mean) << " "
|
|
|
|
<< std::setw(10) << util::format_duration(ts.request.sd)
|
|
|
|
<< std::setw(9) << util::dtos(ts.request.within_sd) << "%"
|
2015-05-03 09:47:32 +02:00
|
|
|
<< "\ntime for connect: " << std::setw(10)
|
2015-05-04 04:48:21 +02:00
|
|
|
<< util::format_duration(ts.connect.min) << " " << std::setw(10)
|
|
|
|
<< util::format_duration(ts.connect.max) << " " << std::setw(10)
|
|
|
|
<< util::format_duration(ts.connect.mean) << " " << std::setw(10)
|
|
|
|
<< util::format_duration(ts.connect.sd) << std::setw(9)
|
|
|
|
<< util::dtos(ts.connect.within_sd) << "%"
|
2015-05-03 09:47:32 +02:00
|
|
|
<< "\ntime to 1st byte: " << std::setw(10)
|
2015-05-04 04:48:21 +02:00
|
|
|
<< util::format_duration(ts.ttfb.min) << " " << std::setw(10)
|
|
|
|
<< util::format_duration(ts.ttfb.max) << " " << std::setw(10)
|
|
|
|
<< util::format_duration(ts.ttfb.mean) << " " << std::setw(10)
|
|
|
|
<< util::format_duration(ts.ttfb.sd) << std::setw(9)
|
2015-12-01 15:49:28 +01:00
|
|
|
<< util::dtos(ts.ttfb.within_sd) << "%"
|
2015-12-19 14:56:10 +01:00
|
|
|
<< "\nreq/s : " << std::setw(10) << ts.rps.min << " "
|
2015-12-01 15:49:28 +01:00
|
|
|
<< std::setw(10) << ts.rps.max << " " << std::setw(10)
|
|
|
|
<< ts.rps.mean << " " << std::setw(10) << ts.rps.sd << std::setw(9)
|
|
|
|
<< util::dtos(ts.rps.within_sd) << "%" << std::endl;
|
2014-06-19 17:00:06 +02:00
|
|
|
|
|
|
|
SSL_CTX_free(ssl_ctx);
|
|
|
|
|
2018-11-23 04:46:11 +01:00
|
|
|
if (config.log_fd != -1) {
|
|
|
|
close(config.log_fd);
|
|
|
|
}
|
|
|
|
|
2014-02-28 01:10:42 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace h2load
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
int main(int argc, char **argv) { return h2load::main(argc, argv); }
|