#pragma once #include #include "Generator.h" #include #include #include #include #include #include #include #include #include "Stats.h" using Ports = std::vector; using Strings = std::vector; class Runner { public: Runner( size_t concurrency_, const std::string & generator_name, const Strings & hosts_strings_, double max_time_, double delay_, bool continue_on_error_, size_t max_iterations_) : concurrency(concurrency_) , pool(concurrency) , hosts_strings(hosts_strings_) , generator(getGenerator(generator_name)) , max_time(max_time_) , delay(delay_) , continue_on_error(continue_on_error_) , max_iterations(max_iterations_) , info(std::make_shared()) , queue(concurrency) { } void thread(std::vector> zookeepers); void printNumberOfRequestsExecuted(size_t num) { std::cerr << "Requests executed: " << num << ".\n"; } bool tryPushRequestInteractively(const Coordination::ZooKeeperRequestPtr & request, DB::InterruptListener & interrupt_listener); void runBenchmark(); private: size_t concurrency = 1; ThreadPool pool; Strings hosts_strings; std::unique_ptr generator; double max_time = 0; double delay = 1; bool continue_on_error = false; std::atomic max_iterations = 0; std::atomic requests_executed = 0; std::atomic shutdown = false; std::shared_ptr info; Stopwatch total_watch; Stopwatch delay_watch; std::mutex mutex; using Queue = ConcurrentBoundedQueue; Queue queue; std::vector> getConnections(); };