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.
|
|
|
|
*/
|
|
|
|
#ifndef H2LOAD_H
|
|
|
|
#define H2LOAD_H
|
|
|
|
|
|
|
|
#include "nghttp2_config.h"
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
2015-05-13 15:30:35 +02:00
|
|
|
#ifdef HAVE_SYS_SOCKET_H
|
2018-06-09 09:21:30 +02:00
|
|
|
# include <sys/socket.h>
|
2015-05-13 15:30:35 +02:00
|
|
|
#endif // HAVE_SYS_SOCKET_H
|
|
|
|
#ifdef HAVE_NETDB_H
|
2018-06-09 09:21:30 +02:00
|
|
|
# include <netdb.h>
|
2015-05-13 15:30:35 +02:00
|
|
|
#endif // HAVE_NETDB_H
|
2016-01-19 11:24:15 +01:00
|
|
|
#include <sys/un.h>
|
2014-02-28 01:10:42 +01:00
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
#include <string>
|
|
|
|
#include <unordered_map>
|
|
|
|
#include <memory>
|
2015-01-31 10:13:07 +01:00
|
|
|
#include <chrono>
|
|
|
|
#include <array>
|
2014-02-28 01:10:42 +01:00
|
|
|
|
|
|
|
#include <nghttp2/nghttp2.h>
|
|
|
|
|
2021-08-21 12:00:43 +02:00
|
|
|
#ifdef ENABLE_HTTP3
|
|
|
|
# include <ngtcp2/ngtcp2.h>
|
|
|
|
# include <ngtcp2/ngtcp2_crypto.h>
|
|
|
|
#endif // ENABLE_HTTP3
|
2019-06-08 15:05:25 +02:00
|
|
|
|
2014-12-27 18:59:06 +01:00
|
|
|
#include <ev.h>
|
2014-02-28 01:10:42 +01:00
|
|
|
|
|
|
|
#include <openssl/ssl.h>
|
|
|
|
|
2014-10-22 15:53:54 +02:00
|
|
|
#include "http2.h"
|
2021-08-21 12:00:43 +02:00
|
|
|
#ifdef ENABLE_HTTP3
|
|
|
|
# include "quic.h"
|
|
|
|
#endif // ENABLE_HTTP3
|
2016-06-12 11:50:52 +02:00
|
|
|
#include "memchunk.h"
|
2015-06-21 07:32:47 +02:00
|
|
|
#include "template.h"
|
2014-12-27 18:59:06 +01:00
|
|
|
|
|
|
|
using namespace nghttp2;
|
2014-10-22 15:53:54 +02:00
|
|
|
|
2014-02-28 01:10:42 +01:00
|
|
|
namespace h2load {
|
|
|
|
|
2016-06-12 11:50:52 +02:00
|
|
|
constexpr auto BACKOFF_WRITE_BUFFER_THRES = 16_k;
|
|
|
|
|
2014-02-28 01:10:42 +01:00
|
|
|
class Session;
|
2015-07-15 01:41:29 +02:00
|
|
|
struct Worker;
|
2014-02-28 01:10:42 +01:00
|
|
|
|
|
|
|
struct Config {
|
2014-03-14 15:15:01 +01:00
|
|
|
std::vector<std::vector<nghttp2_nv>> nva;
|
2015-09-14 15:33:48 +02:00
|
|
|
std::vector<std::string> h1reqs;
|
2015-07-31 19:49:59 +02:00
|
|
|
std::vector<ev_tstamp> timings;
|
2014-10-22 15:53:54 +02:00
|
|
|
nghttp2::Headers custom_headers;
|
2014-02-28 01:10:42 +01:00
|
|
|
std::string scheme;
|
|
|
|
std::string host;
|
2019-12-12 17:33:34 +01:00
|
|
|
std::string connect_to_host;
|
2014-10-22 00:29:36 +02:00
|
|
|
std::string ifile;
|
2015-07-08 16:14:41 +02:00
|
|
|
std::string ciphers;
|
2019-08-08 02:59:21 +02:00
|
|
|
std::string tls13_ciphers;
|
2019-07-24 16:14:33 +02:00
|
|
|
// supported groups (or curves).
|
|
|
|
std::string groups;
|
2015-03-26 11:53:42 +01:00
|
|
|
// length of upload data
|
|
|
|
int64_t data_length;
|
2020-12-03 14:29:30 +01:00
|
|
|
// memory mapped upload data
|
|
|
|
uint8_t *data;
|
2014-02-28 01:10:42 +01:00
|
|
|
addrinfo *addrs;
|
|
|
|
size_t nreqs;
|
|
|
|
size_t nclients;
|
2014-03-03 17:12:11 +01:00
|
|
|
size_t nthreads;
|
2014-02-28 01:10:42 +01:00
|
|
|
// The maximum number of concurrent streams per session.
|
2014-03-14 15:15:01 +01:00
|
|
|
ssize_t max_concurrent_streams;
|
2014-02-28 01:10:42 +01:00
|
|
|
size_t window_bits;
|
|
|
|
size_t connection_window_bits;
|
2021-11-14 01:35:15 +01:00
|
|
|
size_t max_frame_size;
|
2015-07-13 20:28:15 +02:00
|
|
|
// rate at which connections should be made
|
2015-08-08 17:51:58 +02:00
|
|
|
size_t rate;
|
2015-10-05 17:27:00 +02:00
|
|
|
ev_tstamp rate_period;
|
2017-07-28 23:08:20 +02:00
|
|
|
// amount of time for main measurements in timing-based test
|
|
|
|
ev_tstamp duration;
|
|
|
|
// amount of time to wait before starting measurements in timing-based test
|
|
|
|
ev_tstamp warm_up_time;
|
2015-08-18 07:52:22 +02:00
|
|
|
// amount of time to wait for activity on a given connection
|
2015-10-10 10:52:51 +02:00
|
|
|
ev_tstamp conn_active_timeout;
|
2015-08-18 07:52:22 +02:00
|
|
|
// amount of time to wait after the last request is made on a connection
|
2015-10-10 10:52:51 +02:00
|
|
|
ev_tstamp conn_inactivity_timeout;
|
2017-12-17 05:23:37 +01:00
|
|
|
enum { PROTO_HTTP2, PROTO_HTTP1_1 } no_tls_proto;
|
2016-10-06 15:20:10 +02:00
|
|
|
uint32_t header_table_size;
|
|
|
|
uint32_t encoder_header_table_size;
|
2015-03-26 11:53:42 +01:00
|
|
|
// file descriptor for upload data
|
|
|
|
int data_fd;
|
2018-11-23 04:46:11 +01:00
|
|
|
// file descriptor to write per-request stats to.
|
|
|
|
int log_fd;
|
2021-03-12 20:12:46 +01:00
|
|
|
// base file name of qlog output files
|
|
|
|
std::string qlog_file_base;
|
2014-02-28 01:10:42 +01:00
|
|
|
uint16_t port;
|
2014-10-22 15:42:40 +02:00
|
|
|
uint16_t default_port;
|
2019-12-21 03:38:27 +01:00
|
|
|
uint16_t connect_to_port;
|
2014-02-28 01:10:42 +01:00
|
|
|
bool verbose;
|
2015-07-31 19:49:59 +02:00
|
|
|
bool timing_script;
|
|
|
|
std::string base_uri;
|
2016-01-19 11:24:15 +01:00
|
|
|
// true if UNIX domain socket is used. In this case, base_uri is
|
|
|
|
// not used in usual way.
|
|
|
|
bool base_uri_unix;
|
|
|
|
// used when UNIX domain socket is used (base_uri_unix is true).
|
|
|
|
sockaddr_un unix_addr;
|
2015-09-14 15:33:48 +02:00
|
|
|
// list of supported NPN/ALPN protocol strings in the order of
|
|
|
|
// preference.
|
|
|
|
std::vector<std::string> npn_list;
|
2021-02-23 03:39:02 +01:00
|
|
|
// The number of request per second for each client.
|
|
|
|
double rps;
|
2019-12-18 06:23:05 +01:00
|
|
|
// Disables GSO for UDP connections.
|
|
|
|
bool no_udp_gso;
|
2021-09-07 07:42:35 +02:00
|
|
|
// The maximum UDP datagram payload size to send.
|
|
|
|
size_t max_udp_payload_size;
|
2014-02-28 01:10:42 +01:00
|
|
|
|
|
|
|
Config();
|
|
|
|
~Config();
|
2015-07-13 20:28:15 +02:00
|
|
|
|
2015-08-08 17:51:58 +02:00
|
|
|
bool is_rate_mode() const;
|
2017-07-28 23:08:20 +02:00
|
|
|
bool is_timing_based_mode() const;
|
2015-07-31 19:49:59 +02:00
|
|
|
bool has_base_uri() const;
|
2021-02-23 03:39:02 +01:00
|
|
|
bool rps_enabled() const;
|
2019-06-08 15:05:25 +02:00
|
|
|
bool is_quic() const;
|
2014-02-28 01:10:42 +01:00
|
|
|
};
|
|
|
|
|
2015-01-31 10:13:07 +01:00
|
|
|
struct RequestStat {
|
|
|
|
// time point when request was sent
|
|
|
|
std::chrono::steady_clock::time_point request_time;
|
2018-11-11 19:33:50 +01:00
|
|
|
// same, but in wall clock reference frame
|
|
|
|
std::chrono::system_clock::time_point request_wall_time;
|
2015-01-31 10:13:07 +01:00
|
|
|
// time point when stream was closed
|
|
|
|
std::chrono::steady_clock::time_point stream_close_time;
|
2015-05-03 09:47:32 +02:00
|
|
|
// upload data length sent so far
|
2015-03-26 11:53:42 +01:00
|
|
|
int64_t data_offset;
|
2018-11-11 19:33:50 +01:00
|
|
|
// HTTP status code
|
|
|
|
int status;
|
2015-01-31 10:13:07 +01:00
|
|
|
// true if stream was successfully closed. This means stream was
|
|
|
|
// not reset, but it does not mean HTTP level error (e.g., 404).
|
|
|
|
bool completed;
|
|
|
|
};
|
|
|
|
|
2015-12-01 14:29:30 +01:00
|
|
|
struct ClientStat {
|
2015-12-01 15:49:28 +01:00
|
|
|
// time client started (i.e., first connect starts)
|
|
|
|
std::chrono::steady_clock::time_point client_start_time;
|
|
|
|
// time client end (i.e., client somehow processed all requests it
|
|
|
|
// is responsible for, and disconnected)
|
|
|
|
std::chrono::steady_clock::time_point client_end_time;
|
2017-10-28 15:25:42 +02:00
|
|
|
// The number of requests completed successful, but not necessarily
|
2015-12-01 15:49:28 +01:00
|
|
|
// means successful HTTP status code.
|
|
|
|
size_t req_success;
|
|
|
|
|
|
|
|
// The following 3 numbers are overwritten each time when connection
|
|
|
|
// is made.
|
|
|
|
|
2015-12-01 14:29:30 +01:00
|
|
|
// time connect starts
|
|
|
|
std::chrono::steady_clock::time_point connect_start_time;
|
|
|
|
// time to connect
|
|
|
|
std::chrono::steady_clock::time_point connect_time;
|
|
|
|
// time to first byte (TTFB)
|
|
|
|
std::chrono::steady_clock::time_point ttfb;
|
|
|
|
};
|
|
|
|
|
2015-12-01 15:49:28 +01:00
|
|
|
struct SDStat {
|
2015-05-04 04:48:21 +02:00
|
|
|
// min, max, mean and sd (standard deviation)
|
2015-12-01 15:49:28 +01:00
|
|
|
double min, max, mean, sd;
|
2015-05-04 04:48:21 +02:00
|
|
|
// percentage of samples inside mean -/+ sd
|
|
|
|
double within_sd;
|
|
|
|
};
|
|
|
|
|
2015-12-01 15:49:28 +01:00
|
|
|
struct SDStats {
|
2015-05-04 04:48:21 +02:00
|
|
|
// time for request
|
2015-12-01 15:49:28 +01:00
|
|
|
SDStat request;
|
2015-05-04 04:48:21 +02:00
|
|
|
// time for connect
|
2015-12-01 15:49:28 +01:00
|
|
|
SDStat connect;
|
2015-05-04 04:48:21 +02:00
|
|
|
// time to first byte (TTFB)
|
2015-12-01 15:49:28 +01:00
|
|
|
SDStat ttfb;
|
|
|
|
// request per second for each client
|
|
|
|
SDStat rps;
|
2015-01-31 10:13:07 +01:00
|
|
|
};
|
|
|
|
|
2014-02-28 01:10:42 +01:00
|
|
|
struct Stats {
|
2015-12-01 14:29:30 +01:00
|
|
|
Stats(size_t req_todo, size_t nclients);
|
2014-02-28 01:10:42 +01:00
|
|
|
// The total number of requests
|
|
|
|
size_t req_todo;
|
|
|
|
// The number of requests issued so far
|
|
|
|
size_t req_started;
|
|
|
|
// The number of requests finished
|
|
|
|
size_t req_done;
|
2017-10-28 15:25:42 +02:00
|
|
|
// The number of requests completed successful, but not necessarily
|
2015-01-31 10:13:07 +01:00
|
|
|
// means successful HTTP status code.
|
2014-02-28 01:10:42 +01:00
|
|
|
size_t req_success;
|
2015-01-31 10:13:07 +01:00
|
|
|
// The number of requests marked as success. HTTP status code is
|
|
|
|
// also considered as success. This is subset of req_done.
|
|
|
|
size_t req_status_success;
|
2014-02-28 01:10:42 +01:00
|
|
|
// The number of requests failed. This is subset of req_done.
|
|
|
|
size_t req_failed;
|
|
|
|
// The number of requests failed due to network errors. This is
|
|
|
|
// subset of req_failed.
|
|
|
|
size_t req_error;
|
2015-08-18 07:52:22 +02:00
|
|
|
// The number of requests that failed due to timeout.
|
|
|
|
size_t req_timedout;
|
2014-02-28 01:10:42 +01:00
|
|
|
// The number of bytes received on the "wire". If SSL/TLS is used,
|
|
|
|
// this is the number of decrypted bytes the application received.
|
|
|
|
int64_t bytes_total;
|
2015-11-03 17:03:35 +01:00
|
|
|
// The number of bytes received for header fields. This is
|
|
|
|
// compressed version.
|
2014-02-28 01:10:42 +01:00
|
|
|
int64_t bytes_head;
|
2015-11-03 17:03:35 +01:00
|
|
|
// The number of bytes received for header fields after they are
|
|
|
|
// decompressed.
|
|
|
|
int64_t bytes_head_decomp;
|
2014-02-28 01:10:42 +01:00
|
|
|
// The number of bytes received in DATA frame.
|
|
|
|
int64_t bytes_body;
|
|
|
|
// The number of each HTTP status category, status[i] is status code
|
|
|
|
// in the range [i*100, (i+1)*100).
|
2015-01-31 10:13:07 +01:00
|
|
|
std::array<size_t, 6> status;
|
|
|
|
// The statistics per request
|
|
|
|
std::vector<RequestStat> req_stats;
|
2021-02-23 09:41:27 +01:00
|
|
|
// The statistics per client
|
2015-12-01 14:29:30 +01:00
|
|
|
std::vector<ClientStat> client_stats;
|
2021-02-23 09:39:38 +01:00
|
|
|
// The number of UDP datagrams received.
|
|
|
|
size_t udp_dgram_recv;
|
|
|
|
// The number of UDP datagrams sent.
|
|
|
|
size_t udp_dgram_sent;
|
2014-02-28 01:10:42 +01:00
|
|
|
};
|
|
|
|
|
2014-11-27 15:39:04 +01:00
|
|
|
enum ClientState { CLIENT_IDLE, CLIENT_CONNECTED };
|
2014-02-28 01:10:42 +01:00
|
|
|
|
2017-07-28 23:08:20 +02:00
|
|
|
// This type tells whether the client is in warmup phase or not or is over
|
2017-08-23 12:19:00 +02:00
|
|
|
enum class Phase {
|
|
|
|
INITIAL_IDLE, // Initial idle state before warm-up phase
|
|
|
|
WARM_UP, // Warm up phase when no measurements are done
|
2017-07-28 23:08:20 +02:00
|
|
|
MAIN_DURATION, // Main measurement phase; if timing-based
|
|
|
|
// test is not run, this is the default phase
|
2017-08-23 12:19:00 +02:00
|
|
|
DURATION_OVER // This phase occurs after the measurements are over
|
2017-07-28 23:08:20 +02:00
|
|
|
};
|
|
|
|
|
2014-02-28 01:10:42 +01:00
|
|
|
struct Client;
|
|
|
|
|
2017-08-14 13:25:02 +02:00
|
|
|
// We use reservoir sampling method
|
2016-01-06 14:43:09 +01:00
|
|
|
struct Sampling {
|
2017-08-14 13:25:02 +02:00
|
|
|
// maximum number of samples
|
|
|
|
size_t max_samples;
|
2016-01-06 14:43:09 +01:00
|
|
|
// number of samples seen, including discarded samples.
|
|
|
|
size_t n;
|
|
|
|
};
|
|
|
|
|
2014-02-28 01:10:42 +01:00
|
|
|
struct Worker {
|
2016-06-12 11:50:52 +02:00
|
|
|
MemchunkPool mcpool;
|
2021-11-03 13:23:26 +01:00
|
|
|
std::mt19937 randgen;
|
2014-02-28 01:10:42 +01:00
|
|
|
Stats stats;
|
2016-01-06 14:43:09 +01:00
|
|
|
Sampling request_times_smp;
|
2016-01-06 15:03:37 +01:00
|
|
|
Sampling client_smp;
|
2014-12-27 18:59:06 +01:00
|
|
|
struct ev_loop *loop;
|
2014-02-28 01:10:42 +01:00
|
|
|
SSL_CTX *ssl_ctx;
|
|
|
|
Config *config;
|
|
|
|
size_t progress_interval;
|
2014-03-03 17:12:11 +01:00
|
|
|
uint32_t id;
|
2014-11-08 13:24:24 +01:00
|
|
|
bool tls_info_report_done;
|
2015-09-14 15:33:48 +02:00
|
|
|
bool app_info_report_done;
|
2015-08-08 17:51:58 +02:00
|
|
|
size_t nconns_made;
|
2015-10-08 14:25:58 +02:00
|
|
|
// number of clients this worker handles
|
2015-08-08 17:51:58 +02:00
|
|
|
size_t nclients;
|
2015-10-08 14:25:58 +02:00
|
|
|
// number of requests each client issues
|
|
|
|
size_t nreqs_per_client;
|
|
|
|
// at most nreqs_rem clients get an extra request
|
|
|
|
size_t nreqs_rem;
|
2015-08-08 17:51:58 +02:00
|
|
|
size_t rate;
|
2016-01-07 14:41:37 +01:00
|
|
|
// maximum number of samples in this worker thread
|
|
|
|
size_t max_samples;
|
2015-07-21 20:28:12 +02:00
|
|
|
ev_timer timeout_watcher;
|
2015-12-01 14:29:30 +01:00
|
|
|
// The next client ID this worker assigns
|
|
|
|
uint32_t next_client_id;
|
2017-08-23 12:19:00 +02:00
|
|
|
// Keeps track of the current phase (for timing-based experiment) for the
|
|
|
|
// worker
|
2017-07-28 23:08:20 +02:00
|
|
|
Phase current_phase;
|
|
|
|
// We need to keep track of the clients in order to stop them when needed
|
2017-08-23 12:19:00 +02:00
|
|
|
std::vector<Client *> clients;
|
|
|
|
// This is only active when there is not a bounded number of requests
|
|
|
|
// specified
|
2017-07-28 23:08:20 +02:00
|
|
|
ev_timer duration_watcher;
|
|
|
|
ev_timer warmup_watcher;
|
2014-02-28 01:10:42 +01:00
|
|
|
|
2015-07-25 00:35:11 +02:00
|
|
|
Worker(uint32_t id, SSL_CTX *ssl_ctx, size_t nreq_todo, size_t nclients,
|
2016-01-07 14:41:37 +01:00
|
|
|
size_t rate, size_t max_samples, Config *config);
|
2014-02-28 01:10:42 +01:00
|
|
|
~Worker();
|
2015-01-31 10:13:07 +01:00
|
|
|
Worker(Worker &&o) = default;
|
2014-02-28 01:10:42 +01:00
|
|
|
void run();
|
2016-01-05 14:36:37 +01:00
|
|
|
void sample_req_stat(RequestStat *req_stat);
|
2016-01-06 15:03:37 +01:00
|
|
|
void sample_client_stat(ClientStat *cstat);
|
2016-01-05 15:56:31 +01:00
|
|
|
void report_progress();
|
|
|
|
void report_rate_progress();
|
2017-07-28 23:08:20 +02:00
|
|
|
// This function calls the destructors of all the clients.
|
|
|
|
void stop_all_clients();
|
2017-08-08 00:58:12 +02:00
|
|
|
// This function frees a client from the list of clients for this Worker.
|
2017-08-23 12:19:00 +02:00
|
|
|
void free_client(Client *);
|
2014-02-28 01:10:42 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
struct Stream {
|
2016-01-05 14:36:37 +01:00
|
|
|
RequestStat req_stat;
|
2014-02-28 01:10:42 +01:00
|
|
|
int status_success;
|
|
|
|
Stream();
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Client {
|
2016-06-12 11:50:52 +02:00
|
|
|
DefaultMemchunks wb;
|
2014-02-28 01:10:42 +01:00
|
|
|
std::unordered_map<int32_t, Stream> streams;
|
2016-01-06 15:03:37 +01:00
|
|
|
ClientStat cstat;
|
2014-02-28 01:10:42 +01:00
|
|
|
std::unique_ptr<Session> session;
|
2014-12-27 18:59:06 +01:00
|
|
|
ev_io wev;
|
|
|
|
ev_io rev;
|
|
|
|
std::function<int(Client &)> readfn, writefn;
|
2014-02-28 01:10:42 +01:00
|
|
|
Worker *worker;
|
|
|
|
SSL *ssl;
|
2021-08-21 12:00:43 +02:00
|
|
|
#ifdef ENABLE_HTTP3
|
2019-06-08 15:05:25 +02:00
|
|
|
struct {
|
|
|
|
ev_timer pkt_timer;
|
|
|
|
ngtcp2_conn *conn;
|
2022-03-29 14:22:16 +02:00
|
|
|
ngtcp2_connection_close_error last_error;
|
2019-06-08 15:05:25 +02:00
|
|
|
bool close_requested;
|
2021-03-12 20:12:46 +01:00
|
|
|
FILE *qlog_file;
|
2022-02-10 11:35:50 +01:00
|
|
|
|
|
|
|
struct {
|
|
|
|
bool send_blocked;
|
2022-04-06 11:50:31 +02:00
|
|
|
size_t num_blocked;
|
|
|
|
size_t num_blocked_sent;
|
2022-02-10 11:35:50 +01:00
|
|
|
struct {
|
|
|
|
Address remote_addr;
|
2022-04-06 11:50:31 +02:00
|
|
|
const uint8_t *data;
|
2022-02-10 11:35:50 +01:00
|
|
|
size_t datalen;
|
2022-04-06 11:50:31 +02:00
|
|
|
size_t gso_size;
|
|
|
|
} blocked[2];
|
2022-02-10 11:35:50 +01:00
|
|
|
std::unique_ptr<uint8_t[]> data;
|
|
|
|
} tx;
|
2019-06-08 15:05:25 +02:00
|
|
|
} quic;
|
2021-08-21 12:00:43 +02:00
|
|
|
#endif // ENABLE_HTTP3
|
2015-07-31 19:49:59 +02:00
|
|
|
ev_timer request_timeout_watcher;
|
2014-02-28 01:10:42 +01:00
|
|
|
addrinfo *next_addr;
|
2015-09-28 16:50:44 +02:00
|
|
|
// Address for the current address. When try_new_connection() is
|
|
|
|
// used and current_addr is not nullptr, it is used instead of
|
|
|
|
// trying next address though next_addr. To try new address, set
|
|
|
|
// nullptr to current_addr before calling connect().
|
|
|
|
addrinfo *current_addr;
|
2014-03-14 15:15:01 +01:00
|
|
|
size_t reqidx;
|
2014-02-28 01:10:42 +01:00
|
|
|
ClientState state;
|
2014-06-22 04:33:16 +02:00
|
|
|
// The number of requests this client has to issue.
|
|
|
|
size_t req_todo;
|
2017-01-25 16:16:12 +01:00
|
|
|
// The number of requests left to issue
|
|
|
|
size_t req_left;
|
|
|
|
// The number of requests currently have started, but not abandoned
|
|
|
|
// or finished.
|
|
|
|
size_t req_inflight;
|
2014-06-22 04:33:16 +02:00
|
|
|
// The number of requests this client has issued so far.
|
|
|
|
size_t req_started;
|
2014-11-06 16:28:10 +01:00
|
|
|
// The number of requests this client has done so far.
|
2014-06-22 04:33:16 +02:00
|
|
|
size_t req_done;
|
2015-12-01 14:29:30 +01:00
|
|
|
// The client id per worker
|
|
|
|
uint32_t id;
|
2014-12-27 18:59:06 +01:00
|
|
|
int fd;
|
2019-06-08 15:05:25 +02:00
|
|
|
Address local_addr;
|
2015-08-18 07:52:22 +02:00
|
|
|
ev_timer conn_active_watcher;
|
|
|
|
ev_timer conn_inactivity_watcher;
|
2015-09-14 15:33:48 +02:00
|
|
|
std::string selected_proto;
|
2015-09-28 16:50:44 +02:00
|
|
|
bool new_connection_requested;
|
2016-06-12 10:42:12 +02:00
|
|
|
// true if the current connection will be closed, and no more new
|
|
|
|
// request cannot be processed.
|
|
|
|
bool final;
|
2021-02-23 03:39:02 +01:00
|
|
|
// rps_watcher is a timer to invoke callback periodically to
|
|
|
|
// generate a new request.
|
|
|
|
ev_timer rps_watcher;
|
|
|
|
// The timestamp that starts the period which contributes to the
|
|
|
|
// next request generation.
|
|
|
|
ev_tstamp rps_duration_started;
|
|
|
|
// The number of requests allowed by rps, but limited by stream
|
|
|
|
// concurrency.
|
|
|
|
size_t rps_req_pending;
|
|
|
|
// The number of in-flight streams. req_inflight has similar value
|
|
|
|
// but it only measures requests made during Phase::MAIN_DURATION.
|
|
|
|
// rps_req_inflight measures the number of requests in all phases,
|
|
|
|
// and it is only used if --rps is given.
|
|
|
|
size_t rps_req_inflight;
|
2014-02-28 01:10:42 +01:00
|
|
|
|
2015-01-04 17:56:02 +01:00
|
|
|
enum { ERR_CONNECT_FAIL = -100 };
|
|
|
|
|
2015-12-01 14:29:30 +01:00
|
|
|
Client(uint32_t id, Worker *worker, size_t req_todo);
|
2014-02-28 01:10:42 +01:00
|
|
|
~Client();
|
2015-09-28 16:50:44 +02:00
|
|
|
int make_socket(addrinfo *addr);
|
2014-02-28 01:10:42 +01:00
|
|
|
int connect();
|
|
|
|
void disconnect();
|
2014-06-26 16:20:12 +02:00
|
|
|
void fail();
|
2016-03-02 14:24:14 +01:00
|
|
|
// Call this function when do_read() returns -1. This function
|
|
|
|
// tries to connect to the remote host again if it is requested. If
|
|
|
|
// so, this function returns 0, and this object should be retained.
|
|
|
|
// Otherwise, this function returns -1, and this object should be
|
|
|
|
// deleted.
|
|
|
|
int try_again_or_fail();
|
2015-08-18 07:52:22 +02:00
|
|
|
void timeout();
|
|
|
|
void restart_timeout();
|
2015-10-29 14:31:03 +01:00
|
|
|
int submit_request();
|
|
|
|
void process_request_failure();
|
2015-08-18 07:52:22 +02:00
|
|
|
void process_timedout_streams();
|
2014-02-28 01:10:42 +01:00
|
|
|
void process_abandoned_streams();
|
2014-11-08 13:24:24 +01:00
|
|
|
void report_tls_info();
|
2015-09-14 15:33:48 +02:00
|
|
|
void report_app_info();
|
2014-02-28 01:10:42 +01:00
|
|
|
void terminate_session();
|
2015-09-28 16:50:44 +02:00
|
|
|
// Asks client to create new connection, instead of just fail.
|
|
|
|
void try_new_connection();
|
2014-12-27 18:59:06 +01:00
|
|
|
|
|
|
|
int do_read();
|
|
|
|
int do_write();
|
|
|
|
|
2015-03-28 12:17:30 +01:00
|
|
|
// low-level I/O callback functions called by do_read/do_write
|
2014-12-27 18:59:06 +01:00
|
|
|
int connected();
|
|
|
|
int read_clear();
|
|
|
|
int write_clear();
|
|
|
|
int tls_handshake();
|
|
|
|
int read_tls();
|
|
|
|
int write_tls();
|
|
|
|
|
|
|
|
int on_read(const uint8_t *data, size_t len);
|
2014-02-28 01:10:42 +01:00
|
|
|
int on_write();
|
2014-12-27 18:59:06 +01:00
|
|
|
|
2015-03-28 12:13:37 +01:00
|
|
|
int connection_made();
|
|
|
|
|
2014-02-28 01:10:42 +01:00
|
|
|
void on_request(int32_t stream_id);
|
2014-11-27 15:39:04 +01:00
|
|
|
void on_header(int32_t stream_id, const uint8_t *name, size_t namelen,
|
2014-02-28 01:10:42 +01:00
|
|
|
const uint8_t *value, size_t valuelen);
|
2015-09-14 15:33:48 +02:00
|
|
|
void on_status_code(int32_t stream_id, uint16_t status);
|
2015-10-29 13:16:47 +01:00
|
|
|
// |success| == true means that the request/response was exchanged
|
|
|
|
// |successfully, but it does not mean response carried successful
|
|
|
|
// |HTTP status code.
|
2016-01-05 14:36:37 +01:00
|
|
|
void on_stream_close(int32_t stream_id, bool success, bool final = false);
|
|
|
|
// Returns RequestStat for |stream_id|. This function must be
|
|
|
|
// called after on_request(stream_id), and before
|
|
|
|
// on_stream_close(stream_id, ...). Otherwise, this will return
|
|
|
|
// nullptr.
|
|
|
|
RequestStat *get_req_stat(int32_t stream_id);
|
2015-01-31 10:13:07 +01:00
|
|
|
|
|
|
|
void record_request_time(RequestStat *req_stat);
|
2015-12-01 14:29:30 +01:00
|
|
|
void record_connect_start_time();
|
|
|
|
void record_connect_time();
|
2015-09-12 04:18:54 +02:00
|
|
|
void record_ttfb();
|
2015-12-01 14:29:30 +01:00
|
|
|
void clear_connect_times();
|
2015-12-01 15:49:28 +01:00
|
|
|
void record_client_start_time();
|
|
|
|
void record_client_end_time();
|
2014-12-27 18:59:06 +01:00
|
|
|
|
|
|
|
void signal_write();
|
2019-06-08 15:05:25 +02:00
|
|
|
|
2021-08-21 12:00:43 +02:00
|
|
|
#ifdef ENABLE_HTTP3
|
2019-06-08 15:05:25 +02:00
|
|
|
// QUIC
|
|
|
|
int quic_init(const sockaddr *local_addr, socklen_t local_addrlen,
|
|
|
|
const sockaddr *remote_addr, socklen_t remote_addrlen);
|
|
|
|
void quic_free();
|
|
|
|
int read_quic();
|
|
|
|
int write_quic();
|
|
|
|
int write_udp(const sockaddr *addr, socklen_t addrlen, const uint8_t *data,
|
2019-12-18 06:23:05 +01:00
|
|
|
size_t datalen, size_t gso_size);
|
2022-04-06 11:50:31 +02:00
|
|
|
void on_send_blocked(const ngtcp2_addr &remote_addr, const uint8_t *data,
|
|
|
|
size_t datalen, size_t gso_size);
|
2022-02-10 11:35:50 +01:00
|
|
|
int send_blocked_packet();
|
2019-06-08 15:05:25 +02:00
|
|
|
void quic_close_connection();
|
|
|
|
|
|
|
|
int quic_handshake_completed();
|
2020-06-07 15:49:34 +02:00
|
|
|
int quic_recv_stream_data(uint32_t flags, int64_t stream_id,
|
|
|
|
const uint8_t *data, size_t datalen);
|
2019-08-31 10:33:11 +02:00
|
|
|
int quic_acked_stream_data_offset(int64_t stream_id, size_t datalen);
|
2019-07-14 15:11:42 +02:00
|
|
|
int quic_stream_close(int64_t stream_id, uint64_t app_error_code);
|
|
|
|
int quic_stream_reset(int64_t stream_id, uint64_t app_error_code);
|
2021-08-09 14:54:04 +02:00
|
|
|
int quic_stream_stop_sending(int64_t stream_id, uint64_t app_error_code);
|
2019-06-08 15:05:25 +02:00
|
|
|
int quic_extend_max_local_streams();
|
|
|
|
|
2021-10-15 12:52:01 +02:00
|
|
|
int quic_on_rx_secret(ngtcp2_crypto_level level, const uint8_t *secret,
|
|
|
|
size_t secretlen);
|
|
|
|
int quic_on_tx_secret(ngtcp2_crypto_level level, const uint8_t *secret,
|
|
|
|
size_t secretlen);
|
2019-06-08 15:05:25 +02:00
|
|
|
void quic_set_tls_alert(uint8_t alert);
|
|
|
|
|
2019-08-29 10:15:59 +02:00
|
|
|
void quic_write_client_handshake(ngtcp2_crypto_level level,
|
|
|
|
const uint8_t *data, size_t datalen);
|
2019-06-08 15:05:25 +02:00
|
|
|
int quic_pkt_timeout();
|
|
|
|
void quic_restart_pkt_timer();
|
2021-03-12 20:12:46 +01:00
|
|
|
void quic_write_qlog(const void *data, size_t datalen);
|
2021-08-21 12:00:43 +02:00
|
|
|
#endif // ENABLE_HTTP3
|
2014-02-28 01:10:42 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace h2load
|
|
|
|
|
|
|
|
#endif // H2LOAD_H
|