Skip to content

Commit 19c7dcd

Browse files
pongadcallmehiphop
authored andcommitted
bigquery: add simple benchmarks (#2666)
1 parent 3a20e26 commit 19c7dcd

4 files changed

Lines changed: 103 additions & 1 deletion

File tree

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# BigQuery Benchmark
2+
This directory contains benchmarks for BigQuery client.
3+
4+
## Usage
5+
`node bench.js queries.json`
6+
7+
BigQuery service caches requests so the benchmark should be run
8+
at least twice, disregarding the first result.
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*!
2+
* Copyright 2017 Google Inc. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
'use strict';
18+
19+
const async = require('async');
20+
const fs = require('fs');
21+
const BigQuery = require('../src/index.js');
22+
const env = require('../../../system-test/env.js');
23+
24+
if (process.argv.length < 3) {
25+
throw new Error(`need query file; ` +
26+
`usage: '${process.argv[0]} ${process.argv[1]} <queries.json>'`);
27+
}
28+
29+
var queryJson = fs.readFileSync(process.argv[2]);
30+
var queries = JSON.parse(queryJson);
31+
var client = new BigQuery(env);
32+
33+
var doQuery = function(queryTxt, callback) {
34+
var startMilli = new Date().getTime();
35+
var numRows = 0;
36+
var numCols;
37+
var timeFirstByteMilli;
38+
39+
var query = {
40+
query: queryTxt,
41+
useLegacySql: false
42+
};
43+
44+
client
45+
.createQueryStream(query)
46+
.on('error', callback)
47+
.on('data', function(row) {
48+
if (numRows === 0) {
49+
numCols = Object.keys(row).length;
50+
timeFirstByteMilli = new Date().getTime() - startMilli;
51+
} else if (numCols !== Object.keys(row).length) {
52+
this.end();
53+
54+
var receivedCols = Object.keys(row).length;
55+
var error = new Error(
56+
`query "${queryTxt}": ` +
57+
`wrong number of columns, want ${numCols} got ${receivedCols}`
58+
);
59+
60+
callback(error);
61+
}
62+
numRows++;
63+
})
64+
.on('end', function() {
65+
var timeTotalMilli = new Date().getTime() - startMilli;
66+
67+
console.log(
68+
`query ${queryTxt}:`,
69+
`got ${numRows} rows,`,
70+
`${numCols} cols,`,
71+
`first byte ${timeFirstByteMilli / 1000} sec,`,
72+
`total ${timeTotalMilli / 1000} sec`
73+
);
74+
75+
callback(null);
76+
});
77+
};
78+
79+
async.eachSeries(queries, doQuery, err => {
80+
if (err) {
81+
console.error(err);
82+
}
83+
});
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[
2+
"SELECT * FROM `nyc-tlc.yellow.trips` LIMIT 10000",
3+
"SELECT * FROM `nyc-tlc.yellow.trips` LIMIT 100000",
4+
"SELECT * FROM `nyc-tlc.yellow.trips` LIMIT 1000000",
5+
"SELECT title FROM `bigquery-public-data.samples.wikipedia` ORDER BY title LIMIT 1000",
6+
"SELECT title, id, timestamp, contributor_ip FROM `bigquery-public-data.samples.wikipedia` WHERE title like 'Blo%' ORDER BY id",
7+
"SELECT * FROM `bigquery-public-data.baseball.games_post_wide` ORDER BY gameId",
8+
"SELECT * FROM `bigquery-public-data.samples.github_nested` WHERE repository.has_downloads ORDER BY repository.created_at LIMIT 10000",
9+
"SELECT repo_name, path FROM `bigquery-public-data.github_repos.files` WHERE path LIKE '%.java' ORDER BY id LIMIT 1000000"
10+
]

packages/bigquery/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@
7171
"scripts": {
7272
"publish-module": "node ../../scripts/publish.js bigquery",
7373
"test": "mocha test/*.js",
74-
"system-test": "mocha system-test/*.js --no-timeouts --bail"
74+
"system-test": "mocha system-test/*.js --no-timeouts --bail",
75+
"benchmark": "time node benchmark/bench.js benchmark/queries.json"
7576
},
7677
"license": "Apache-2.0",
7778
"engines": {

0 commit comments

Comments
 (0)