Skip to content

Commit 7a77b6b

Browse files
committed
bigquery: add simple benchmarks
Benchmarks make various queries and measure 1. how long until we get the first row 2. how long we need to go through all rows
1 parent 9ecca41 commit 7a77b6b

4 files changed

Lines changed: 88 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: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*!
2+
* Copyright 2014 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+
const util = require('util');
18+
const fs = require('fs');
19+
const BigQuery = require('../src/index.js');
20+
21+
if (process.argv.length < 3) {
22+
throw util.format("need query file; usage: '%s %s <queries.json>'", process.argv[0], process.argv[1]);
23+
}
24+
var queryJson = fs.readFileSync(process.argv[2]);
25+
var queries = JSON.parse(queryJson);
26+
var client = BigQuery();
27+
28+
var doQuery = function(queryTxt) {
29+
var startMilli = new Date().getTime();
30+
var numRows = 0;
31+
var numCols;
32+
var timeFirstByteMilli;
33+
34+
var query = {
35+
query: queryTxt,
36+
useLegacySql: false
37+
};
38+
39+
client.createQueryStream(query)
40+
.on('error', function(err) {
41+
throw err;
42+
})
43+
.on('data', function(row) {
44+
if (numRows == 0) {
45+
numCols = Object.keys(row).length;
46+
timeFirstByteMilli = new Date().getTime() - startMilli;
47+
} else if (numCols != Object.keys(row).length) {
48+
throw util.format("query %j: wrong number of columns, want %d got %d",
49+
queryTxt,
50+
numCols,
51+
Object.keys(row).length);
52+
}
53+
numRows++;
54+
})
55+
.on('end', function() {
56+
timeTotalMilli = new Date().getTime() - startMilli;
57+
console.log(util.format("query %j: got %d rows, %d cols, first byte %d sec, total %d sec",
58+
queryTxt,
59+
numRows,
60+
numCols,
61+
timeFirstByteMilli/1000,
62+
timeTotalMilli/1000));
63+
});
64+
}
65+
66+
for (queryTxt of queries) {
67+
doQuery(queryTxt);
68+
}
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
@@ -70,7 +70,8 @@
7070
"scripts": {
7171
"publish-module": "node ../../scripts/publish.js bigquery",
7272
"test": "mocha test/*.js",
73-
"system-test": "mocha system-test/*.js --no-timeouts --bail"
73+
"system-test": "mocha system-test/*.js --no-timeouts --bail",
74+
"benchmark": "time node benchmark/bench.js benchmark/queries.json"
7475
},
7576
"license": "Apache-2.0",
7677
"engines": {

0 commit comments

Comments
 (0)