ClickHouse/utils/keeper-bench/main.cpp

88 lines
3.6 KiB
C++
Raw Normal View History

2021-04-12 08:10:23 +00:00
#include <iostream>
2021-04-12 15:40:42 +00:00
#include <boost/program_options.hpp>
#include "Runner.h"
2023-04-07 14:14:39 +00:00
#include "Common/Exception.h"
2021-04-12 15:40:42 +00:00
#include <Common/TerminalSize.h>
#include <Core/Types.h>
2023-04-07 14:14:39 +00:00
#include <boost/program_options/variables_map.hpp>
2021-04-12 08:10:23 +00:00
2023-04-07 14:14:39 +00:00
namespace
{
template <typename T>
std::optional<T> valueToOptional(const boost::program_options::variable_value & value)
{
if (value.empty())
return std::nullopt;
return value.as<T>();
}
}
2021-04-12 08:10:23 +00:00
int main(int argc, char *argv[])
{
2021-04-12 15:40:42 +00:00
bool print_stacktrace = true;
2021-04-12 08:10:23 +00:00
2024-04-10 10:56:29 +00:00
//Poco::AutoPtr<Poco::ConsoleChannel> channel(new Poco::ConsoleChannel(std::cerr));
//Poco::Logger::root().setChannel(channel);
//Poco::Logger::root().setLevel("trace");
2021-04-12 15:40:42 +00:00
try
{
using boost::program_options::value;
boost::program_options::options_description desc = createOptionsDescription("Allowed options", getTerminalWidth());
desc.add_options()
2023-04-07 14:14:39 +00:00
("help", "produce help message")
2024-04-10 10:56:29 +00:00
("config", value<std::string>()->default_value(""), "yaml/xml file containing configuration")
("input-request-log", value<std::string>()->default_value(""), "log of requests that will be replayed")
2024-05-10 12:15:01 +00:00
("setup-nodes-snapshot-path", value<std::string>()->default_value(""), "directory containing snapshots with starting state")
2024-04-10 10:56:29 +00:00
("concurrency,c", value<unsigned>(), "number of parallel queries")
("report-delay,d", value<double>(), "delay between intermediate reports in seconds (set 0 to disable reports)")
("iterations,i", value<size_t>(), "amount of queries to be executed")
("time-limit,t", value<double>(), "stop launch of queries after specified time limit")
("hosts,h", value<Strings>()->multitoken()->default_value(Strings{}, ""), "")
2021-04-12 15:40:42 +00:00
("continue_on_errors", "continue testing even if a query fails")
;
boost::program_options::variables_map options;
boost::program_options::store(boost::program_options::parse_command_line(argc, argv, desc), options);
boost::program_options::notify(options);
if (options.count("help"))
{
std::cout << "Usage: " << argv[0] << " [options] < queries.txt\n";
std::cout << desc << "\n";
return 1;
}
2023-04-07 14:14:39 +00:00
Runner runner(valueToOptional<unsigned>(options["concurrency"]),
options["config"].as<std::string>(),
2024-04-10 10:56:29 +00:00
options["input-request-log"].as<std::string>(),
2024-05-10 12:15:01 +00:00
options["setup-nodes-snapshot-path"].as<std::string>(),
2023-04-07 14:14:39 +00:00
options["hosts"].as<Strings>(),
valueToOptional<double>(options["time-limit"]),
valueToOptional<double>(options["report-delay"]),
options.count("continue_on_errors") ? std::optional<bool>(true) : std::nullopt,
valueToOptional<size_t>(options["iterations"]));
2021-04-12 15:40:42 +00:00
2023-04-07 14:14:39 +00:00
try
{
runner.runBenchmark();
}
2024-04-10 10:56:29 +00:00
catch (...)
2023-04-07 14:14:39 +00:00
{
2024-04-10 10:56:29 +00:00
std::cout << "Got exception while trying to run benchmark: " << DB::getCurrentExceptionMessage(true) << std::endl;
2023-04-07 14:14:39 +00:00
}
2021-04-12 15:40:42 +00:00
return 0;
}
catch (...)
{
std::cerr << DB::getCurrentExceptionMessage(print_stacktrace, true) << std::endl;
return DB::getCurrentExceptionCode();
}
2021-04-12 08:10:23 +00:00
}