ClickHouse/utils/keeper-bench/Runner.h

80 lines
2.1 KiB
C++
Raw Normal View History

2021-04-12 08:10:23 +00:00
#pragma once
#include <Common/ZooKeeper/ZooKeeperImpl.h>
#include "Generator.h"
#include <Common/ZooKeeper/IKeeper.h>
#include <Common/ZooKeeper/ZooKeeperCommon.h>
#include <Common/Stopwatch.h>
#include <Common/ThreadPool.h>
#include <pcg-random/pcg_random.hpp>
#include <Common/randomSeed.h>
2021-04-12 15:40:42 +00:00
#include <Common/InterruptListener.h>
#include <Core/Types.h>
#include "Stats.h"
2021-04-12 08:10:23 +00:00
using Ports = std::vector<UInt16>;
2021-04-12 15:40:42 +00:00
using Strings = std::vector<std::string>;
2021-04-12 08:10:23 +00:00
class Runner
{
public:
2021-04-12 15:40:42 +00:00
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_)
2021-04-12 08:10:23 +00:00
: concurrency(concurrency_)
, pool(concurrency)
, hosts_strings(hosts_strings_)
2021-04-13 11:55:08 +00:00
, generator(getGenerator(generator_name))
2021-04-12 15:40:42 +00:00
, max_time(max_time_)
, delay(delay_)
2021-04-12 08:10:23 +00:00
, continue_on_error(continue_on_error_)
2021-04-12 15:40:42 +00:00
, max_iterations(max_iterations_)
, info(std::make_shared<Stats>())
2021-04-12 08:10:23 +00:00
, queue(concurrency)
{
}
2021-04-13 11:55:08 +00:00
void thread(std::vector<std::shared_ptr<Coordination::ZooKeeper>> & zookeepers);
2021-04-12 08:10:23 +00:00
2021-04-12 15:40:42 +00:00
void printNumberOfRequestsExecuted(size_t num)
{
std::cerr << "Requests executed: " << num << ".\n";
}
2021-04-13 11:55:08 +00:00
bool tryPushRequestInteractively(const Coordination::ZooKeeperRequestPtr & request, DB::InterruptListener & interrupt_listener);
2021-04-12 15:40:42 +00:00
2021-04-13 11:55:08 +00:00
void runBenchmark();
2021-04-12 08:10:23 +00:00
private:
2021-04-13 07:33:18 +00:00
size_t concurrency = 1;
2021-04-12 08:10:23 +00:00
ThreadPool pool;
Strings hosts_strings;
std::unique_ptr<IGenerator> generator;
2021-04-13 07:33:18 +00:00
double max_time = 0;
double delay = 1;
bool continue_on_error = false;
std::atomic<size_t> max_iterations = 0;
std::atomic<size_t> requests_executed = 0;
std::atomic<bool> shutdown = false;
2021-04-12 08:10:23 +00:00
2021-04-12 15:40:42 +00:00
std::shared_ptr<Stats> info;
Stopwatch total_watch;
Stopwatch delay_watch;
std::mutex mutex;
using Queue = ConcurrentBoundedQueue<Coordination::ZooKeeperRequestPtr>;
2021-04-12 08:10:23 +00:00
Queue queue;
2021-04-13 11:55:08 +00:00
std::vector<std::shared_ptr<Coordination::ZooKeeper>> getConnections();
2021-04-12 08:10:23 +00:00
};