FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

impl(bigquery): Dataset Benchmark program (#12655) · comius/google-cloud-cpp@a773840 · GitHub

Commit a773840

Browse files
authored
impl(bigquery): Dataset Benchmark program (googleapis#12655)
1 parent 0452268 commit a773840

6 files changed

Lines changed: 450 additions & 100 deletions

File tree

‎google/cloud/bigquery/v2/minimal/benchmarks/benchmark.cc‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,13 @@ std::chrono::milliseconds ToChronoMillis(int m) {
9292
void Benchmark::PrintThroughputResult(std::ostream& os, std::string const&,
9393
std::string const& phase,
9494
BenchmarkResult const& result) {
95-
auto ops_throughput =
96-
1000 * result.operations.size() / result.elapsed.count();
97-
os << "# " << phase << " op throughput=" << ops_throughput << " ops/s\n";
95+
std::chrono::seconds elapsed =
96+
std::chrono::duration_cast<std::chrono::seconds>(result.elapsed);
97+
auto elapsed_dbl = static_cast<double>(elapsed.count());
98+
auto operations_size_dbl = static_cast<double>(result.operations.size());
99+
auto ops_throughput = operations_size_dbl / elapsed_dbl;
100+
os << "# " << phase << " op throughput=" << ops_throughput << " ops/s"
101+
<< std::endl;
98102
}
99103

100104
void Benchmark::PrintLatencyResult(std::ostream& os,
@@ -111,9 +115,7 @@ void Benchmark::PrintLatencyResult(std::ostream& os,
111115
});
112116

113117
auto const nsamples = result.operations.size();
114-
auto ops_throughput = 1000 * nsamples / result.elapsed.count();
115-
os << "# Test=" << test_name << ", " << operation
116-
<< " Throughput = " << ops_throughput << " ops/s, Latency And Status: ";
118+
os << "# Test=" << test_name << ", " << operation << ", Latency And Status: ";
117119
char const* sep = "";
118120
for (double p : kResultPercentiles) {
119121
auto index = static_cast<std::size_t>(

‎google/cloud/bigquery/v2/minimal/benchmarks/benchmark_test.cc‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,6 @@ TEST(BenchmarkTest, PrintLatencyResult) {
167167
Benchmark::PrintLatencyResult(os, "PrintLatencyResult", "Query", result);
168168
std::string output = os.str();
169169

170-
EXPECT_THAT(output, HasSubstr("Query Throughput = 100 ops/s"));
171170
EXPECT_THAT(output, HasSubstr("Latency And Status: p0=100us"));
172171
EXPECT_THAT(output, HasSubstr("p50=5.1ms"));
173172
EXPECT_THAT(output, HasSubstr("p90=9ms"));

‎google/cloud/bigquery/v2/minimal/benchmarks/benchmarks_config.cc‎

Lines changed: 156 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,19 @@ namespace cloud {
2828
namespace bigquery_v2_minimal_benchmarks {
2929
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
3030

31+
using ::google::cloud::StatusCode;
3132
using ::google::cloud::bigquery_v2_minimal_internal::Projection;
3233
using ::google::cloud::bigquery_v2_minimal_internal::StateFilter;
3334
using ::google::cloud::bigquery_v2_minimal_internal::TableMetadataView;
3435

3536
namespace {
3637

3738
auto invalid_argument = [](std::string msg) {
38-
return google::cloud::Status(google::cloud::StatusCode::kInvalidArgument,
39-
std::move(msg));
39+
return google::cloud::Status(StatusCode::kInvalidArgument, std::move(msg));
4040
};
4141

42+
auto status_ok = google::cloud::Status(StatusCode::kOk, "");
43+
4244
std::string GenerateJobId() {
4345
auto constexpr kJobPrefix = "bqOdbcJob_benchmark_test_";
4446
auto generator = google::cloud::internal::MakeDefaultPRNG();
@@ -92,11 +94,14 @@ std::string query_drop_request_body =
9294
std::ostream& PrintHelper(std::ostream& os, std::string const& endpoint,
9395
std::string const& project_id,
9496
std::string const& page_token, int max_results,
95-
int connection_pool_size) {
97+
int thread_count, int connection_pool_size,
98+
std::chrono::seconds const& test_duration) {
9699
return os << "\n# Endpoint: " << endpoint << "\n# Project: " << project_id
97100
<< "\n# Page Token: " << page_token
98101
<< "\n# Max Results: " << max_results
102+
<< "\n# Thread Count: " << thread_count
99103
<< "\n# Connection Size: " << connection_pool_size
104+
<< "\n# Test Duration (in seconds): " << test_duration.count()
100105
<< "\n# Compiler: " << google::cloud::internal::CompilerId() << "-"
101106
<< google::cloud::internal::CompilerVersion()
102107
<< "\n# Build Flags: " << google::cloud::internal::compiler_flags()
@@ -106,15 +111,17 @@ std::ostream& PrintHelper(std::ostream& os, std::string const& endpoint,
106111

107112
std::ostream& operator<<(std::ostream& os, Config const& config) {
108113
return PrintHelper(os, config.endpoint, config.project_id, config.page_token,
109-
config.max_results, config.connection_pool_size);
114+
config.max_results, config.thread_count,
115+
config.connection_pool_size, config.test_duration);
110116
}
111117

112118
std::ostream& operator<<(std::ostream& os, DatasetConfig const& config) {
113119
os << "\n# Dataset: " << config.dataset_id << "\n# All: " << config.all
114120
<< "\n# Filter: " << config.filter
115121
<< "\n# Page Token: " << config.page_token;
116122
return PrintHelper(os, config.endpoint, config.project_id, config.page_token,
117-
config.max_results, config.connection_pool_size);
123+
config.max_results, config.thread_count,
124+
config.connection_pool_size, config.test_duration);
118125
}
119126

120127
std::ostream& operator<<(std::ostream& os, TableConfig const& config) {
@@ -123,7 +130,8 @@ std::ostream& operator<<(std::ostream& os, TableConfig const& config) {
123130
<< "\n# View: " << config.view.value;
124131

125132
return PrintHelper(os, config.endpoint, config.project_id, config.page_token,
126-
config.max_results, config.connection_pool_size);
133+
config.max_results, config.thread_count,
134+
config.connection_pool_size, config.test_duration);
127135
}
128136

129137
std::ostream& operator<<(std::ostream& os, JobConfig const& config) {
@@ -136,22 +144,53 @@ std::ostream& operator<<(std::ostream& os, JobConfig const& config) {
136144
<< "\n# State Filter: " << config.state_filter.value;
137145

138146
return PrintHelper(os, config.endpoint, config.project_id, config.page_token,
139-
config.max_results, config.connection_pool_size);
147+
config.max_results, config.thread_count,
148+
config.connection_pool_size, config.test_duration);
149+
}
150+
151+
void Config::PrintUsage() {
152+
std::cout << "Usage Information: " << std::endl;
153+
std::cout << "Brief information about the flags is listed below. Please take "
154+
"a look at the Bigquery api docs "
155+
"(https://cloud.google.com/bigquery/docs/reference/rest) "
156+
"for more details information "
157+
"regarding api specific flags."
158+
<< std::endl;
159+
std::cout << std::endl;
160+
for (auto const& flag : flags_) {
161+
std::cout << flag.flag_name << "=>" << flag.flag_desc << std::endl;
162+
}
140163
}
141164

142-
void Config::ParseCommonFlags() {
165+
google::cloud::Status Config::ParseCommonArgs(
166+
std::vector<std::string> const& args) {
143167
flags_.push_back(
144-
{"--endpoint=", [this](std::string v) { endpoint = std::move(v); }});
168+
{"--wants-description=", "print benchmark description",
169+
[this](std::string const& v) { wants_description = (v == "true"); }});
145170
flags_.push_back(
146-
{"--project=", [this](std::string v) { project_id = std::move(v); }});
171+
{"--help=", "print usage information",
172+
[this](std::string const& v) { wants_help = (v == "true"); }});
173+
flags_.push_back({"--endpoint=", "the Bigquery api endpoint",
174+
[this](std::string v) { endpoint = std::move(v); }});
175+
flags_.push_back({"--project=", "the GCP project ID",
176+
[this](std::string v) { project_id = std::move(v); }});
177+
flags_.push_back({"--page-token=", "page token for multiple page results",
178+
[this](std::string v) { page_token = std::move(v); }});
147179
flags_.push_back(
148-
{"--page-token=", [this](std::string v) { page_token = std::move(v); }});
149-
flags_.push_back({"--connection-pool-size=", [this](std::string const& v) {
150-
connection_pool_size = std::stoi(v);
151-
}});
152-
flags_.push_back({"--maximum-results=", [this](std::string const& v) {
153-
max_results = std::stoi(v);
180+
{"--connection-pool-size=", "connection pool size for rest connections",
181+
[this](std::string const& v) { connection_pool_size = std::stoi(v); }});
182+
flags_.push_back(
183+
{"--maximum-results=", "the maximum results returned in a single page",
184+
[this](std::string const& v) { max_results = std::stoi(v); }});
185+
flags_.push_back(
186+
{"--thread-count=", "the number of threads to use for this benchmark",
187+
[this](std::string const& v) { thread_count = std::stoi(v); }});
188+
flags_.push_back({"--test-duration=", "the duration of this test",
189+
[this](std::string const& v) {
190+
test_duration = std::chrono::seconds(std::stoi(v));
154191
}});
192+
193+
return ValidateArgs(args);
155194
}
156195

157196
google::cloud::Status Config::ValidateArgs(
@@ -170,7 +209,11 @@ google::cloud::Status Config::ValidateArgs(
170209
}
171210
}
172211

173-
return google::cloud::Status(StatusCode::kOk, "");
212+
if (wants_description || wants_help) {
213+
exit_after_parse_ = true;
214+
}
215+
216+
return status_ok;
174217
}
175218

176219
google::cloud::StatusOr<Config> Config::ParseArgs(
@@ -180,13 +223,16 @@ google::cloud::StatusOr<Config> Config::ParseArgs(
180223
project_id =
181224
google::cloud::internal::GetEnv("GOOGLE_CLOUD_PROJECT").value_or("");
182225

183-
ParseCommonFlags();
184-
auto status = ValidateArgs(args);
185-
226+
auto status = ParseCommonArgs(args);
186227
if (!status.ok()) {
187228
return status;
188229
}
189230
}
231+
232+
if (ExitAfterParse()) {
233+
return *this;
234+
}
235+
190236
if (project_id.empty()) {
191237
return invalid_argument(
192238
"The project id is not set, provide a value in the --project flag,"
@@ -213,16 +259,21 @@ google::cloud::StatusOr<Config> Config::ParseArgs(
213259

214260
google::cloud::StatusOr<DatasetConfig> DatasetConfig::ParseArgs(
215261
std::vector<std::string> const& args) {
216-
ParseCommonFlags();
217-
flags_.push_back(
218-
{"--dataset=", [this](std::string v) { dataset_id = std::move(v); }});
262+
ParseCommonArgs(args);
263+
264+
flags_.push_back({"--dataset=", "the Bigquery Dataset ID",
265+
[this](std::string v) { dataset_id = std::move(v); }});
219266
flags_.push_back(
220-
{"--filter=", [this](std::string v) { filter = std::move(v); }});
267+
{"--filter=", "the Dataset filter to filter the results by label",
268+
[this](std::string v) { filter = std::move(v); }});
221269
flags_.push_back(
222-
{"--all=", [this](std::string const& v) { all = (v == "true"); }});
270+
{"--all=", "whether to list all datasets, including hidden ones",
271+
[this](std::string const& v) { all = (v == "true"); }});
223272

273+
if (ExitAfterParse()) {
274+
return *this;
275+
}
224276
auto status = ValidateArgs(args);
225-
226277
if (!status.ok()) {
227278
return status;
228279
}
@@ -237,14 +288,19 @@ google::cloud::StatusOr<DatasetConfig> DatasetConfig::ParseArgs(
237288

238289
google::cloud::StatusOr<TableConfig> TableConfig::ParseArgs(
239290
std::vector<std::string> const& args) {
240-
ParseCommonFlags();
241-
flags_.push_back(
242-
{"--dataset=", [this](std::string v) { dataset_id = std::move(v); }});
291+
ParseCommonArgs(args);
292+
293+
flags_.push_back({"--dataset=", "the Dataset ID of the requested table",
294+
[this](std::string v) { dataset_id = std::move(v); }});
295+
flags_.push_back({"--table=", "the Table ID of the requested table",
296+
[this](std::string v) { table_id = std::move(v); }});
243297
flags_.push_back(
244-
{"--table=", [this](std::string v) { table_id = std::move(v); }});
245-
flags_.push_back({"--selected-fields=",
246-
[this](std::string v) { selected_fields = std::move(v); }});
247-
flags_.push_back({"--view=", [this](std::string const& v) {
298+
{"--selected-fields=", "list of table schema fields to return",
299+
[this](std::string v) { selected_fields = std::move(v); }});
300+
flags_.push_back({"--view=",
301+
"specifies the view that determines which table "
302+
"information is returned.",
303+
[this](std::string const& v) {
248304
if (v == "TABLE_METADATA_VIEW_UNSPECIFIED") {
249305
view = TableMetadataView::UnSpecified();
250306
} else if (v == "BASIC") {
@@ -256,8 +312,11 @@ google::cloud::StatusOr<TableConfig> TableConfig::ParseArgs(
256312
}
257313
}});
258314

259-
auto status = ValidateArgs(args);
315+
if (ExitAfterParse()) {
316+
return *this;
317+
}
260318

319+
auto status = ValidateArgs(args);
261320
if (!status.ok()) {
262321
return status;
263322
}
@@ -277,55 +336,72 @@ google::cloud::StatusOr<TableConfig> TableConfig::ParseArgs(
277336

278337
google::cloud::StatusOr<JobConfig> JobConfig::ParseArgs(
279338
std::vector<std::string> const& args) {
280-
ParseCommonFlags();
281-
flags_.push_back(
282-
{"--job=", [this](std::string v) { job_id = std::move(v); }});
283-
flags_.push_back(
284-
{"--location=", [this](std::string v) { location = std::move(v); }});
339+
ParseCommonArgs(args);
340+
341+
flags_.push_back({"--job=", "the Job ID of the requested job.",
342+
[this](std::string v) { job_id = std::move(v); }});
343+
flags_.push_back({"--location=", "the geographic location of the job",
344+
[this](std::string v) { location = std::move(v); }});
285345
flags_.push_back({"--parent-job-id=",
346+
"if set, show only child jobs of the specified parent",
286347
[this](std::string v) { parent_job_id = std::move(v); }});
287-
flags_.push_back({"--all-users=", [this](std::string const& v) {
288-
all_users = (v == "true");
289-
}});
290-
flags_.push_back({"--dry-run=",
348+
flags_.push_back(
349+
{"--all-users=",
350+
"whether to display jobs owned by all users in the project",
351+
[this](std::string const& v) { all_users = (v == "true"); }});
352+
flags_.push_back({"--dry-run=", "dry run mode",
291353
[this](std::string const& v) { dry_run = (v == "true"); }});
292-
flags_.push_back({"--query-create-replace=", [this](std::string const& v) {
293-
query_create_replace = (v == "true");
294-
}});
295-
flags_.push_back({"--query-drop=", [this](std::string const& v) {
296-
query_drop = (v == "true");
297-
}});
298-
flags_.push_back({"--use-int64-timestamp=", [this](std::string const& v) {
299-
use_int64_timestamp = (v == "true");
300-
}});
301-
flags_.push_back({"--min-creation-time=", [this](std::string v) {
302-
min_creation_time = std::move(v);
303-
}});
304-
flags_.push_back({"--max-creation-time=", [this](std::string v) {
305-
max_creation_time = std::move(v);
306-
}});
307-
flags_.push_back({"--timeout-ms=", [this](std::string const& v) {
308-
timeout_ms = std::stoi(v);
309-
}});
310-
flags_.push_back({"--start-index=", [this](std::string const& v) {
311-
start_index = std::stoi(v);
312-
}});
313-
flags_.push_back({"--projection=", [this](std::string const& v) {
314-
if (v == "MINIMAL") {
315-
projection = Projection::Minimal();
316-
} else if (v == "FULL") {
317-
projection = Projection::Full();
318-
}
319-
}});
320-
flags_.push_back({"--state-filter=", [this](std::string const& v) {
321-
if (v == "RUNNING") {
322-
state_filter = StateFilter::Running();
323-
} else if (v == "PENDING") {
324-
state_filter = StateFilter::Pending();
325-
} else if (v == "DONE") {
326-
state_filter = StateFilter::Done();
327-
}
328-
}});
354+
flags_.push_back(
355+
{"--query-create-replace=", "whether to execute create-replace stmt",
356+
[this](std::string const& v) { query_create_replace = (v == "true"); }});
357+
flags_.push_back(
358+
{"--query-drop=", "whether to execute drop stmt",
359+
[this](std::string const& v) { query_drop = (v == "true"); }});
360+
flags_.push_back(
361+
{"--use-int64-timestamp=", "outputs timestamp as usec int64",
362+
[this](std::string const& v) { use_int64_timestamp = (v == "true"); }});
363+
flags_.push_back(
364+
{"--min-creation-time=",
365+
"min job creation time. If set, only jobs created after or at this "
366+
"timestamp are returned",
367+
[this](std::string v) { min_creation_time = std::move(v); }});
368+
flags_.push_back(
369+
{"--max-creation-time=",
370+
"max job creation time. If set, only jobs created before or at this "
371+
"timestamp are returned",
372+
[this](std::string v) { max_creation_time = std::move(v); }});
373+
flags_.push_back(
374+
{"--timeout-ms=",
375+
"specifies the maximum amount of time, in milliseconds, that the client "
376+
"is willing to wait for the query to complete",
377+
[this](std::string const& v) { timeout_ms = std::stoi(v); }});
378+
flags_.push_back(
379+
{"--start-index=", "zero-based index of the starting row",
380+
[this](std::string const& v) { start_index = std::stoi(v); }});
381+
flags_.push_back(
382+
{"--projection=",
383+
"restricts information returned to a set of selected fields",
384+
[this](std::string const& v) {
385+
if (v == "MINIMAL") {
386+
projection = Projection::Minimal();
387+
} else if (v == "FULL") {
388+
projection = Projection::Full();
389+
}
390+
}});
391+
flags_.push_back(
392+
{"--state-filter=", "filter for job state", [this](std::string const& v) {
393+
if (v == "RUNNING") {
394+
state_filter = StateFilter::Running();
395+
} else if (v == "PENDING") {
396+
state_filter = StateFilter::Pending();
397+
} else if (v == "DONE") {
398+
state_filter = StateFilter::Done();
399+
}
400+
}});
401+
402+
if (ExitAfterParse()) {
403+
return *this;
404+
}
329405

330406
auto status = ValidateArgs(args);
331407
if (!status.ok()) {

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL