diff --git a/docs/en/operations/utilities/clickhouse-benchmark.md b/docs/en/operations/utilities/clickhouse-benchmark.md index f948630b7bb..9c90ba7f028 100644 --- a/docs/en/operations/utilities/clickhouse-benchmark.md +++ b/docs/en/operations/utilities/clickhouse-benchmark.md @@ -9,6 +9,12 @@ Connects to a ClickHouse server and repeatedly sends specified queries. Syntax: +``` bash +$ clickhouse-benchmark --query ["single query"] [keys] +``` + +or + ``` bash $ echo "single query" | clickhouse-benchmark [keys] ``` @@ -34,6 +40,7 @@ clickhouse-benchmark [keys] < queries_file ## Keys {#clickhouse-benchmark-keys} +- `--query=WORD` - Query to execute. If this parameter is not passed clickhouse-benchmark will read queries from standard input. - `-c N`, `--concurrency=N` — Number of queries that `clickhouse-benchmark` sends simultaneously. Default value: 1. - `-d N`, `--delay=N` — Interval in seconds between intermediate reports (set 0 to disable reports). Default value: 1. - `-h WORD`, `--host=WORD` — Server host. Default value: `localhost`. For the [comparison mode](#clickhouse-benchmark-comparison-mode) you can use multiple `-h` keys. diff --git a/programs/benchmark/Benchmark.cpp b/programs/benchmark/Benchmark.cpp index a383a06ade0..8c69a545017 100644 --- a/programs/benchmark/Benchmark.cpp +++ b/programs/benchmark/Benchmark.cpp @@ -60,13 +60,13 @@ public: const String & user_, const String & password_, const String & stage, bool randomize_, size_t max_iterations_, double max_time_, const String & json_path_, size_t confidence_, - const String & query_id_, bool continue_on_errors_, + const String & query_id_, const String & query_to_execute_, bool continue_on_errors_, bool print_stacktrace_, const Settings & settings_) : concurrency(concurrency_), delay(delay_), queue(concurrency), randomize(randomize_), cumulative(cumulative_), max_iterations(max_iterations_), max_time(max_time_), json_path(json_path_), confidence(confidence_), query_id(query_id_), - continue_on_errors(continue_on_errors_), + query_to_execute(query_to_execute_), continue_on_errors(continue_on_errors_), print_stacktrace(print_stacktrace_), settings(settings_), shared_context(Context::createShared()), global_context(Context::createGlobal(shared_context.get())), pool(concurrency) @@ -150,7 +150,8 @@ private: double max_time; String json_path; size_t confidence; - std::string query_id; + String query_id; + String query_to_execute; bool continue_on_errors; bool print_stacktrace; const Settings & settings; @@ -213,20 +214,28 @@ private: void readQueries() { - ReadBufferFromFileDescriptor in(STDIN_FILENO); - - while (!in.eof()) + if (query_to_execute.empty()) { - std::string query; - readText(query, in); - assertChar('\n', in); + ReadBufferFromFileDescriptor in(STDIN_FILENO); - if (!query.empty()) - queries.emplace_back(query); + while (!in.eof()) + { + String query; + readText(query, in); + assertChar('\n', in); + + if (!query.empty()) + queries.emplace_back(std::move(query)); + } + + if (queries.empty()) + throw Exception("Empty list of queries.", ErrorCodes::EMPTY_DATA_PASSED); + } + else + { + queries.emplace_back(query_to_execute); } - if (queries.empty()) - throw Exception("Empty list of queries.", ErrorCodes::EMPTY_DATA_PASSED); std::cerr << "Loaded " << queries.size() << " queries.\n"; } @@ -559,6 +568,7 @@ int mainEntryClickHouseBenchmark(int argc, char ** argv) boost::program_options::options_description desc = createOptionsDescription("Allowed options", getTerminalWidth()); desc.add_options() ("help", "produce help message") + ("query", value()->default_value(""), "query to execute") ("concurrency,c", value()->default_value(1), "number of parallel queries") ("delay,d", value()->default_value(1), "delay between intermediate reports in seconds (set 0 to disable reports)") ("stage", value()->default_value("complete"), "request query processing up to specified stage: complete,fetch_columns,with_mergeable_state,with_mergeable_state_after_aggregation") @@ -625,6 +635,7 @@ int mainEntryClickHouseBenchmark(int argc, char ** argv) options["json"].as(), options["confidence"].as(), options["query_id"].as(), + options["query"].as(), options.count("continue_on_errors") > 0, print_stacktrace, settings); diff --git a/tests/queries/0_stateless/01304_direct_io.sh b/tests/queries/0_stateless/01304_direct_io.sh index 244e4c6e02d..0126a9525ed 100755 --- a/tests/queries/0_stateless/01304_direct_io.sh +++ b/tests/queries/0_stateless/01304_direct_io.sh @@ -13,5 +13,7 @@ $CLICKHOUSE_BENCHMARK --iterations 10 --max_threads 100 --min_bytes_to_use_direc cat "$CLICKHOUSE_TMP"/err | grep Exception cat "$CLICKHOUSE_TMP"/err | grep Loaded +rm "$CLICKHOUSE_TMP"/err + $CLICKHOUSE_CLIENT --multiquery --query " DROP TABLE bug;" diff --git a/tests/queries/0_stateless/01600_benchmark_query.reference b/tests/queries/0_stateless/01600_benchmark_query.reference new file mode 100644 index 00000000000..ec7a223ddc2 --- /dev/null +++ b/tests/queries/0_stateless/01600_benchmark_query.reference @@ -0,0 +1 @@ +Loaded 1 queries. diff --git a/tests/queries/0_stateless/01600_benchmark_query.sh b/tests/queries/0_stateless/01600_benchmark_query.sh new file mode 100755 index 00000000000..6b40b4464c7 --- /dev/null +++ b/tests/queries/0_stateless/01600_benchmark_query.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env bash + +CURDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) +. "$CURDIR"/../shell_config.sh + +$CLICKHOUSE_BENCHMARK --iterations 10 --query "SELECT 1" 1>/dev/null 2>"$CLICKHOUSE_TMP"/err + +cat "$CLICKHOUSE_TMP"/err | grep Exception +cat "$CLICKHOUSE_TMP"/err | grep Loaded + +rm "$CLICKHOUSE_TMP"/err