From c9ab031626c7b6f6138eac201a2e1ccffdecfcd4 Mon Sep 17 00:00:00 2001 From: Joe Damato Date: Mon, 21 Jun 2021 15:06:01 -0700 Subject: [PATCH] Add option to control TLS full handshake rate. It can be useful to adjust the rate of TLS session resumption vs full TLS handshakes during load testing. This change adds support for setting TLS session handshake rate. --- src/h2load.cc | 31 +++++++++++++++++++++++++++++++ src/h2load.h | 1 + 2 files changed, 32 insertions(+) diff --git a/src/h2load.cc b/src/h2load.cc index 7d3d8e04..de7fefae 100644 --- a/src/h2load.cc +++ b/src/h2load.cc @@ -471,6 +471,16 @@ int Client::make_socket(addrinfo *addr) { return -1; } if (config.scheme == "https") { + + if (config.full_handshake_rate > 0) { + auto d = std::uniform_int_distribution(0, 99); + if (d(gen) <= config.full_handshake_rate) { + // ok, now we are doign a full handshake.. + SSL_free(ssl); + ssl = NULL; + } + } + if (!ssl) { ssl = SSL_new(worker->ssl_ctx); } @@ -1837,6 +1847,11 @@ std::unique_ptr create_worker(uint32_t id, SSL_CTX *ssl_ctx, << " total requests" << std::endl; } + if (config.full_handshake_rate > 0) { + std::cout << " full TLS handshakes will happen: " << + config.full_handshake_rate << "%% of the time." << std::endl; + } + if (config.is_rate_mode()) { return std::make_unique(id, ssl_ctx, nreqs, nclients, rate, max_samples, &config); @@ -1921,6 +1936,10 @@ Options: Number of native threads. Default: )" << config.nthreads << R"( + --full-handshake-rate= + Whole number representing the percentage of time a full + TLS handshake will happen. For example "70" means 70% of the + time a full handshake will happen. -i, --input-file= Path of a file with multiple URIs are separated by EOLs. This option will disable URIs getting from command-line. @@ -2130,6 +2149,7 @@ int main(int argc, char **argv) { {"log-file", required_argument, &flag, 10}, {"connect-to", required_argument, &flag, 11}, {"rps", required_argument, &flag, 12}, + {"full-handshake-rate", required_argument, &flag, 13}, {nullptr, 0, nullptr, 0}}; int option_index = 0; auto c = getopt_long(argc, argv, @@ -2380,6 +2400,17 @@ int main(int argc, char **argv) { config.rps = v; break; } + case 13: { + char *end = NULL; + auto v = std::strtod(optarg, &end); + if (end == optarg || *end != '\0' || !std::isfinite(v) || 1. / v < 1e-6) { + std::cerr << "--rps: Invalid value " << optarg << std::endl; + exit(EXIT_FAILURE); + } + + config.full_handshake_rate = v; + break; + } } break; default: diff --git a/src/h2load.h b/src/h2load.h index fead67c5..c4e3431a 100644 --- a/src/h2load.h +++ b/src/h2load.h @@ -104,6 +104,7 @@ struct Config { uint16_t default_port; uint16_t connect_to_port; bool verbose; + uint32_t full_handshake_rate; bool timing_script; std::string base_uri; // true if UNIX domain socket is used. In this case, base_uri is