2017-05-07 18:55:42 +00:00
|
|
|
#include <functional>
|
2017-01-13 18:26:51 +00:00
|
|
|
#include <iostream>
|
2017-02-07 16:47:10 +00:00
|
|
|
#include <limits>
|
2017-05-07 18:55:42 +00:00
|
|
|
#include <regex>
|
2017-07-19 15:18:47 +00:00
|
|
|
#include <thread>
|
2018-03-23 16:05:14 +00:00
|
|
|
#include <port/unistd.h>
|
2017-05-05 18:32:38 +00:00
|
|
|
#include <boost/filesystem.hpp>
|
2017-09-06 02:19:52 +00:00
|
|
|
#include <boost/program_options.hpp>
|
2017-05-05 11:36:55 +00:00
|
|
|
#include <sys/stat.h>
|
2017-06-22 13:58:58 +00:00
|
|
|
#include <common/DateLUT.h>
|
2017-05-05 11:36:55 +00:00
|
|
|
#include <AggregateFunctions/ReservoirSampler.h>
|
2017-05-05 12:41:18 +00:00
|
|
|
#include <Client/Connection.h>
|
2017-05-05 11:36:55 +00:00
|
|
|
#include <Common/ConcurrentBoundedQueue.h>
|
|
|
|
#include <Common/Stopwatch.h>
|
2017-06-21 15:51:12 +00:00
|
|
|
#include <Common/getFQDNOrHostName.h>
|
2017-09-06 02:19:52 +00:00
|
|
|
#include <Common/getMultipleKeysFromConfig.h>
|
2017-06-22 13:58:58 +00:00
|
|
|
#include <Common/getNumberOfPhysicalCPUCores.h>
|
2017-05-05 11:36:55 +00:00
|
|
|
#include <Core/Types.h>
|
|
|
|
#include <DataStreams/RemoteBlockInputStream.h>
|
2017-05-06 14:36:37 +00:00
|
|
|
#include <IO/ReadBufferFromFile.h>
|
2017-05-05 11:36:55 +00:00
|
|
|
#include <IO/ReadHelpers.h>
|
2017-05-08 19:25:38 +00:00
|
|
|
#include <IO/WriteBufferFromFile.h>
|
2018-01-10 00:09:22 +00:00
|
|
|
#include <IO/ConnectionTimeouts.h>
|
2018-09-06 18:05:33 +00:00
|
|
|
#include <IO/UseSSL.h>
|
2017-05-05 11:36:55 +00:00
|
|
|
#include <Interpreters/Settings.h>
|
2017-09-06 02:19:52 +00:00
|
|
|
#include <common/ThreadPool.h>
|
2017-06-22 15:57:37 +00:00
|
|
|
#include <common/getMemoryAmount.h>
|
2017-01-20 12:36:16 +00:00
|
|
|
#include <Poco/AutoPtr.h>
|
2017-05-05 11:36:55 +00:00
|
|
|
#include <Poco/Exception.h>
|
2017-01-20 12:36:16 +00:00
|
|
|
#include <Poco/SAX/InputSource.h>
|
|
|
|
#include <Poco/Util/XMLConfiguration.h>
|
2017-05-05 11:36:55 +00:00
|
|
|
#include <Poco/XML/XMLStream.h>
|
2018-11-28 21:21:22 +00:00
|
|
|
#include <Poco/Util/Application.h>
|
2018-06-05 20:09:51 +00:00
|
|
|
#include <Common/InterruptListener.h>
|
2018-11-28 21:21:22 +00:00
|
|
|
#include <Common/Config/configReadClient.h>
|
2017-01-20 12:36:16 +00:00
|
|
|
|
2018-09-01 02:22:30 +00:00
|
|
|
#ifndef __clang__
|
|
|
|
#pragma GCC optimize("-fno-var-tracking-assignments")
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2017-01-13 18:26:51 +00:00
|
|
|
/** Tests launcher for ClickHouse.
|
|
|
|
* The tool walks through given or default folder in order to find files with
|
2017-04-07 19:01:41 +00:00
|
|
|
* tests' descriptions and launches it.
|
2017-01-13 18:26:51 +00:00
|
|
|
*/
|
2017-09-06 02:33:24 +00:00
|
|
|
namespace fs = boost::filesystem;
|
2017-05-30 16:26:37 +00:00
|
|
|
using String = std::string;
|
|
|
|
const String FOUR_SPACES = " ";
|
2017-05-06 14:36:37 +00:00
|
|
|
|
2017-01-13 18:26:51 +00:00
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
namespace ErrorCodes
|
|
|
|
{
|
2017-06-15 19:39:35 +00:00
|
|
|
extern const int NOT_IMPLEMENTED;
|
2018-11-22 21:19:58 +00:00
|
|
|
extern const int LOGICAL_ERROR;
|
|
|
|
extern const int BAD_ARGUMENTS;
|
|
|
|
extern const int FILE_DOESNT_EXIST;
|
2017-01-13 18:26:51 +00:00
|
|
|
}
|
|
|
|
|
2017-09-06 02:19:52 +00:00
|
|
|
static String pad(size_t padding)
|
|
|
|
{
|
2017-05-30 16:26:37 +00:00
|
|
|
return String(padding * 4, ' ');
|
2017-03-13 16:24:50 +00:00
|
|
|
}
|
|
|
|
|
2017-09-07 21:04:48 +00:00
|
|
|
|
|
|
|
/// NOTE The code is totally wrong.
|
2017-05-05 11:36:55 +00:00
|
|
|
class JSONString
|
|
|
|
{
|
|
|
|
private:
|
2017-05-30 16:26:37 +00:00
|
|
|
std::map<String, String> content;
|
|
|
|
size_t padding;
|
2017-05-05 11:36:55 +00:00
|
|
|
|
|
|
|
public:
|
2018-06-03 20:39:06 +00:00
|
|
|
explicit JSONString(size_t padding_ = 1) : padding(padding_) {}
|
2017-03-13 16:24:50 +00:00
|
|
|
|
2017-05-30 16:26:37 +00:00
|
|
|
void set(const String key, String value, bool wrap = true)
|
2017-03-13 16:24:50 +00:00
|
|
|
{
|
2017-05-05 11:36:55 +00:00
|
|
|
if (value.empty())
|
2017-03-13 16:24:50 +00:00
|
|
|
value = "null";
|
|
|
|
|
|
|
|
bool reserved = (value[0] == '[' || value[0] == '{' || value == "null");
|
2017-05-30 16:26:37 +00:00
|
|
|
if (!reserved && wrap)
|
2017-09-06 02:25:01 +00:00
|
|
|
value = '"' + value + '"';
|
2017-03-13 16:24:50 +00:00
|
|
|
|
2017-05-30 16:26:37 +00:00
|
|
|
content[key] = value;
|
2017-03-13 16:24:50 +00:00
|
|
|
}
|
|
|
|
|
2017-05-30 16:26:37 +00:00
|
|
|
template <typename T>
|
2017-12-25 04:01:46 +00:00
|
|
|
std::enable_if_t<std::is_arithmetic_v<T>> set(const String key, T value)
|
2017-03-13 16:24:50 +00:00
|
|
|
{
|
2017-09-06 02:19:52 +00:00
|
|
|
set(key, std::to_string(value), /*wrap= */ false);
|
2017-03-13 16:24:50 +00:00
|
|
|
}
|
|
|
|
|
2017-05-30 16:26:37 +00:00
|
|
|
void set(const String key, const std::vector<JSONString> & run_infos)
|
2017-03-13 16:24:50 +00:00
|
|
|
{
|
2017-05-30 16:26:37 +00:00
|
|
|
String value = "[\n";
|
2017-03-13 16:24:50 +00:00
|
|
|
|
2017-05-05 17:48:11 +00:00
|
|
|
for (size_t i = 0; i < run_infos.size(); ++i)
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
2017-05-30 16:26:37 +00:00
|
|
|
value += pad(padding + 1) + run_infos[i].asString(padding + 2);
|
2017-05-05 17:48:11 +00:00
|
|
|
if (i != run_infos.size() - 1)
|
2017-05-30 16:26:37 +00:00
|
|
|
value += ',';
|
2017-03-13 16:24:50 +00:00
|
|
|
|
2017-05-30 16:26:37 +00:00
|
|
|
value += "\n";
|
2017-03-13 16:24:50 +00:00
|
|
|
}
|
|
|
|
|
2017-05-30 16:26:37 +00:00
|
|
|
value += pad(padding) + ']';
|
|
|
|
content[key] = value;
|
2017-03-13 16:24:50 +00:00
|
|
|
}
|
|
|
|
|
2017-09-06 02:19:52 +00:00
|
|
|
String asString() const
|
|
|
|
{
|
|
|
|
return asString(padding);
|
|
|
|
}
|
2017-05-30 16:26:37 +00:00
|
|
|
String asString(size_t padding) const
|
2017-03-13 16:24:50 +00:00
|
|
|
{
|
2017-05-30 16:26:37 +00:00
|
|
|
String repr = "{";
|
2017-03-13 16:24:50 +00:00
|
|
|
|
2017-05-05 11:36:55 +00:00
|
|
|
for (auto it = content.begin(); it != content.end(); ++it)
|
|
|
|
{
|
2017-05-30 16:26:37 +00:00
|
|
|
if (it != content.begin())
|
|
|
|
repr += ',';
|
|
|
|
/// construct "key": "value" string with padding
|
2017-09-06 02:25:01 +00:00
|
|
|
repr += "\n" + pad(padding) + '"' + it->first + '"' + ": " + it->second;
|
2017-03-13 16:24:50 +00:00
|
|
|
}
|
|
|
|
|
2017-05-30 16:26:37 +00:00
|
|
|
repr += "\n" + pad(padding - 1) + '}';
|
|
|
|
return repr;
|
2017-03-13 16:24:50 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-03-27 18:25:42 +00:00
|
|
|
|
2017-06-21 18:41:50 +00:00
|
|
|
using ConfigurationPtr = Poco::AutoPtr<Poco::Util::AbstractConfiguration>;
|
2017-02-07 16:47:10 +00:00
|
|
|
|
2017-06-21 18:41:50 +00:00
|
|
|
/// A set of supported stop conditions.
|
|
|
|
struct StopConditionsSet
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
2017-06-21 18:41:50 +00:00
|
|
|
void loadFromConfig(const ConfigurationPtr & stop_conditions_view)
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
2017-06-21 18:41:50 +00:00
|
|
|
using Keys = std::vector<String>;
|
2017-05-05 11:36:55 +00:00
|
|
|
Keys keys;
|
2017-06-21 18:41:50 +00:00
|
|
|
stop_conditions_view->keys(keys);
|
2017-05-05 11:36:55 +00:00
|
|
|
|
2017-05-30 16:26:37 +00:00
|
|
|
for (const String & key : keys)
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
2017-06-21 14:55:09 +00:00
|
|
|
if (key == "total_time_ms")
|
2017-06-21 18:41:50 +00:00
|
|
|
total_time_ms.value = stop_conditions_view->getUInt64(key);
|
2017-05-05 11:36:55 +00:00
|
|
|
else if (key == "rows_read")
|
2017-06-21 18:41:50 +00:00
|
|
|
rows_read.value = stop_conditions_view->getUInt64(key);
|
2017-05-05 11:36:55 +00:00
|
|
|
else if (key == "bytes_read_uncompressed")
|
2017-06-21 18:41:50 +00:00
|
|
|
bytes_read_uncompressed.value = stop_conditions_view->getUInt64(key);
|
2017-05-05 11:36:55 +00:00
|
|
|
else if (key == "iterations")
|
2017-06-21 18:41:50 +00:00
|
|
|
iterations.value = stop_conditions_view->getUInt64(key);
|
2017-05-05 11:36:55 +00:00
|
|
|
else if (key == "min_time_not_changing_for_ms")
|
2017-06-21 18:41:50 +00:00
|
|
|
min_time_not_changing_for_ms.value = stop_conditions_view->getUInt64(key);
|
2017-05-05 11:36:55 +00:00
|
|
|
else if (key == "max_speed_not_changing_for_ms")
|
2017-06-21 18:41:50 +00:00
|
|
|
max_speed_not_changing_for_ms.value = stop_conditions_view->getUInt64(key);
|
2017-05-05 11:36:55 +00:00
|
|
|
else if (key == "average_speed_not_changing_for_ms")
|
2017-06-21 18:41:50 +00:00
|
|
|
average_speed_not_changing_for_ms.value = stop_conditions_view->getUInt64(key);
|
2017-05-05 11:36:55 +00:00
|
|
|
else
|
2018-11-22 21:19:58 +00:00
|
|
|
throw DB::Exception("Met unkown stop condition: " + key, DB::ErrorCodes::LOGICAL_ERROR);
|
2017-05-05 11:36:55 +00:00
|
|
|
|
2017-06-21 18:41:50 +00:00
|
|
|
++initialized_count;
|
2017-05-05 11:36:55 +00:00
|
|
|
}
|
|
|
|
}
|
2017-02-07 16:47:10 +00:00
|
|
|
|
2017-06-21 18:41:50 +00:00
|
|
|
void reset()
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
2017-06-21 18:41:50 +00:00
|
|
|
total_time_ms.fulfilled = false;
|
|
|
|
rows_read.fulfilled = false;
|
|
|
|
bytes_read_uncompressed.fulfilled = false;
|
|
|
|
iterations.fulfilled = false;
|
|
|
|
min_time_not_changing_for_ms.fulfilled = false;
|
|
|
|
max_speed_not_changing_for_ms.fulfilled = false;
|
|
|
|
average_speed_not_changing_for_ms.fulfilled = false;
|
|
|
|
|
|
|
|
fulfilled_count = 0;
|
2017-05-05 11:36:55 +00:00
|
|
|
}
|
|
|
|
|
2017-06-21 18:41:50 +00:00
|
|
|
/// Note: only conditions with UInt64 minimal thresholds are supported.
|
|
|
|
/// I.e. condition is fulfilled when value is exceeded.
|
|
|
|
struct StopCondition
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
2017-06-21 18:41:50 +00:00
|
|
|
UInt64 value = 0;
|
|
|
|
bool fulfilled = false;
|
|
|
|
};
|
2017-05-05 11:36:55 +00:00
|
|
|
|
2017-06-21 18:41:50 +00:00
|
|
|
void report(UInt64 value, StopCondition & condition)
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
2017-06-21 18:41:50 +00:00
|
|
|
if (condition.value && !condition.fulfilled && value >= condition.value)
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
2017-06-21 18:41:50 +00:00
|
|
|
condition.fulfilled = true;
|
|
|
|
++fulfilled_count;
|
2017-05-05 11:36:55 +00:00
|
|
|
}
|
2017-06-21 18:41:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
StopCondition total_time_ms;
|
|
|
|
StopCondition rows_read;
|
|
|
|
StopCondition bytes_read_uncompressed;
|
|
|
|
StopCondition iterations;
|
|
|
|
StopCondition min_time_not_changing_for_ms;
|
|
|
|
StopCondition max_speed_not_changing_for_ms;
|
|
|
|
StopCondition average_speed_not_changing_for_ms;
|
2017-05-05 11:36:55 +00:00
|
|
|
|
2017-06-21 18:41:50 +00:00
|
|
|
size_t initialized_count = 0;
|
|
|
|
size_t fulfilled_count = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
/// Stop conditions for a test run. The running test will be terminated in either of two conditions:
|
|
|
|
/// 1. All conditions marked 'all_of' are fulfilled
|
|
|
|
/// or
|
|
|
|
/// 2. Any condition marked 'any_of' is fulfilled
|
|
|
|
class TestStopConditions
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
void loadFromConfig(ConfigurationPtr & stop_conditions_config)
|
|
|
|
{
|
|
|
|
if (stop_conditions_config->has("all_of"))
|
|
|
|
{
|
|
|
|
ConfigurationPtr config_all_of(stop_conditions_config->createView("all_of"));
|
|
|
|
conditions_all_of.loadFromConfig(config_all_of);
|
|
|
|
}
|
|
|
|
if (stop_conditions_config->has("any_of"))
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
2017-06-21 18:41:50 +00:00
|
|
|
ConfigurationPtr config_any_of(stop_conditions_config->createView("any_of"));
|
|
|
|
conditions_any_of.loadFromConfig(config_any_of);
|
2017-05-05 11:36:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-21 18:41:50 +00:00
|
|
|
bool empty() const
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
2017-06-21 18:41:50 +00:00
|
|
|
return !conditions_all_of.initialized_count && !conditions_any_of.initialized_count;
|
|
|
|
}
|
|
|
|
|
2017-09-06 02:19:52 +00:00
|
|
|
#define DEFINE_REPORT_FUNC(FUNC_NAME, CONDITION) \
|
|
|
|
void FUNC_NAME(UInt64 value) \
|
|
|
|
{ \
|
|
|
|
conditions_all_of.report(value, conditions_all_of.CONDITION); \
|
|
|
|
conditions_any_of.report(value, conditions_any_of.CONDITION); \
|
|
|
|
}
|
2017-06-21 18:41:50 +00:00
|
|
|
|
2018-06-03 20:39:06 +00:00
|
|
|
DEFINE_REPORT_FUNC(reportTotalTime, total_time_ms)
|
|
|
|
DEFINE_REPORT_FUNC(reportRowsRead, rows_read)
|
|
|
|
DEFINE_REPORT_FUNC(reportBytesReadUncompressed, bytes_read_uncompressed)
|
|
|
|
DEFINE_REPORT_FUNC(reportIterations, iterations)
|
|
|
|
DEFINE_REPORT_FUNC(reportMinTimeNotChangingFor, min_time_not_changing_for_ms)
|
|
|
|
DEFINE_REPORT_FUNC(reportMaxSpeedNotChangingFor, max_speed_not_changing_for_ms)
|
|
|
|
DEFINE_REPORT_FUNC(reportAverageSpeedNotChangingFor, average_speed_not_changing_for_ms)
|
2017-05-05 11:36:55 +00:00
|
|
|
|
2017-06-21 18:41:50 +00:00
|
|
|
#undef REPORT
|
|
|
|
|
|
|
|
bool areFulfilled() const
|
|
|
|
{
|
2017-09-06 02:19:52 +00:00
|
|
|
return (conditions_all_of.initialized_count && conditions_all_of.fulfilled_count >= conditions_all_of.initialized_count)
|
2017-06-21 18:41:50 +00:00
|
|
|
|| (conditions_any_of.initialized_count && conditions_any_of.fulfilled_count);
|
|
|
|
}
|
|
|
|
|
|
|
|
void reset()
|
|
|
|
{
|
|
|
|
conditions_all_of.reset();
|
|
|
|
conditions_any_of.reset();
|
2017-05-05 11:36:55 +00:00
|
|
|
}
|
|
|
|
|
2017-06-21 18:41:50 +00:00
|
|
|
private:
|
|
|
|
StopConditionsSet conditions_all_of;
|
|
|
|
StopConditionsSet conditions_any_of;
|
2017-02-07 16:47:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct Stats
|
|
|
|
{
|
2017-05-05 11:36:55 +00:00
|
|
|
Stopwatch watch;
|
|
|
|
Stopwatch watch_per_query;
|
|
|
|
Stopwatch min_time_watch;
|
|
|
|
Stopwatch max_rows_speed_watch;
|
|
|
|
Stopwatch max_bytes_speed_watch;
|
|
|
|
Stopwatch avg_rows_speed_watch;
|
|
|
|
Stopwatch avg_bytes_speed_watch;
|
2017-06-21 16:47:16 +00:00
|
|
|
|
|
|
|
bool last_query_was_cancelled = false;
|
|
|
|
|
2017-07-11 18:08:02 +00:00
|
|
|
size_t queries = 0;
|
|
|
|
|
|
|
|
size_t total_rows_read = 0;
|
|
|
|
size_t total_bytes_read = 0;
|
|
|
|
|
|
|
|
size_t last_query_rows_read = 0;
|
|
|
|
size_t last_query_bytes_read = 0;
|
2017-05-05 11:36:55 +00:00
|
|
|
|
|
|
|
using Sampler = ReservoirSampler<double>;
|
|
|
|
Sampler sampler{1 << 16};
|
|
|
|
|
|
|
|
/// min_time in ms
|
|
|
|
UInt64 min_time = std::numeric_limits<UInt64>::max();
|
|
|
|
double total_time = 0;
|
|
|
|
|
|
|
|
double max_rows_speed = 0;
|
|
|
|
double max_bytes_speed = 0;
|
|
|
|
|
|
|
|
double avg_rows_speed_value = 0;
|
|
|
|
double avg_rows_speed_first = 0;
|
|
|
|
static double avg_rows_speed_precision;
|
|
|
|
|
|
|
|
double avg_bytes_speed_value = 0;
|
|
|
|
double avg_bytes_speed_first = 0;
|
|
|
|
static double avg_bytes_speed_precision;
|
|
|
|
|
|
|
|
size_t number_of_rows_speed_info_batches = 0;
|
|
|
|
size_t number_of_bytes_speed_info_batches = 0;
|
|
|
|
|
2017-05-05 12:41:18 +00:00
|
|
|
bool ready = false; // check if a query wasn't interrupted by SIGINT
|
2017-11-16 18:03:31 +00:00
|
|
|
String exception;
|
2017-05-05 11:36:55 +00:00
|
|
|
|
2017-05-30 16:26:37 +00:00
|
|
|
String getStatisticByName(const String & statistic_name)
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
2017-05-05 17:48:11 +00:00
|
|
|
if (statistic_name == "min_time")
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
|
|
|
return std::to_string(min_time) + "ms";
|
|
|
|
}
|
2017-05-05 17:48:11 +00:00
|
|
|
if (statistic_name == "quantiles")
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
2017-05-30 16:26:37 +00:00
|
|
|
String result = "\n";
|
2017-05-05 11:36:55 +00:00
|
|
|
|
|
|
|
for (double percent = 10; percent <= 90; percent += 10)
|
|
|
|
{
|
2017-05-05 17:48:11 +00:00
|
|
|
result += FOUR_SPACES + std::to_string((percent / 100));
|
2017-05-05 11:36:55 +00:00
|
|
|
result += ": " + std::to_string(sampler.quantileInterpolated(percent / 100.0));
|
|
|
|
result += "\n";
|
|
|
|
}
|
2017-05-05 17:48:11 +00:00
|
|
|
result += FOUR_SPACES + "0.95: " + std::to_string(sampler.quantileInterpolated(95 / 100.0)) + "\n";
|
2017-09-06 02:19:52 +00:00
|
|
|
result += FOUR_SPACES + "0.99: " + std::to_string(sampler.quantileInterpolated(99 / 100.0)) + "\n";
|
|
|
|
result += FOUR_SPACES + "0.999: " + std::to_string(sampler.quantileInterpolated(99.9 / 100.)) + "\n";
|
2017-05-05 17:48:11 +00:00
|
|
|
result += FOUR_SPACES + "0.9999: " + std::to_string(sampler.quantileInterpolated(99.99 / 100.));
|
2017-05-05 11:36:55 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
2017-05-05 17:48:11 +00:00
|
|
|
if (statistic_name == "total_time")
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
|
|
|
return std::to_string(total_time) + "s";
|
|
|
|
}
|
2017-05-05 17:48:11 +00:00
|
|
|
if (statistic_name == "queries_per_second")
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
|
|
|
return std::to_string(queries / total_time);
|
|
|
|
}
|
2017-05-05 17:48:11 +00:00
|
|
|
if (statistic_name == "rows_per_second")
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
2017-07-11 18:08:02 +00:00
|
|
|
return std::to_string(total_rows_read / total_time);
|
2017-05-05 11:36:55 +00:00
|
|
|
}
|
2017-05-05 17:48:11 +00:00
|
|
|
if (statistic_name == "bytes_per_second")
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
2017-07-11 18:08:02 +00:00
|
|
|
return std::to_string(total_bytes_read / total_time);
|
2017-05-05 11:36:55 +00:00
|
|
|
}
|
|
|
|
|
2017-05-05 17:48:11 +00:00
|
|
|
if (statistic_name == "max_rows_per_second")
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
|
|
|
return std::to_string(max_rows_speed);
|
|
|
|
}
|
2017-05-05 17:48:11 +00:00
|
|
|
if (statistic_name == "max_bytes_per_second")
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
|
|
|
return std::to_string(max_bytes_speed);
|
|
|
|
}
|
2017-05-05 17:48:11 +00:00
|
|
|
if (statistic_name == "avg_rows_per_second")
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
|
|
|
return std::to_string(avg_rows_speed_value);
|
|
|
|
}
|
2017-05-05 17:48:11 +00:00
|
|
|
if (statistic_name == "avg_bytes_per_second")
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
|
|
|
return std::to_string(avg_bytes_speed_value);
|
|
|
|
}
|
|
|
|
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
void update_min_time(const UInt64 min_time_candidate)
|
|
|
|
{
|
|
|
|
if (min_time_candidate < min_time)
|
|
|
|
{
|
|
|
|
min_time = min_time_candidate;
|
|
|
|
min_time_watch.restart();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void update_average_speed(const double new_speed_info,
|
|
|
|
Stopwatch & avg_speed_watch,
|
|
|
|
size_t & number_of_info_batches,
|
|
|
|
double precision,
|
|
|
|
double & avg_speed_first,
|
|
|
|
double & avg_speed_value)
|
|
|
|
{
|
|
|
|
avg_speed_value = ((avg_speed_value * number_of_info_batches) + new_speed_info);
|
2017-09-06 02:25:01 +00:00
|
|
|
++number_of_info_batches;
|
|
|
|
avg_speed_value /= number_of_info_batches;
|
2017-05-05 11:36:55 +00:00
|
|
|
|
|
|
|
if (avg_speed_first == 0)
|
|
|
|
{
|
|
|
|
avg_speed_first = avg_speed_value;
|
|
|
|
}
|
|
|
|
|
2017-10-04 00:05:50 +00:00
|
|
|
if (std::abs(avg_speed_value - avg_speed_first) >= precision)
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
|
|
|
avg_speed_first = avg_speed_value;
|
|
|
|
avg_speed_watch.restart();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void update_max_speed(const size_t max_speed_candidate, Stopwatch & max_speed_watch, double & max_speed)
|
|
|
|
{
|
|
|
|
if (max_speed_candidate > max_speed)
|
|
|
|
{
|
|
|
|
max_speed = max_speed_candidate;
|
|
|
|
max_speed_watch.restart();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void add(size_t rows_read_inc, size_t bytes_read_inc)
|
|
|
|
{
|
2017-07-11 18:08:02 +00:00
|
|
|
total_rows_read += rows_read_inc;
|
|
|
|
total_bytes_read += bytes_read_inc;
|
|
|
|
last_query_rows_read += rows_read_inc;
|
|
|
|
last_query_bytes_read += bytes_read_inc;
|
2017-05-05 11:36:55 +00:00
|
|
|
|
2017-07-11 18:08:02 +00:00
|
|
|
double new_rows_speed = last_query_rows_read / watch_per_query.elapsedSeconds();
|
|
|
|
double new_bytes_speed = last_query_bytes_read / watch_per_query.elapsedSeconds();
|
2017-05-05 11:36:55 +00:00
|
|
|
|
|
|
|
/// Update rows speed
|
|
|
|
update_max_speed(new_rows_speed, max_rows_speed_watch, max_rows_speed);
|
|
|
|
update_average_speed(new_rows_speed,
|
|
|
|
avg_rows_speed_watch,
|
|
|
|
number_of_rows_speed_info_batches,
|
|
|
|
avg_rows_speed_precision,
|
|
|
|
avg_rows_speed_first,
|
|
|
|
avg_rows_speed_value);
|
|
|
|
/// Update bytes speed
|
|
|
|
update_max_speed(new_bytes_speed, max_bytes_speed_watch, max_bytes_speed);
|
|
|
|
update_average_speed(new_bytes_speed,
|
|
|
|
avg_bytes_speed_watch,
|
|
|
|
number_of_bytes_speed_info_batches,
|
|
|
|
avg_bytes_speed_precision,
|
|
|
|
avg_bytes_speed_first,
|
|
|
|
avg_bytes_speed_value);
|
|
|
|
}
|
|
|
|
|
|
|
|
void updateQueryInfo()
|
|
|
|
{
|
|
|
|
++queries;
|
|
|
|
sampler.insert(watch_per_query.elapsedSeconds());
|
|
|
|
update_min_time(watch_per_query.elapsed() / (1000 * 1000)); /// ns to ms
|
|
|
|
}
|
|
|
|
|
|
|
|
void setTotalTime()
|
|
|
|
{
|
|
|
|
total_time = watch.elapsedSeconds();
|
|
|
|
}
|
|
|
|
|
|
|
|
void clear()
|
|
|
|
{
|
|
|
|
watch.restart();
|
|
|
|
watch_per_query.restart();
|
|
|
|
min_time_watch.restart();
|
|
|
|
max_rows_speed_watch.restart();
|
|
|
|
max_bytes_speed_watch.restart();
|
|
|
|
avg_rows_speed_watch.restart();
|
|
|
|
avg_bytes_speed_watch.restart();
|
|
|
|
|
2017-06-21 16:47:16 +00:00
|
|
|
last_query_was_cancelled = false;
|
|
|
|
|
2017-05-05 11:36:55 +00:00
|
|
|
sampler.clear();
|
|
|
|
|
|
|
|
queries = 0;
|
2017-07-11 18:08:02 +00:00
|
|
|
total_rows_read = 0;
|
|
|
|
total_bytes_read = 0;
|
|
|
|
last_query_rows_read = 0;
|
|
|
|
last_query_bytes_read = 0;
|
2017-05-05 11:36:55 +00:00
|
|
|
|
|
|
|
min_time = std::numeric_limits<UInt64>::max();
|
|
|
|
total_time = 0;
|
|
|
|
max_rows_speed = 0;
|
|
|
|
max_bytes_speed = 0;
|
|
|
|
avg_rows_speed_value = 0;
|
|
|
|
avg_bytes_speed_value = 0;
|
|
|
|
avg_rows_speed_first = 0;
|
|
|
|
avg_bytes_speed_first = 0;
|
|
|
|
avg_rows_speed_precision = 0.001;
|
|
|
|
avg_bytes_speed_precision = 0.001;
|
|
|
|
number_of_rows_speed_info_batches = 0;
|
|
|
|
number_of_bytes_speed_info_batches = 0;
|
|
|
|
}
|
2017-02-07 16:47:10 +00:00
|
|
|
};
|
|
|
|
|
2017-09-06 02:19:52 +00:00
|
|
|
double Stats::avg_rows_speed_precision = 0.001;
|
2017-03-27 18:25:42 +00:00
|
|
|
double Stats::avg_bytes_speed_precision = 0.001;
|
|
|
|
|
2018-11-28 21:21:22 +00:00
|
|
|
class PerformanceTest : public Poco::Util::Application
|
2017-01-13 18:26:51 +00:00
|
|
|
{
|
|
|
|
public:
|
2017-05-30 16:26:37 +00:00
|
|
|
using Strings = std::vector<String>;
|
2017-05-07 18:55:42 +00:00
|
|
|
|
2017-09-06 02:19:52 +00:00
|
|
|
PerformanceTest(const String & host_,
|
2017-05-05 11:36:55 +00:00
|
|
|
const UInt16 port_,
|
2018-11-28 15:27:23 +00:00
|
|
|
const bool secure_,
|
2017-05-05 11:36:55 +00:00
|
|
|
const String & default_database_,
|
|
|
|
const String & user_,
|
|
|
|
const String & password_,
|
2018-11-28 15:27:23 +00:00
|
|
|
const bool lite_output_,
|
2017-05-30 16:26:37 +00:00
|
|
|
const String & profiles_file_,
|
2017-05-07 18:55:42 +00:00
|
|
|
Strings && input_files_,
|
|
|
|
Strings && tests_tags_,
|
|
|
|
Strings && skip_tags_,
|
|
|
|
Strings && tests_names_,
|
|
|
|
Strings && skip_names_,
|
|
|
|
Strings && tests_names_regexp_,
|
2018-01-10 00:09:22 +00:00
|
|
|
Strings && skip_names_regexp_,
|
|
|
|
const ConnectionTimeouts & timeouts)
|
2018-11-28 12:19:01 +00:00
|
|
|
: connection(host_, port_, default_database_, user_, password_, timeouts, "performance-test", Protocol::Compression::Enable, secure_ ? Protocol::Secure::Enable : Protocol::Secure::Disable),
|
2017-05-05 15:58:25 +00:00
|
|
|
gotSIGINT(false),
|
2017-05-07 00:29:30 +00:00
|
|
|
lite_output(lite_output_),
|
2017-05-07 18:55:42 +00:00
|
|
|
profiles_file(profiles_file_),
|
|
|
|
input_files(input_files_),
|
|
|
|
tests_tags(std::move(tests_tags_)),
|
|
|
|
skip_tags(std::move(skip_tags_)),
|
|
|
|
tests_names(std::move(tests_names_)),
|
|
|
|
skip_names(std::move(skip_names_)),
|
|
|
|
tests_names_regexp(std::move(tests_names_regexp_)),
|
2018-01-10 00:15:08 +00:00
|
|
|
skip_names_regexp(std::move(skip_names_regexp_))
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
|
|
|
if (input_files.size() < 1)
|
|
|
|
{
|
2018-11-22 21:19:58 +00:00
|
|
|
throw DB::Exception("No tests were specified", DB::ErrorCodes::BAD_ARGUMENTS);
|
2017-05-05 11:36:55 +00:00
|
|
|
}
|
2018-11-28 21:21:22 +00:00
|
|
|
}
|
|
|
|
|
2018-11-29 08:23:27 +00:00
|
|
|
void initialize(Poco::Util::Application & self [[maybe_unused]])
|
2018-11-28 21:21:22 +00:00
|
|
|
{
|
|
|
|
std::string home_path;
|
|
|
|
const char * home_path_cstr = getenv("HOME");
|
|
|
|
if (home_path_cstr)
|
|
|
|
home_path = home_path_cstr;
|
|
|
|
configReadClient(Poco::Util::Application::instance().config(), home_path);
|
|
|
|
}
|
2017-05-05 11:36:55 +00:00
|
|
|
|
2018-11-28 21:21:22 +00:00
|
|
|
int main(const std::vector < std::string > & /* args */)
|
|
|
|
{
|
2017-06-21 15:51:12 +00:00
|
|
|
std::string name;
|
|
|
|
UInt64 version_major;
|
|
|
|
UInt64 version_minor;
|
2018-07-31 21:36:18 +00:00
|
|
|
UInt64 version_patch;
|
2017-06-21 15:51:12 +00:00
|
|
|
UInt64 version_revision;
|
2018-07-31 21:36:18 +00:00
|
|
|
connection.getServerVersion(name, version_major, version_minor, version_patch, version_revision);
|
2017-06-21 15:51:12 +00:00
|
|
|
|
|
|
|
std::stringstream ss;
|
2018-07-31 21:36:18 +00:00
|
|
|
ss << version_major << "." << version_minor << "." << version_patch;
|
2017-06-21 15:51:12 +00:00
|
|
|
server_version = ss.str();
|
|
|
|
|
2017-05-07 18:55:42 +00:00
|
|
|
processTestsConfigurations(input_files);
|
2018-11-29 07:58:59 +00:00
|
|
|
|
|
|
|
return 0;
|
2017-05-05 11:36:55 +00:00
|
|
|
}
|
2017-01-13 18:26:51 +00:00
|
|
|
|
|
|
|
private:
|
2017-05-30 16:26:37 +00:00
|
|
|
String test_name;
|
2017-05-05 11:36:55 +00:00
|
|
|
|
2017-05-30 16:26:37 +00:00
|
|
|
using Query = String;
|
2017-05-05 11:36:55 +00:00
|
|
|
using Queries = std::vector<Query>;
|
|
|
|
using QueriesWithIndexes = std::vector<std::pair<Query, size_t>>;
|
|
|
|
Queries queries;
|
|
|
|
|
2017-05-05 12:41:18 +00:00
|
|
|
Connection connection;
|
2017-06-21 15:51:12 +00:00
|
|
|
std::string server_version;
|
2017-05-05 11:36:55 +00:00
|
|
|
|
2017-05-30 16:26:37 +00:00
|
|
|
using Keys = std::vector<String>;
|
2017-05-05 11:36:55 +00:00
|
|
|
|
|
|
|
Settings settings;
|
2017-06-19 20:31:23 +00:00
|
|
|
Context global_context = Context::createGlobal();
|
2017-05-05 11:36:55 +00:00
|
|
|
|
|
|
|
InterruptListener interrupt_listener;
|
|
|
|
|
|
|
|
using XMLConfiguration = Poco::Util::XMLConfiguration;
|
2017-06-21 18:41:50 +00:00
|
|
|
using XMLConfigurationPtr = Poco::AutoPtr<XMLConfiguration>;
|
2017-05-07 18:55:42 +00:00
|
|
|
|
2017-05-30 16:26:37 +00:00
|
|
|
using Paths = std::vector<String>;
|
|
|
|
using StringToVector = std::map<String, std::vector<String>>;
|
2017-05-05 11:36:55 +00:00
|
|
|
StringToVector substitutions;
|
|
|
|
|
2017-05-30 16:26:37 +00:00
|
|
|
using StringKeyValue = std::map<String, String>;
|
2017-05-05 17:48:11 +00:00
|
|
|
std::vector<StringKeyValue> substitutions_maps;
|
2017-05-05 11:36:55 +00:00
|
|
|
|
2017-05-05 12:41:18 +00:00
|
|
|
bool gotSIGINT;
|
2017-06-21 18:41:50 +00:00
|
|
|
std::vector<TestStopConditions> stop_conditions_by_run;
|
2017-05-30 16:26:37 +00:00
|
|
|
String main_metric;
|
2017-05-05 15:58:25 +00:00
|
|
|
bool lite_output;
|
2017-05-30 16:26:37 +00:00
|
|
|
String profiles_file;
|
2017-05-05 11:36:55 +00:00
|
|
|
|
2017-05-07 18:55:42 +00:00
|
|
|
Strings input_files;
|
2017-06-21 18:41:50 +00:00
|
|
|
std::vector<XMLConfigurationPtr> tests_configurations;
|
2017-05-07 18:55:42 +00:00
|
|
|
|
|
|
|
Strings tests_tags;
|
|
|
|
Strings skip_tags;
|
|
|
|
Strings tests_names;
|
|
|
|
Strings skip_names;
|
|
|
|
Strings tests_names_regexp;
|
|
|
|
Strings skip_names_regexp;
|
|
|
|
|
2017-05-30 16:26:37 +00:00
|
|
|
enum class ExecutionType
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
2017-05-30 16:26:37 +00:00
|
|
|
Loop,
|
|
|
|
Once
|
2017-05-05 11:36:55 +00:00
|
|
|
};
|
2017-05-05 17:48:11 +00:00
|
|
|
ExecutionType exec_type;
|
2017-05-05 11:36:55 +00:00
|
|
|
|
2017-05-30 16:26:37 +00:00
|
|
|
enum class FilterType
|
2017-05-07 18:55:42 +00:00
|
|
|
{
|
2017-05-30 16:26:37 +00:00
|
|
|
Tag,
|
|
|
|
Name,
|
|
|
|
Name_regexp
|
2017-05-07 18:55:42 +00:00
|
|
|
};
|
|
|
|
|
2017-05-05 16:49:14 +00:00
|
|
|
size_t times_to_run = 1;
|
2017-06-21 14:19:05 +00:00
|
|
|
std::vector<Stats> statistics_by_run;
|
2017-05-05 11:36:55 +00:00
|
|
|
|
2017-05-07 18:55:42 +00:00
|
|
|
/// Removes configurations that has a given value. If leave is true, the logic is reversed.
|
2017-06-21 18:41:50 +00:00
|
|
|
void removeConfigurationsIf(
|
2017-09-06 02:19:52 +00:00
|
|
|
std::vector<XMLConfigurationPtr> & configs, FilterType filter_type, const Strings & values, bool leave = false)
|
2017-05-07 18:55:42 +00:00
|
|
|
{
|
2018-01-10 00:04:08 +00:00
|
|
|
auto checker = [&filter_type, &values, &leave](XMLConfigurationPtr & config)
|
|
|
|
{
|
2017-05-07 18:55:42 +00:00
|
|
|
if (values.size() == 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
bool remove_or_not = false;
|
|
|
|
|
2017-05-30 16:26:37 +00:00
|
|
|
if (filter_type == FilterType::Tag)
|
2017-05-07 18:55:42 +00:00
|
|
|
{
|
|
|
|
Keys tags_keys;
|
|
|
|
config->keys("tags", tags_keys);
|
|
|
|
|
|
|
|
Strings tags(tags_keys.size());
|
|
|
|
for (size_t i = 0; i != tags_keys.size(); ++i)
|
|
|
|
tags[i] = config->getString("tags.tag[" + std::to_string(i) + "]");
|
|
|
|
|
2017-09-06 02:19:52 +00:00
|
|
|
for (const String & config_tag : tags)
|
|
|
|
{
|
2017-05-07 18:55:42 +00:00
|
|
|
if (std::find(values.begin(), values.end(), config_tag) != values.end())
|
|
|
|
remove_or_not = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-30 16:26:37 +00:00
|
|
|
if (filter_type == FilterType::Name)
|
2017-05-07 18:55:42 +00:00
|
|
|
{
|
|
|
|
remove_or_not = (std::find(values.begin(), values.end(), config->getString("name", "")) != values.end());
|
|
|
|
}
|
|
|
|
|
2017-05-30 16:26:37 +00:00
|
|
|
if (filter_type == FilterType::Name_regexp)
|
2017-05-07 18:55:42 +00:00
|
|
|
{
|
2017-05-30 16:26:37 +00:00
|
|
|
String config_name = config->getString("name", "");
|
2018-01-10 00:04:08 +00:00
|
|
|
auto regex_checker = [&config_name](const String & name_regexp)
|
|
|
|
{
|
2017-05-07 18:55:42 +00:00
|
|
|
std::regex pattern(name_regexp);
|
|
|
|
return std::regex_search(config_name, pattern);
|
|
|
|
};
|
|
|
|
|
2017-09-06 02:19:52 +00:00
|
|
|
remove_or_not = config->has("name") ? (std::find_if(values.begin(), values.end(), regex_checker) != values.end()) : false;
|
2017-05-07 18:55:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (leave)
|
|
|
|
remove_or_not = !remove_or_not;
|
|
|
|
return remove_or_not;
|
|
|
|
};
|
|
|
|
|
2017-06-21 18:41:50 +00:00
|
|
|
auto new_end = std::remove_if(configs.begin(), configs.end(), checker);
|
2017-05-07 18:55:42 +00:00
|
|
|
configs.erase(new_end, configs.end());
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Filter tests by tags, names, regexp matching, etc.
|
|
|
|
void filterConfigurations()
|
|
|
|
{
|
|
|
|
/// Leave tests:
|
2017-05-30 16:26:37 +00:00
|
|
|
removeConfigurationsIf(tests_configurations, FilterType::Tag, tests_tags, true);
|
|
|
|
removeConfigurationsIf(tests_configurations, FilterType::Name, tests_names, true);
|
|
|
|
removeConfigurationsIf(tests_configurations, FilterType::Name_regexp, tests_names_regexp, true);
|
2017-05-07 18:55:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
/// Skip tests
|
2017-05-30 16:26:37 +00:00
|
|
|
removeConfigurationsIf(tests_configurations, FilterType::Tag, skip_tags, false);
|
|
|
|
removeConfigurationsIf(tests_configurations, FilterType::Name, skip_names, false);
|
|
|
|
removeConfigurationsIf(tests_configurations, FilterType::Name_regexp, skip_names_regexp, false);
|
2017-05-07 18:55:42 +00:00
|
|
|
}
|
|
|
|
|
2017-05-08 19:25:38 +00:00
|
|
|
/// Checks specified preconditions per test (process cache, table existence, etc.)
|
2017-06-21 18:41:50 +00:00
|
|
|
bool checkPreconditions(const XMLConfigurationPtr & config)
|
2017-05-08 19:25:38 +00:00
|
|
|
{
|
|
|
|
if (!config->has("preconditions"))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
Keys preconditions;
|
|
|
|
config->keys("preconditions", preconditions);
|
|
|
|
size_t table_precondition_index = 0;
|
|
|
|
|
2017-05-30 16:26:37 +00:00
|
|
|
for (const String & precondition : preconditions)
|
2017-05-08 19:25:38 +00:00
|
|
|
{
|
2017-06-21 14:55:09 +00:00
|
|
|
if (precondition == "flush_disk_cache")
|
2017-09-06 02:25:01 +00:00
|
|
|
{
|
2017-09-06 02:19:52 +00:00
|
|
|
if (system(
|
|
|
|
"(>&2 echo 'Flushing disk cache...') && (sudo sh -c 'echo 3 > /proc/sys/vm/drop_caches') && (>&2 echo 'Flushed.')"))
|
2017-06-22 15:57:37 +00:00
|
|
|
{
|
2017-06-21 14:55:09 +00:00
|
|
|
std::cerr << "Failed to flush disk cache" << std::endl;
|
2017-05-30 16:26:37 +00:00
|
|
|
return false;
|
|
|
|
}
|
2017-09-06 02:25:01 +00:00
|
|
|
}
|
2017-05-08 19:25:38 +00:00
|
|
|
|
|
|
|
if (precondition == "ram_size")
|
|
|
|
{
|
2017-06-22 15:57:37 +00:00
|
|
|
size_t ram_size_needed = config->getUInt64("preconditions.ram_size");
|
|
|
|
size_t actual_ram = getMemoryAmount();
|
|
|
|
if (!actual_ram)
|
2018-11-22 21:19:58 +00:00
|
|
|
throw DB::Exception("ram_size precondition not available on this platform", DB::ErrorCodes::NOT_IMPLEMENTED);
|
2017-06-22 15:57:37 +00:00
|
|
|
|
|
|
|
if (ram_size_needed > actual_ram)
|
2017-05-08 19:25:38 +00:00
|
|
|
{
|
2017-06-22 15:57:37 +00:00
|
|
|
std::cerr << "Not enough RAM: need = " << ram_size_needed << ", present = " << actual_ram << std::endl;
|
|
|
|
return false;
|
2017-05-08 19:25:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (precondition == "table_exists")
|
|
|
|
{
|
2017-05-30 16:26:37 +00:00
|
|
|
String precondition_key = "preconditions.table_exists[" + std::to_string(table_precondition_index++) + "]";
|
|
|
|
String table_to_check = config->getString(precondition_key);
|
|
|
|
String query = "EXISTS TABLE " + table_to_check + ";";
|
2017-05-08 19:25:38 +00:00
|
|
|
|
|
|
|
size_t exist = 0;
|
|
|
|
|
|
|
|
connection.sendQuery(query, "", QueryProcessingStage::Complete, &settings, nullptr, false);
|
|
|
|
|
|
|
|
while (true)
|
|
|
|
{
|
|
|
|
Connection::Packet packet = connection.receivePacket();
|
|
|
|
|
2017-06-22 15:57:37 +00:00
|
|
|
if (packet.type == Protocol::Server::Data)
|
|
|
|
{
|
2017-12-18 02:37:08 +00:00
|
|
|
for (const ColumnWithTypeAndName & column : packet.block)
|
2017-05-08 19:25:38 +00:00
|
|
|
{
|
2017-06-22 15:57:37 +00:00
|
|
|
if (column.name == "result" && column.column->size() > 0)
|
|
|
|
{
|
2017-05-08 19:25:38 +00:00
|
|
|
exist = column.column->get64(0);
|
2017-06-22 15:57:37 +00:00
|
|
|
if (exist)
|
|
|
|
break;
|
2017-05-08 19:25:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (packet.type == Protocol::Server::Exception || packet.type == Protocol::Server::EndOfStream)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-06-22 15:57:37 +00:00
|
|
|
if (!exist)
|
|
|
|
{
|
|
|
|
std::cerr << "Table " << table_to_check << " doesn't exist" << std::endl;
|
2017-05-08 19:25:38 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-05-07 18:55:42 +00:00
|
|
|
void processTestsConfigurations(const Paths & input_files)
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
2017-05-05 17:48:11 +00:00
|
|
|
tests_configurations.resize(input_files.size());
|
2017-05-05 11:36:55 +00:00
|
|
|
|
|
|
|
for (size_t i = 0; i != input_files.size(); ++i)
|
|
|
|
{
|
2017-05-30 16:26:37 +00:00
|
|
|
const String path = input_files[i];
|
2017-06-21 18:41:50 +00:00
|
|
|
tests_configurations[i] = XMLConfigurationPtr(new XMLConfiguration(path));
|
2017-05-05 11:36:55 +00:00
|
|
|
}
|
|
|
|
|
2017-05-07 18:55:42 +00:00
|
|
|
filterConfigurations();
|
2017-05-05 11:36:55 +00:00
|
|
|
|
2017-05-05 17:48:11 +00:00
|
|
|
if (tests_configurations.size())
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
2017-05-07 01:29:24 +00:00
|
|
|
Strings outputs;
|
|
|
|
|
2017-05-05 17:48:11 +00:00
|
|
|
for (auto & test_config : tests_configurations)
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
2017-05-08 19:25:38 +00:00
|
|
|
if (!checkPreconditions(test_config))
|
|
|
|
{
|
2017-09-06 02:25:01 +00:00
|
|
|
std::cerr << "Preconditions are not fulfilled for test '" + test_config->getString("name", "") + "' ";
|
2017-05-08 19:25:38 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2017-05-30 16:26:37 +00:00
|
|
|
String output = runTest(test_config);
|
2017-05-07 01:29:24 +00:00
|
|
|
if (lite_output)
|
2017-06-21 14:19:05 +00:00
|
|
|
std::cout << output;
|
2017-05-07 01:29:24 +00:00
|
|
|
else
|
|
|
|
outputs.push_back(output);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!lite_output && outputs.size())
|
|
|
|
{
|
|
|
|
std::cout << "[" << std::endl;
|
|
|
|
|
|
|
|
for (size_t i = 0; i != outputs.size(); ++i)
|
|
|
|
{
|
|
|
|
std::cout << outputs[i];
|
|
|
|
if (i != outputs.size() - 1)
|
|
|
|
std::cout << ",";
|
|
|
|
|
|
|
|
std::cout << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::cout << "]" << std::endl;
|
2017-05-05 11:36:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-21 18:41:50 +00:00
|
|
|
void extractSettings(
|
2017-09-06 02:19:52 +00:00
|
|
|
const XMLConfigurationPtr & config, const String & key, const Strings & settings_list, std::map<String, String> & settings_to_apply)
|
2017-05-07 00:29:30 +00:00
|
|
|
{
|
2017-05-30 16:26:37 +00:00
|
|
|
for (const String & setup : settings_list)
|
2017-05-07 00:29:30 +00:00
|
|
|
{
|
|
|
|
if (setup == "profile")
|
|
|
|
continue;
|
|
|
|
|
2017-05-30 16:26:37 +00:00
|
|
|
String value = config->getString(key + "." + setup);
|
2017-05-07 00:29:30 +00:00
|
|
|
if (value.empty())
|
|
|
|
value = "true";
|
|
|
|
|
|
|
|
settings_to_apply[setup] = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-21 18:41:50 +00:00
|
|
|
String runTest(XMLConfigurationPtr & test_config)
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
2017-05-06 22:38:14 +00:00
|
|
|
queries.clear();
|
|
|
|
|
2017-05-05 17:48:11 +00:00
|
|
|
test_name = test_config->getString("name");
|
2017-05-07 01:29:24 +00:00
|
|
|
std::cerr << "Running: " << test_name << "\n";
|
2017-05-05 11:36:55 +00:00
|
|
|
|
2017-05-05 17:48:11 +00:00
|
|
|
if (test_config->has("settings"))
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
2017-05-30 16:26:37 +00:00
|
|
|
std::map<String, String> settings_to_apply;
|
2017-05-05 17:48:11 +00:00
|
|
|
Keys config_settings;
|
|
|
|
test_config->keys("settings", config_settings);
|
2017-05-05 11:36:55 +00:00
|
|
|
|
2017-05-07 00:29:30 +00:00
|
|
|
/// Preprocess configuration file
|
|
|
|
if (std::find(config_settings.begin(), config_settings.end(), "profile") != config_settings.end())
|
|
|
|
{
|
|
|
|
if (!profiles_file.empty())
|
|
|
|
{
|
2017-05-30 16:26:37 +00:00
|
|
|
String profile_name = test_config->getString("settings.profile");
|
2017-06-21 18:41:50 +00:00
|
|
|
XMLConfigurationPtr profiles_config(new XMLConfiguration(profiles_file));
|
2017-05-07 00:29:30 +00:00
|
|
|
|
|
|
|
Keys profile_settings;
|
|
|
|
profiles_config->keys("profiles." + profile_name, profile_settings);
|
|
|
|
|
|
|
|
extractSettings(profiles_config, "profiles." + profile_name, profile_settings, settings_to_apply);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
extractSettings(test_config, "settings", config_settings, settings_to_apply);
|
|
|
|
|
2017-05-05 11:36:55 +00:00
|
|
|
/// This macro goes through all settings in the Settings.h
|
|
|
|
/// and, if found any settings in test's xml configuration
|
|
|
|
/// with the same name, sets its value to settings
|
2017-05-30 16:26:37 +00:00
|
|
|
std::map<String, String>::iterator it;
|
2017-11-30 11:50:02 +00:00
|
|
|
#define EXTRACT_SETTING(TYPE, NAME, DEFAULT, DESCRIPTION) \
|
2017-09-06 02:19:52 +00:00
|
|
|
it = settings_to_apply.find(#NAME); \
|
|
|
|
if (it != settings_to_apply.end()) \
|
|
|
|
settings.set(#NAME, settings_to_apply[#NAME]);
|
2017-05-05 11:36:55 +00:00
|
|
|
|
2017-05-07 00:29:30 +00:00
|
|
|
APPLY_FOR_SETTINGS(EXTRACT_SETTING)
|
|
|
|
|
2017-09-06 02:19:52 +00:00
|
|
|
#undef EXTRACT_SETTING
|
2017-05-05 11:36:55 +00:00
|
|
|
|
2017-05-05 17:48:11 +00:00
|
|
|
if (std::find(config_settings.begin(), config_settings.end(), "average_rows_speed_precision") != config_settings.end())
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
2017-05-05 17:48:11 +00:00
|
|
|
Stats::avg_rows_speed_precision = test_config->getDouble("settings.average_rows_speed_precision");
|
2017-05-05 11:36:55 +00:00
|
|
|
}
|
|
|
|
|
2017-05-05 17:48:11 +00:00
|
|
|
if (std::find(config_settings.begin(), config_settings.end(), "average_bytes_speed_precision") != config_settings.end())
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
2017-05-05 17:48:11 +00:00
|
|
|
Stats::avg_bytes_speed_precision = test_config->getDouble("settings.average_bytes_speed_precision");
|
2017-05-05 11:36:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Query query;
|
|
|
|
|
2017-05-06 14:36:37 +00:00
|
|
|
if (!test_config->has("query") && !test_config->has("query_file"))
|
|
|
|
{
|
2018-11-22 21:19:58 +00:00
|
|
|
throw DB::Exception("Missing query fields in test's config: " + test_name, DB::ErrorCodes::BAD_ARGUMENTS);
|
2017-05-06 14:36:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (test_config->has("query") && test_config->has("query_file"))
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
2018-11-22 21:19:58 +00:00
|
|
|
throw DB::Exception("Found both query and query_file fields. Choose only one", DB::ErrorCodes::BAD_ARGUMENTS);
|
2017-05-05 11:36:55 +00:00
|
|
|
}
|
|
|
|
|
2017-05-06 14:36:37 +00:00
|
|
|
if (test_config->has("query"))
|
2017-06-21 14:16:19 +00:00
|
|
|
{
|
2017-06-22 18:56:40 +00:00
|
|
|
queries = DB::getMultipleValuesFromConfig(*test_config, "", "query");
|
2017-06-21 14:16:19 +00:00
|
|
|
}
|
2017-05-06 14:36:37 +00:00
|
|
|
|
|
|
|
if (test_config->has("query_file"))
|
|
|
|
{
|
2017-05-30 16:26:37 +00:00
|
|
|
const String filename = test_config->getString("query_file");
|
2017-05-06 14:36:37 +00:00
|
|
|
if (filename.empty())
|
2018-11-22 21:19:58 +00:00
|
|
|
throw DB::Exception("Empty file name", DB::ErrorCodes::BAD_ARGUMENTS);
|
2017-05-06 14:36:37 +00:00
|
|
|
|
2017-09-06 02:33:24 +00:00
|
|
|
bool tsv = fs::path(filename).extension().string() == ".tsv";
|
2017-05-06 14:36:37 +00:00
|
|
|
|
|
|
|
ReadBufferFromFile query_file(filename);
|
2017-05-06 22:25:18 +00:00
|
|
|
|
2017-06-13 06:21:52 +00:00
|
|
|
if (tsv)
|
|
|
|
{
|
|
|
|
while (!query_file.eof())
|
|
|
|
{
|
|
|
|
readEscapedString(query, query_file);
|
|
|
|
assertChar('\n', query_file);
|
2017-05-06 22:25:18 +00:00
|
|
|
queries.push_back(query);
|
2017-06-13 06:21:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
readStringUntilEOF(query, query_file);
|
|
|
|
queries.push_back(query);
|
2017-05-06 14:36:37 +00:00
|
|
|
}
|
|
|
|
}
|
2017-05-05 11:36:55 +00:00
|
|
|
|
2017-05-06 14:36:37 +00:00
|
|
|
if (queries.empty())
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
2018-11-22 21:19:58 +00:00
|
|
|
throw DB::Exception("Did not find any query to execute: " + test_name, DB::ErrorCodes::BAD_ARGUMENTS);
|
2017-05-05 11:36:55 +00:00
|
|
|
}
|
|
|
|
|
2017-05-05 17:48:11 +00:00
|
|
|
if (test_config->has("substitutions"))
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
|
|
|
/// Make "subconfig" of inner xml block
|
2017-06-21 18:41:50 +00:00
|
|
|
ConfigurationPtr substitutions_view(test_config->createView("substitutions"));
|
2017-05-05 17:48:11 +00:00
|
|
|
constructSubstitutions(substitutions_view, substitutions);
|
2017-05-05 11:36:55 +00:00
|
|
|
|
2017-11-16 18:03:31 +00:00
|
|
|
auto queries_pre_format = queries;
|
|
|
|
queries.clear();
|
2018-01-10 00:04:08 +00:00
|
|
|
for (const auto & query : queries_pre_format)
|
|
|
|
{
|
2017-11-16 18:03:31 +00:00
|
|
|
auto formatted = formatQueries(query, substitutions);
|
|
|
|
queries.insert(queries.end(), formatted.begin(), formatted.end());
|
|
|
|
}
|
2017-05-05 11:36:55 +00:00
|
|
|
}
|
|
|
|
|
2017-05-05 17:48:11 +00:00
|
|
|
if (!test_config->has("type"))
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
2018-11-22 21:19:58 +00:00
|
|
|
throw DB::Exception("Missing type property in config: " + test_name, DB::ErrorCodes::BAD_ARGUMENTS);
|
2017-05-05 11:36:55 +00:00
|
|
|
}
|
|
|
|
|
2017-05-30 16:26:37 +00:00
|
|
|
String config_exec_type = test_config->getString("type");
|
2017-05-05 17:48:11 +00:00
|
|
|
if (config_exec_type == "loop")
|
2017-05-30 16:26:37 +00:00
|
|
|
exec_type = ExecutionType::Loop;
|
2017-05-05 17:48:11 +00:00
|
|
|
else if (config_exec_type == "once")
|
2017-05-30 16:26:37 +00:00
|
|
|
exec_type = ExecutionType::Once;
|
2017-05-05 11:36:55 +00:00
|
|
|
else
|
2018-11-22 21:19:58 +00:00
|
|
|
throw DB::Exception("Unknown type " + config_exec_type + " in :" + test_name, DB::ErrorCodes::BAD_ARGUMENTS);
|
2017-05-05 11:36:55 +00:00
|
|
|
|
2017-10-10 13:32:31 +00:00
|
|
|
times_to_run = test_config->getUInt("times_to_run", 1);
|
2017-05-05 11:36:55 +00:00
|
|
|
|
2017-07-17 18:01:47 +00:00
|
|
|
stop_conditions_by_run.clear();
|
2017-06-21 18:41:50 +00:00
|
|
|
TestStopConditions stop_conditions_template;
|
2017-06-21 14:55:09 +00:00
|
|
|
if (test_config->has("stop_conditions"))
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
2017-06-21 18:41:50 +00:00
|
|
|
ConfigurationPtr stop_conditions_config(test_config->createView("stop_conditions"));
|
|
|
|
stop_conditions_template.loadFromConfig(stop_conditions_config);
|
2017-05-05 11:36:55 +00:00
|
|
|
}
|
2017-06-21 18:41:50 +00:00
|
|
|
|
|
|
|
if (stop_conditions_template.empty())
|
2018-11-22 21:19:58 +00:00
|
|
|
throw DB::Exception("No termination conditions were found in config", DB::ErrorCodes::BAD_ARGUMENTS);
|
2017-05-05 11:36:55 +00:00
|
|
|
|
2017-06-21 18:41:50 +00:00
|
|
|
for (size_t i = 0; i < times_to_run * queries.size(); ++i)
|
|
|
|
stop_conditions_by_run.push_back(stop_conditions_template);
|
|
|
|
|
|
|
|
|
|
|
|
ConfigurationPtr metrics_view(test_config->createView("metrics"));
|
2017-05-05 11:36:55 +00:00
|
|
|
Keys metrics;
|
2017-05-05 17:48:11 +00:00
|
|
|
metrics_view->keys(metrics);
|
2017-05-07 01:29:24 +00:00
|
|
|
|
2017-07-17 18:01:47 +00:00
|
|
|
main_metric.clear();
|
2017-05-07 01:29:24 +00:00
|
|
|
if (test_config->has("main_metric"))
|
|
|
|
{
|
|
|
|
Keys main_metrics;
|
|
|
|
test_config->keys("main_metric", main_metrics);
|
|
|
|
if (main_metrics.size())
|
|
|
|
main_metric = main_metrics[0];
|
|
|
|
}
|
2017-05-05 11:36:55 +00:00
|
|
|
|
2017-05-08 19:25:38 +00:00
|
|
|
if (!main_metric.empty())
|
|
|
|
{
|
2017-05-05 15:58:25 +00:00
|
|
|
if (std::find(metrics.begin(), metrics.end(), main_metric) == metrics.end())
|
|
|
|
metrics.push_back(main_metric);
|
2017-05-08 19:25:38 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-05-05 15:58:25 +00:00
|
|
|
if (lite_output)
|
2018-11-22 21:19:58 +00:00
|
|
|
throw DB::Exception("Specify main_metric for lite output", DB::ErrorCodes::BAD_ARGUMENTS);
|
2017-05-05 11:36:55 +00:00
|
|
|
}
|
2017-05-05 15:58:25 +00:00
|
|
|
|
|
|
|
if (metrics.size() > 0)
|
|
|
|
checkMetricsInput(metrics);
|
2017-05-05 11:36:55 +00:00
|
|
|
|
2017-06-21 14:19:05 +00:00
|
|
|
statistics_by_run.resize(times_to_run * queries.size());
|
2017-05-05 17:48:11 +00:00
|
|
|
for (size_t number_of_launch = 0; number_of_launch < times_to_run; ++number_of_launch)
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
2017-05-05 17:48:11 +00:00
|
|
|
QueriesWithIndexes queries_with_indexes;
|
2017-05-05 11:36:55 +00:00
|
|
|
|
2017-05-05 17:48:11 +00:00
|
|
|
for (size_t query_index = 0; query_index < queries.size(); ++query_index)
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
2017-05-05 17:48:11 +00:00
|
|
|
size_t statistic_index = number_of_launch * queries.size() + query_index;
|
2017-06-21 18:41:50 +00:00
|
|
|
stop_conditions_by_run[statistic_index].reset();
|
2017-05-05 11:36:55 +00:00
|
|
|
|
2017-05-05 17:48:11 +00:00
|
|
|
queries_with_indexes.push_back({queries[query_index], statistic_index});
|
2017-05-05 11:36:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (interrupt_listener.check())
|
|
|
|
gotSIGINT = true;
|
|
|
|
|
|
|
|
if (gotSIGINT)
|
|
|
|
break;
|
|
|
|
|
2017-05-05 17:48:11 +00:00
|
|
|
runQueries(queries_with_indexes);
|
2017-05-05 11:36:55 +00:00
|
|
|
}
|
|
|
|
|
2017-05-05 15:58:25 +00:00
|
|
|
if (lite_output)
|
2017-05-07 01:29:24 +00:00
|
|
|
return minOutput(main_metric);
|
2017-05-05 11:36:55 +00:00
|
|
|
else
|
2017-05-09 17:17:24 +00:00
|
|
|
return constructTotalInfo(metrics);
|
2017-05-05 11:36:55 +00:00
|
|
|
}
|
|
|
|
|
2017-05-05 15:58:25 +00:00
|
|
|
void checkMetricsInput(const Strings & metrics) const
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
2017-05-30 16:26:37 +00:00
|
|
|
std::vector<String> loop_metrics
|
2017-05-05 11:36:55 +00:00
|
|
|
= {"min_time", "quantiles", "total_time", "queries_per_second", "rows_per_second", "bytes_per_second"};
|
|
|
|
|
2017-05-30 16:26:37 +00:00
|
|
|
std::vector<String> non_loop_metrics
|
2017-05-05 11:36:55 +00:00
|
|
|
= {"max_rows_per_second", "max_bytes_per_second", "avg_rows_per_second", "avg_bytes_per_second"};
|
|
|
|
|
2017-05-30 16:26:37 +00:00
|
|
|
if (exec_type == ExecutionType::Loop)
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
2017-05-30 16:26:37 +00:00
|
|
|
for (const String & metric : metrics)
|
2017-05-05 17:48:11 +00:00
|
|
|
if (std::find(non_loop_metrics.begin(), non_loop_metrics.end(), metric) != non_loop_metrics.end())
|
2018-11-22 21:19:58 +00:00
|
|
|
throw DB::Exception("Wrong type of metric for loop execution type (" + metric + ")", DB::ErrorCodes::BAD_ARGUMENTS);
|
2017-05-05 11:36:55 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-05-30 16:26:37 +00:00
|
|
|
for (const String & metric : metrics)
|
2017-05-05 17:48:11 +00:00
|
|
|
if (std::find(loop_metrics.begin(), loop_metrics.end(), metric) != loop_metrics.end())
|
2018-11-22 21:19:58 +00:00
|
|
|
throw DB::Exception("Wrong type of metric for non-loop execution type (" + metric + ")", DB::ErrorCodes::BAD_ARGUMENTS);
|
2017-05-05 11:36:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-05 17:48:11 +00:00
|
|
|
void runQueries(const QueriesWithIndexes & queries_with_indexes)
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
2017-05-05 17:48:11 +00:00
|
|
|
for (const std::pair<Query, const size_t> & query_and_index : queries_with_indexes)
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
2017-05-05 17:48:11 +00:00
|
|
|
Query query = query_and_index.first;
|
2017-06-21 16:47:16 +00:00
|
|
|
const size_t run_index = query_and_index.second;
|
|
|
|
|
2017-06-21 18:41:50 +00:00
|
|
|
TestStopConditions & stop_conditions = stop_conditions_by_run[run_index];
|
|
|
|
Stats & statistics = statistics_by_run[run_index];
|
2017-05-05 11:36:55 +00:00
|
|
|
|
2017-06-21 16:47:16 +00:00
|
|
|
statistics.clear();
|
2017-11-16 18:09:28 +00:00
|
|
|
try
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
2017-11-16 18:09:28 +00:00
|
|
|
execute(query, statistics, stop_conditions);
|
|
|
|
|
|
|
|
if (exec_type == ExecutionType::Loop)
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
2017-11-16 18:09:28 +00:00
|
|
|
for (size_t iteration = 1; !gotSIGINT; ++iteration)
|
|
|
|
{
|
|
|
|
stop_conditions.reportIterations(iteration);
|
|
|
|
if (stop_conditions.areFulfilled())
|
|
|
|
break;
|
2017-05-05 11:36:55 +00:00
|
|
|
|
2017-11-16 18:09:28 +00:00
|
|
|
execute(query, statistics, stop_conditions);
|
|
|
|
}
|
2017-05-05 11:36:55 +00:00
|
|
|
}
|
|
|
|
}
|
2017-11-16 18:09:28 +00:00
|
|
|
catch (const DB::Exception & e)
|
|
|
|
{
|
2017-11-16 18:03:31 +00:00
|
|
|
statistics.exception = e.what() + String(", ") + e.displayText();
|
2017-11-16 18:09:28 +00:00
|
|
|
}
|
2017-05-05 11:36:55 +00:00
|
|
|
|
|
|
|
if (!gotSIGINT)
|
|
|
|
{
|
2017-06-21 16:47:16 +00:00
|
|
|
statistics.ready = true;
|
2017-05-05 11:36:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-21 18:41:50 +00:00
|
|
|
void execute(const Query & query, Stats & statistics, TestStopConditions & stop_conditions)
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
2017-06-21 16:47:16 +00:00
|
|
|
statistics.watch_per_query.restart();
|
|
|
|
statistics.last_query_was_cancelled = false;
|
2017-07-11 18:08:02 +00:00
|
|
|
statistics.last_query_rows_read = 0;
|
|
|
|
statistics.last_query_bytes_read = 0;
|
2017-05-05 11:36:55 +00:00
|
|
|
|
2018-02-15 18:54:12 +00:00
|
|
|
RemoteBlockInputStream stream(connection, query, {}, global_context, &settings);
|
2017-05-05 11:36:55 +00:00
|
|
|
|
2017-09-06 02:19:52 +00:00
|
|
|
stream.setProgressCallback(
|
|
|
|
[&](const Progress & value) { this->checkFulfilledConditionsAndUpdate(value, stream, statistics, stop_conditions); });
|
2017-05-05 11:36:55 +00:00
|
|
|
|
2017-05-05 12:41:18 +00:00
|
|
|
stream.readPrefix();
|
|
|
|
while (Block block = stream.read())
|
2017-05-05 11:36:55 +00:00
|
|
|
;
|
2017-05-05 12:41:18 +00:00
|
|
|
stream.readSuffix();
|
2017-05-05 11:36:55 +00:00
|
|
|
|
2017-06-21 16:47:16 +00:00
|
|
|
if (!statistics.last_query_was_cancelled)
|
|
|
|
statistics.updateQueryInfo();
|
|
|
|
|
|
|
|
statistics.setTotalTime();
|
2017-05-05 11:36:55 +00:00
|
|
|
}
|
|
|
|
|
2017-06-21 18:41:50 +00:00
|
|
|
void checkFulfilledConditionsAndUpdate(
|
2017-09-06 02:19:52 +00:00
|
|
|
const Progress & progress, RemoteBlockInputStream & stream, Stats & statistics, TestStopConditions & stop_conditions)
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
2017-06-21 16:47:16 +00:00
|
|
|
statistics.add(progress.rows, progress.bytes);
|
2017-05-05 11:36:55 +00:00
|
|
|
|
2017-07-11 18:08:02 +00:00
|
|
|
stop_conditions.reportRowsRead(statistics.total_rows_read);
|
|
|
|
stop_conditions.reportBytesReadUncompressed(statistics.total_bytes_read);
|
2017-06-21 18:41:50 +00:00
|
|
|
stop_conditions.reportTotalTime(statistics.watch.elapsed() / (1000 * 1000));
|
|
|
|
stop_conditions.reportMinTimeNotChangingFor(statistics.min_time_watch.elapsed() / (1000 * 1000));
|
2017-09-06 02:19:52 +00:00
|
|
|
stop_conditions.reportMaxSpeedNotChangingFor(statistics.max_rows_speed_watch.elapsed() / (1000 * 1000));
|
|
|
|
stop_conditions.reportAverageSpeedNotChangingFor(statistics.avg_rows_speed_watch.elapsed() / (1000 * 1000));
|
2017-05-05 11:36:55 +00:00
|
|
|
|
2017-06-21 18:41:50 +00:00
|
|
|
if (stop_conditions.areFulfilled())
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
2017-06-21 16:47:16 +00:00
|
|
|
statistics.last_query_was_cancelled = true;
|
2018-03-05 21:09:39 +00:00
|
|
|
stream.cancel(false);
|
2017-05-05 11:36:55 +00:00
|
|
|
}
|
|
|
|
|
2017-05-05 12:41:18 +00:00
|
|
|
if (interrupt_listener.check())
|
|
|
|
{
|
2017-05-05 11:36:55 +00:00
|
|
|
gotSIGINT = true;
|
2017-06-21 16:47:16 +00:00
|
|
|
statistics.last_query_was_cancelled = true;
|
2018-03-05 21:09:39 +00:00
|
|
|
stream.cancel(false);
|
2017-05-05 11:36:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-21 18:41:50 +00:00
|
|
|
void constructSubstitutions(ConfigurationPtr & substitutions_view, StringToVector & substitutions)
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
|
|
|
Keys xml_substitutions;
|
2017-05-05 17:48:11 +00:00
|
|
|
substitutions_view->keys(xml_substitutions);
|
2017-05-05 11:36:55 +00:00
|
|
|
|
|
|
|
for (size_t i = 0; i != xml_substitutions.size(); ++i)
|
|
|
|
{
|
2017-09-06 02:19:52 +00:00
|
|
|
const ConfigurationPtr xml_substitution(substitutions_view->createView("substitution[" + std::to_string(i) + "]"));
|
2017-05-05 11:36:55 +00:00
|
|
|
|
|
|
|
/// Property values for substitution will be stored in a vector
|
|
|
|
/// accessible by property name
|
2017-05-30 16:26:37 +00:00
|
|
|
std::vector<String> xml_values;
|
2017-05-05 11:36:55 +00:00
|
|
|
xml_substitution->keys("values", xml_values);
|
|
|
|
|
2017-05-30 16:26:37 +00:00
|
|
|
String name = xml_substitution->getString("name");
|
2017-05-05 11:36:55 +00:00
|
|
|
|
|
|
|
for (size_t j = 0; j != xml_values.size(); ++j)
|
|
|
|
{
|
|
|
|
substitutions[name].push_back(xml_substitution->getString("values.value[" + std::to_string(j) + "]"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-30 16:26:37 +00:00
|
|
|
std::vector<String> formatQueries(const String & query, StringToVector substitutions)
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
2017-05-30 16:26:37 +00:00
|
|
|
std::vector<String> queries;
|
2017-05-05 11:36:55 +00:00
|
|
|
|
|
|
|
StringToVector::iterator substitutions_first = substitutions.begin();
|
|
|
|
StringToVector::iterator substitutions_last = substitutions.end();
|
|
|
|
|
2018-10-01 16:30:12 +00:00
|
|
|
runThroughAllOptionsAndPush(substitutions_first, substitutions_last, query, queries);
|
2017-05-05 11:36:55 +00:00
|
|
|
|
|
|
|
return queries;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Recursive method which goes through all substitution blocks in xml
|
|
|
|
/// and replaces property {names} by their values
|
|
|
|
void runThroughAllOptionsAndPush(StringToVector::iterator substitutions_left,
|
|
|
|
StringToVector::iterator substitutions_right,
|
2017-05-30 16:26:37 +00:00
|
|
|
const String & template_query,
|
2018-10-01 16:30:12 +00:00
|
|
|
std::vector<String> & queries)
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
2018-10-01 16:30:12 +00:00
|
|
|
if (substitutions_left == substitutions_right)
|
|
|
|
{
|
|
|
|
queries.push_back(template_query); /// completely substituted query
|
|
|
|
return;
|
|
|
|
}
|
2017-05-05 11:36:55 +00:00
|
|
|
|
2018-10-01 16:30:12 +00:00
|
|
|
String substitution_mask = "{" + substitutions_left->first + "}";
|
|
|
|
|
|
|
|
if (template_query.find(substitution_mask) == String::npos) /// nothing to substitute here
|
|
|
|
{
|
|
|
|
runThroughAllOptionsAndPush(std::next(substitutions_left), substitutions_right, template_query, queries);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (const String & value : substitutions_left->second)
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
|
|
|
/// Copy query string for each unique permutation
|
|
|
|
Query query = template_query;
|
2017-05-05 17:48:11 +00:00
|
|
|
size_t substr_pos = 0;
|
2017-05-05 11:36:55 +00:00
|
|
|
|
2017-05-30 16:26:37 +00:00
|
|
|
while (substr_pos != String::npos)
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
2018-10-01 16:30:12 +00:00
|
|
|
substr_pos = query.find(substitution_mask);
|
2017-05-05 11:36:55 +00:00
|
|
|
|
2017-05-30 16:26:37 +00:00
|
|
|
if (substr_pos != String::npos)
|
2018-10-01 16:30:12 +00:00
|
|
|
query.replace(substr_pos, substitution_mask.length(), value);
|
2017-05-05 11:36:55 +00:00
|
|
|
}
|
|
|
|
|
2018-10-01 16:30:12 +00:00
|
|
|
runThroughAllOptionsAndPush(std::next(substitutions_left), substitutions_right, query, queries);
|
2017-05-05 11:36:55 +00:00
|
|
|
}
|
|
|
|
}
|
2017-02-24 22:02:08 +00:00
|
|
|
|
|
|
|
public:
|
2017-05-30 16:26:37 +00:00
|
|
|
String constructTotalInfo(Strings metrics)
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
2017-05-05 17:48:11 +00:00
|
|
|
JSONString json_output;
|
2017-05-05 11:36:55 +00:00
|
|
|
|
2017-06-21 15:51:12 +00:00
|
|
|
json_output.set("hostname", getFQDNOrHostName());
|
2017-06-22 13:58:58 +00:00
|
|
|
json_output.set("num_cores", getNumberOfPhysicalCPUCores());
|
2017-07-19 15:18:47 +00:00
|
|
|
json_output.set("num_threads", std::thread::hardware_concurrency());
|
|
|
|
json_output.set("ram", getMemoryAmount());
|
2017-06-21 15:51:12 +00:00
|
|
|
json_output.set("server_version", server_version);
|
2017-12-18 04:07:26 +00:00
|
|
|
json_output.set("time", DateLUT::instance().timeToString(time(nullptr)));
|
2017-05-30 16:26:37 +00:00
|
|
|
json_output.set("test_name", test_name);
|
|
|
|
json_output.set("main_metric", main_metric);
|
2017-05-05 11:36:55 +00:00
|
|
|
|
|
|
|
if (substitutions.size())
|
|
|
|
{
|
2017-05-05 17:48:11 +00:00
|
|
|
JSONString json_parameters(2); /// here, 2 is the size of \t padding
|
2017-05-05 11:36:55 +00:00
|
|
|
|
|
|
|
for (auto it = substitutions.begin(); it != substitutions.end(); ++it)
|
|
|
|
{
|
2017-05-30 16:26:37 +00:00
|
|
|
String parameter = it->first;
|
|
|
|
std::vector<String> values = it->second;
|
2017-05-05 11:36:55 +00:00
|
|
|
|
2017-05-30 16:26:37 +00:00
|
|
|
String array_string = "[";
|
2017-05-05 11:36:55 +00:00
|
|
|
for (size_t i = 0; i != values.size(); ++i)
|
|
|
|
{
|
2017-09-06 02:25:01 +00:00
|
|
|
array_string += '"' + values[i] + '"';
|
2017-05-05 11:36:55 +00:00
|
|
|
if (i != values.size() - 1)
|
|
|
|
{
|
2017-05-05 17:48:11 +00:00
|
|
|
array_string += ", ";
|
2017-05-05 11:36:55 +00:00
|
|
|
}
|
|
|
|
}
|
2017-05-05 17:48:11 +00:00
|
|
|
array_string += ']';
|
2017-05-05 11:36:55 +00:00
|
|
|
|
2017-05-30 16:26:37 +00:00
|
|
|
json_parameters.set(parameter, array_string);
|
2017-05-05 11:36:55 +00:00
|
|
|
}
|
|
|
|
|
2017-05-30 16:26:37 +00:00
|
|
|
json_output.set("parameters", json_parameters.asString());
|
2017-05-05 11:36:55 +00:00
|
|
|
}
|
|
|
|
|
2017-05-05 17:48:11 +00:00
|
|
|
std::vector<JSONString> run_infos;
|
|
|
|
for (size_t query_index = 0; query_index < queries.size(); ++query_index)
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
2017-06-21 14:19:05 +00:00
|
|
|
for (size_t number_of_launch = 0; number_of_launch < times_to_run; ++number_of_launch)
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
2017-06-21 14:19:05 +00:00
|
|
|
Stats & statistics = statistics_by_run[number_of_launch * queries.size() + query_index];
|
|
|
|
|
|
|
|
if (!statistics.ready)
|
2017-05-05 16:49:14 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
JSONString runJSON;
|
2017-05-05 11:36:55 +00:00
|
|
|
|
2017-06-21 14:19:05 +00:00
|
|
|
runJSON.set("query", queries[query_index]);
|
2017-11-16 18:03:31 +00:00
|
|
|
if (!statistics.exception.empty())
|
|
|
|
runJSON.set("exception", statistics.exception);
|
2017-06-21 14:19:05 +00:00
|
|
|
|
2017-05-05 17:48:11 +00:00
|
|
|
if (substitutions_maps.size())
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
2017-05-05 16:49:14 +00:00
|
|
|
JSONString parameters(4);
|
|
|
|
|
2017-05-05 17:48:11 +00:00
|
|
|
for (auto it = substitutions_maps[query_index].begin(); it != substitutions_maps[query_index].end(); ++it)
|
2017-05-05 16:49:14 +00:00
|
|
|
{
|
2017-05-30 16:26:37 +00:00
|
|
|
parameters.set(it->first, it->second);
|
2017-05-05 16:49:14 +00:00
|
|
|
}
|
|
|
|
|
2017-05-30 16:26:37 +00:00
|
|
|
runJSON.set("parameters", parameters.asString());
|
2017-05-05 11:36:55 +00:00
|
|
|
}
|
|
|
|
|
2017-06-21 14:19:05 +00:00
|
|
|
|
2017-05-30 16:26:37 +00:00
|
|
|
if (exec_type == ExecutionType::Loop)
|
2017-05-05 16:49:14 +00:00
|
|
|
{
|
|
|
|
/// in seconds
|
2017-05-09 17:17:24 +00:00
|
|
|
if (std::find(metrics.begin(), metrics.end(), "min_time") != metrics.end())
|
2017-06-21 14:19:05 +00:00
|
|
|
runJSON.set("min_time", statistics.min_time / double(1000));
|
2017-05-05 11:36:55 +00:00
|
|
|
|
2017-05-09 17:17:24 +00:00
|
|
|
if (std::find(metrics.begin(), metrics.end(), "quantiles") != metrics.end())
|
2017-05-05 16:49:14 +00:00
|
|
|
{
|
2017-05-09 17:17:24 +00:00
|
|
|
JSONString quantiles(4); /// here, 4 is the size of \t padding
|
|
|
|
for (double percent = 10; percent <= 90; percent += 10)
|
|
|
|
{
|
2017-05-30 16:26:37 +00:00
|
|
|
String quantile_key = std::to_string(percent / 100.0);
|
|
|
|
while (quantile_key.back() == '0')
|
|
|
|
quantile_key.pop_back();
|
|
|
|
|
2017-06-21 14:19:05 +00:00
|
|
|
quantiles.set(quantile_key, statistics.sampler.quantileInterpolated(percent / 100.0));
|
2017-05-09 17:17:24 +00:00
|
|
|
}
|
2017-09-06 02:19:52 +00:00
|
|
|
quantiles.set("0.95", statistics.sampler.quantileInterpolated(95 / 100.0));
|
|
|
|
quantiles.set("0.99", statistics.sampler.quantileInterpolated(99 / 100.0));
|
|
|
|
quantiles.set("0.999", statistics.sampler.quantileInterpolated(99.9 / 100.0));
|
2017-06-21 14:19:05 +00:00
|
|
|
quantiles.set("0.9999", statistics.sampler.quantileInterpolated(99.99 / 100.0));
|
2017-05-09 17:17:24 +00:00
|
|
|
|
2017-05-30 16:26:37 +00:00
|
|
|
runJSON.set("quantiles", quantiles.asString());
|
2017-05-05 16:49:14 +00:00
|
|
|
}
|
2017-05-05 11:36:55 +00:00
|
|
|
|
2017-05-09 17:17:24 +00:00
|
|
|
if (std::find(metrics.begin(), metrics.end(), "total_time") != metrics.end())
|
2017-06-21 14:19:05 +00:00
|
|
|
runJSON.set("total_time", statistics.total_time);
|
2017-05-09 17:17:24 +00:00
|
|
|
|
|
|
|
if (std::find(metrics.begin(), metrics.end(), "queries_per_second") != metrics.end())
|
2017-09-06 02:19:52 +00:00
|
|
|
runJSON.set("queries_per_second", double(statistics.queries) / statistics.total_time);
|
2017-05-05 16:49:14 +00:00
|
|
|
|
2017-05-09 17:17:24 +00:00
|
|
|
if (std::find(metrics.begin(), metrics.end(), "rows_per_second") != metrics.end())
|
2017-09-06 02:19:52 +00:00
|
|
|
runJSON.set("rows_per_second", double(statistics.total_rows_read) / statistics.total_time);
|
2017-05-09 17:17:24 +00:00
|
|
|
|
|
|
|
if (std::find(metrics.begin(), metrics.end(), "bytes_per_second") != metrics.end())
|
2017-09-06 02:19:52 +00:00
|
|
|
runJSON.set("bytes_per_second", double(statistics.total_bytes_read) / statistics.total_time);
|
2017-05-05 16:49:14 +00:00
|
|
|
}
|
|
|
|
else
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
2017-05-09 17:17:24 +00:00
|
|
|
if (std::find(metrics.begin(), metrics.end(), "max_rows_per_second") != metrics.end())
|
2017-06-21 14:19:05 +00:00
|
|
|
runJSON.set("max_rows_per_second", statistics.max_rows_speed);
|
2017-05-09 17:17:24 +00:00
|
|
|
|
|
|
|
if (std::find(metrics.begin(), metrics.end(), "max_bytes_per_second") != metrics.end())
|
2017-06-21 14:19:05 +00:00
|
|
|
runJSON.set("max_bytes_per_second", statistics.max_bytes_speed);
|
2017-05-09 17:17:24 +00:00
|
|
|
|
|
|
|
if (std::find(metrics.begin(), metrics.end(), "avg_rows_per_second") != metrics.end())
|
2017-06-21 14:19:05 +00:00
|
|
|
runJSON.set("avg_rows_per_second", statistics.avg_rows_speed_value);
|
2017-05-09 17:17:24 +00:00
|
|
|
|
|
|
|
if (std::find(metrics.begin(), metrics.end(), "avg_bytes_per_second") != metrics.end())
|
2017-06-21 14:19:05 +00:00
|
|
|
runJSON.set("avg_bytes_per_second", statistics.avg_bytes_speed_value);
|
2017-05-05 11:36:55 +00:00
|
|
|
}
|
|
|
|
|
2017-05-05 17:48:11 +00:00
|
|
|
run_infos.push_back(runJSON);
|
2017-05-05 11:36:55 +00:00
|
|
|
}
|
|
|
|
}
|
2017-01-13 18:26:51 +00:00
|
|
|
|
2017-05-30 16:26:37 +00:00
|
|
|
json_output.set("runs", run_infos);
|
2017-05-05 11:36:55 +00:00
|
|
|
|
2017-05-30 16:26:37 +00:00
|
|
|
return json_output.asString();
|
2017-05-05 11:36:55 +00:00
|
|
|
}
|
|
|
|
|
2017-05-30 16:26:37 +00:00
|
|
|
String minOutput(const String & main_metric)
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
2017-05-30 16:26:37 +00:00
|
|
|
String output;
|
2017-05-07 01:29:24 +00:00
|
|
|
|
2017-05-05 17:48:11 +00:00
|
|
|
for (size_t query_index = 0; query_index < queries.size(); ++query_index)
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
2017-05-05 17:48:11 +00:00
|
|
|
for (size_t number_of_launch = 0; number_of_launch < times_to_run; ++number_of_launch)
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
2017-06-21 14:19:05 +00:00
|
|
|
if (queries.size() > 1)
|
|
|
|
{
|
|
|
|
output += "query \"" + queries[query_index] + "\", ";
|
|
|
|
}
|
2017-05-05 11:36:55 +00:00
|
|
|
|
2017-05-05 17:48:11 +00:00
|
|
|
if (substitutions_maps.size())
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
2017-05-05 17:48:11 +00:00
|
|
|
for (auto it = substitutions_maps[query_index].begin(); it != substitutions_maps[query_index].end(); ++it)
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
2017-05-07 01:29:24 +00:00
|
|
|
output += it->first + " = " + it->second + ", ";
|
2017-05-05 11:36:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-07 01:29:24 +00:00
|
|
|
output += "run " + std::to_string(number_of_launch + 1) + ": ";
|
|
|
|
output += main_metric + " = ";
|
2017-06-21 14:19:05 +00:00
|
|
|
output += statistics_by_run[number_of_launch * queries.size() + query_index].getStatisticByName(main_metric);
|
2017-05-07 01:29:24 +00:00
|
|
|
output += "\n";
|
2017-05-05 11:36:55 +00:00
|
|
|
}
|
|
|
|
}
|
2017-05-07 01:29:24 +00:00
|
|
|
|
|
|
|
return output;
|
2017-05-05 11:36:55 +00:00
|
|
|
}
|
|
|
|
};
|
2017-01-13 18:26:51 +00:00
|
|
|
}
|
|
|
|
|
2017-09-06 02:33:24 +00:00
|
|
|
static void getFilesFromDir(const fs::path & dir, std::vector<String> & input_files, const bool recursive = false)
|
2017-05-05 18:32:38 +00:00
|
|
|
{
|
|
|
|
if (dir.extension().string() == ".xml")
|
2017-09-06 02:25:01 +00:00
|
|
|
std::cerr << "Warning: '" + dir.string() + "' is a directory, but has .xml extension" << std::endl;
|
2017-05-05 18:32:38 +00:00
|
|
|
|
2017-09-06 02:33:24 +00:00
|
|
|
fs::directory_iterator end;
|
|
|
|
for (fs::directory_iterator it(dir); it != end; ++it)
|
2017-05-05 18:32:38 +00:00
|
|
|
{
|
2017-09-06 02:33:24 +00:00
|
|
|
const fs::path file = (*it);
|
|
|
|
if (recursive && fs::is_directory(file))
|
2017-07-18 20:41:24 +00:00
|
|
|
getFilesFromDir(file, input_files, recursive);
|
2017-09-06 02:33:24 +00:00
|
|
|
else if (!fs::is_directory(file) && file.extension().string() == ".xml")
|
2017-05-05 18:32:38 +00:00
|
|
|
input_files.push_back(file.string());
|
|
|
|
}
|
|
|
|
}
|
2017-01-20 18:34:06 +00:00
|
|
|
|
2018-09-01 02:22:30 +00:00
|
|
|
|
2017-09-06 02:19:52 +00:00
|
|
|
int mainEntryClickHousePerformanceTest(int argc, char ** argv)
|
2017-09-06 02:36:00 +00:00
|
|
|
try
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
2017-09-06 02:36:00 +00:00
|
|
|
using boost::program_options::value;
|
|
|
|
using Strings = std::vector<String>;
|
|
|
|
|
|
|
|
boost::program_options::options_description desc("Allowed options");
|
2018-11-28 15:27:23 +00:00
|
|
|
desc.add_options()
|
|
|
|
("help", "produce help message")
|
|
|
|
("lite", "use lite version of output")
|
|
|
|
("profiles-file", value<String>()->default_value(""), "Specify a file with global profiles")
|
|
|
|
("host,h", value<String>()->default_value("localhost"), "")
|
2018-11-28 12:19:01 +00:00
|
|
|
("port", value<UInt16>()->default_value(9000), "")
|
2018-11-28 21:21:22 +00:00
|
|
|
("secure,s", "Use TLS connection")
|
2018-11-28 15:27:23 +00:00
|
|
|
("database", value<String>()->default_value("default"), "")
|
|
|
|
("user", value<String>()->default_value("default"), "")
|
|
|
|
("password", value<String>()->default_value(""), "")
|
|
|
|
("tags", value<Strings>()->multitoken(), "Run only tests with tag")
|
|
|
|
("skip-tags", value<Strings>()->multitoken(), "Do not run tests with tag")
|
|
|
|
("names", value<Strings>()->multitoken(), "Run tests with specific name")
|
|
|
|
("skip-names", value<Strings>()->multitoken(), "Do not run tests with name")
|
|
|
|
("names-regexp", value<Strings>()->multitoken(), "Run tests with names matching regexp")
|
|
|
|
("skip-names-regexp", value<Strings>()->multitoken(), "Do not run tests with names matching regexp")
|
|
|
|
("recursive,r", "Recurse in directories to find all xml's");
|
2017-09-06 02:36:00 +00:00
|
|
|
|
|
|
|
/// These options will not be displayed in --help
|
|
|
|
boost::program_options::options_description hidden("Hidden options");
|
2018-11-28 15:27:23 +00:00
|
|
|
hidden.add_options()
|
|
|
|
("input-files", value<std::vector<String>>(), "");
|
2017-09-06 02:36:00 +00:00
|
|
|
|
|
|
|
/// But they will be legit, though. And they must be given without name
|
|
|
|
boost::program_options::positional_options_description positional;
|
|
|
|
positional.add("input-files", -1);
|
|
|
|
|
|
|
|
boost::program_options::options_description cmdline_options;
|
|
|
|
cmdline_options.add(desc).add(hidden);
|
|
|
|
|
|
|
|
boost::program_options::variables_map options;
|
|
|
|
boost::program_options::store(
|
|
|
|
boost::program_options::command_line_parser(argc, argv).options(cmdline_options).positional(positional).run(), options);
|
|
|
|
boost::program_options::notify(options);
|
|
|
|
|
|
|
|
if (options.count("help"))
|
|
|
|
{
|
|
|
|
std::cout << "Usage: " << argv[0] << " [options] [test_file ...] [tests_folder]\n";
|
|
|
|
std::cout << desc << "\n";
|
|
|
|
return 0;
|
|
|
|
}
|
2017-05-05 11:36:55 +00:00
|
|
|
|
2017-09-06 02:36:00 +00:00
|
|
|
Strings input_files;
|
|
|
|
bool recursive = options.count("recursive");
|
|
|
|
|
|
|
|
if (!options.count("input-files"))
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
2017-09-06 02:36:00 +00:00
|
|
|
std::cerr << "Trying to find test scenario files in the current folder...";
|
|
|
|
fs::path curr_dir(".");
|
|
|
|
|
|
|
|
getFilesFromDir(curr_dir, input_files, recursive);
|
|
|
|
|
|
|
|
if (input_files.empty())
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
2017-09-06 02:36:00 +00:00
|
|
|
std::cerr << std::endl;
|
2018-11-22 21:19:58 +00:00
|
|
|
throw DB::Exception("Did not find any xml files", DB::ErrorCodes::BAD_ARGUMENTS);
|
2017-05-05 11:36:55 +00:00
|
|
|
}
|
2017-09-06 02:36:00 +00:00
|
|
|
else
|
|
|
|
std::cerr << " found " << input_files.size() << " files." << std::endl;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
input_files = options["input-files"].as<Strings>();
|
|
|
|
Strings collected_files;
|
2017-05-05 11:36:55 +00:00
|
|
|
|
2017-09-06 02:36:00 +00:00
|
|
|
for (const String filename : input_files)
|
2017-05-05 11:36:55 +00:00
|
|
|
{
|
2017-09-06 02:36:00 +00:00
|
|
|
fs::path file(filename);
|
2017-05-05 18:32:38 +00:00
|
|
|
|
2017-09-06 02:36:00 +00:00
|
|
|
if (!fs::exists(file))
|
2018-11-22 21:19:58 +00:00
|
|
|
throw DB::Exception("File '" + filename + "' does not exist", DB::ErrorCodes::FILE_DOESNT_EXIST);
|
2017-05-05 18:32:38 +00:00
|
|
|
|
2017-09-06 02:36:00 +00:00
|
|
|
if (fs::is_directory(file))
|
2017-06-21 14:19:05 +00:00
|
|
|
{
|
2017-09-06 02:36:00 +00:00
|
|
|
getFilesFromDir(file, collected_files, recursive);
|
2017-06-21 14:19:05 +00:00
|
|
|
}
|
|
|
|
else
|
2017-05-05 18:32:38 +00:00
|
|
|
{
|
2017-09-06 02:36:00 +00:00
|
|
|
if (file.extension().string() != ".xml")
|
2018-11-22 21:19:58 +00:00
|
|
|
throw DB::Exception("File '" + filename + "' does not have .xml extension", DB::ErrorCodes::BAD_ARGUMENTS);
|
2017-09-06 02:36:00 +00:00
|
|
|
collected_files.push_back(filename);
|
2017-05-05 18:32:38 +00:00
|
|
|
}
|
2017-05-05 11:36:55 +00:00
|
|
|
}
|
|
|
|
|
2017-09-06 02:36:00 +00:00
|
|
|
input_files = std::move(collected_files);
|
2017-05-05 11:36:55 +00:00
|
|
|
}
|
|
|
|
|
2017-09-06 02:36:00 +00:00
|
|
|
Strings tests_tags = options.count("tags") ? options["tags"].as<Strings>() : Strings({});
|
|
|
|
Strings skip_tags = options.count("skip-tags") ? options["skip-tags"].as<Strings>() : Strings({});
|
|
|
|
Strings tests_names = options.count("names") ? options["names"].as<Strings>() : Strings({});
|
|
|
|
Strings skip_names = options.count("skip-names") ? options["skip-names"].as<Strings>() : Strings({});
|
|
|
|
Strings tests_names_regexp = options.count("names-regexp") ? options["names-regexp"].as<Strings>() : Strings({});
|
|
|
|
Strings skip_names_regexp = options.count("skip-names-regexp") ? options["skip-names-regexp"].as<Strings>() : Strings({});
|
|
|
|
|
2018-03-12 20:25:18 +00:00
|
|
|
auto timeouts = DB::ConnectionTimeouts::getTCPTimeoutsWithoutFailover(DB::Settings());
|
2018-01-10 00:09:22 +00:00
|
|
|
|
2018-09-06 18:05:33 +00:00
|
|
|
DB::UseSSL use_ssl;
|
|
|
|
|
2018-11-28 21:21:22 +00:00
|
|
|
DB::PerformanceTest performance_test(
|
2018-11-28 15:31:09 +00:00
|
|
|
options["host"].as<String>(),
|
2017-09-06 02:36:00 +00:00
|
|
|
options["port"].as<UInt16>(),
|
2018-11-28 15:31:09 +00:00
|
|
|
options.count("secure"),
|
2017-09-06 02:36:00 +00:00
|
|
|
options["database"].as<String>(),
|
|
|
|
options["user"].as<String>(),
|
|
|
|
options["password"].as<String>(),
|
|
|
|
options.count("lite") > 0,
|
|
|
|
options["profiles-file"].as<String>(),
|
|
|
|
std::move(input_files),
|
|
|
|
std::move(tests_tags),
|
|
|
|
std::move(skip_tags),
|
|
|
|
std::move(tests_names),
|
|
|
|
std::move(skip_names),
|
|
|
|
std::move(tests_names_regexp),
|
2018-01-10 00:09:22 +00:00
|
|
|
std::move(skip_names_regexp),
|
|
|
|
timeouts);
|
2018-11-28 21:21:22 +00:00
|
|
|
return performance_test.run();
|
2017-01-13 18:26:51 +00:00
|
|
|
}
|
2017-09-06 02:36:00 +00:00
|
|
|
catch (...)
|
|
|
|
{
|
|
|
|
std::cout << DB::getCurrentExceptionMessage(/*with stacktrace = */ true) << std::endl;
|
|
|
|
int code = DB::getCurrentExceptionCode();
|
|
|
|
return code ? code : 1;
|
|
|
|
}
|