From 08bf8a8f1aa4cd07124ad65e8b1127c235b53ede Mon Sep 17 00:00:00 2001 From: Lucas Pardue Date: Wed, 19 Aug 2015 15:05:06 +0000 Subject: [PATCH] Move input file validation. Timing script auto nreqs scale correctly with nclients. --- src/h2load.cc | 114 ++++++++++++++++++++++++++------------------------ 1 file changed, 60 insertions(+), 54 deletions(-) diff --git a/src/h2load.cc b/src/h2load.cc index 9739db2a..8fce4a6e 100644 --- a/src/h2load.cc +++ b/src/h2load.cc @@ -1527,6 +1527,66 @@ int main(int argc, char **argv) { } } + if (config.nclients == 0) { + std::cerr << "-c: the number of clients must be strictly greater than 0." + << std::endl; + exit(EXIT_FAILURE); + } + + std::vector reqlines; + + if (config.ifile.empty()) { + std::vector uris; + std::copy(&argv[optind], &argv[argc], std::back_inserter(uris)); + reqlines = parse_uris(std::begin(uris), std::end(uris)); + } else { + std::vector uris; + if (config.ifile == "-") { + if (!config.timing_script) { + uris = read_uri_from_file(std::cin); + } else { + read_script_from_file(std::cin, config.timings, uris); + } + } else { + std::ifstream infile(config.ifile); + if (!infile) { + std::cerr << "cannot read input file: " << config.ifile << std::endl; + exit(EXIT_FAILURE); + } + + if (!config.timing_script) { + uris = read_uri_from_file(infile); + } else { + read_script_from_file(infile, config.timings, uris); + 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 " + "of requests to " << uris.size() << std::endl; + + config.nreqs = uris.size(); + } + } else { + // each client will execute the full script, so scale nreqs + config.nreqs = uris.size() * config.nclients; + } + } + } + + reqlines = parse_uris(std::begin(uris), std::end(uris)); + } + + if (reqlines.empty()) { + std::cerr << "No URI given" << std::endl; + exit(EXIT_FAILURE); + } + + if (config.max_concurrent_streams == -1) { + config.max_concurrent_streams = reqlines.size(); + } + + assert(config.max_concurrent_streams > 0); if (config.nreqs == 0) { std::cerr << "-n: the number of requests must be strictly greater than 0." << std::endl; @@ -1650,60 +1710,6 @@ int main(int argc, char **argv) { SSL_CTX_set_alpn_protos(ssl_ctx, proto_list.data(), proto_list.size()); #endif // OPENSSL_VERSION_NUMBER >= 0x10002000L - std::vector reqlines; - - if (config.ifile.empty()) { - std::vector uris; - std::copy(&argv[optind], &argv[argc], std::back_inserter(uris)); - reqlines = parse_uris(std::begin(uris), std::end(uris)); - } else { - std::vector uris; - if (config.ifile == "-") { - if (!config.timing_script) { - uris = read_uri_from_file(std::cin); - } else { - read_script_from_file(std::cin, config.timings, uris); - } - } else { - std::ifstream infile(config.ifile); - if (!infile) { - std::cerr << "cannot read input file: " << config.ifile << std::endl; - exit(EXIT_FAILURE); - } - - if (!config.timing_script) { - uris = read_uri_from_file(infile); - } else { - read_script_from_file(infile, config.timings, uris); - 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 " - "of requests to " << uris.size() << std::endl; - - config.nreqs = uris.size(); - } - } else { - config.nreqs = uris.size(); - } - } - } - - reqlines = parse_uris(std::begin(uris), std::end(uris)); - } - - if (reqlines.empty()) { - std::cerr << "No URI given" << std::endl; - exit(EXIT_FAILURE); - } - - if (config.max_concurrent_streams == -1) { - config.max_concurrent_streams = reqlines.size(); - } - - assert(config.max_concurrent_streams > 0); - // if not in rate mode and -C is set, warn that we are ignoring it if (!config.is_rate_mode() && config.nconns != 0) { std::cerr << "-C: warning: This option can only be used with -r, and"