Skip to content

Commit

Permalink
bigquery: add simple benchmarks
Browse files Browse the repository at this point in the history
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
  • Loading branch information
pongad committed Oct 11, 2017
1 parent 9ecca41 commit 7a77b6b
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 1 deletion.
8 changes: 8 additions & 0 deletions packages/bigquery/benchmark/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# BigQuery Benchmark
This directory contains benchmarks for BigQuery client.

## Usage
`node bench.js queries.json`

BigQuery service caches requests so the benchmark should be run
at least twice, disregarding the first result.
68 changes: 68 additions & 0 deletions packages/bigquery/benchmark/bench.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*!
* Copyright 2014 Google Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

const util = require('util');
const fs = require('fs');
const BigQuery = require('../src/index.js');

if (process.argv.length < 3) {
throw util.format("need query file; usage: '%s %s <queries.json>'", process.argv[0], process.argv[1]);
}
var queryJson = fs.readFileSync(process.argv[2]);
var queries = JSON.parse(queryJson);
var client = BigQuery();

var doQuery = function(queryTxt) {
var startMilli = new Date().getTime();
var numRows = 0;
var numCols;
var timeFirstByteMilli;

var query = {
query: queryTxt,
useLegacySql: false
};

client.createQueryStream(query)
.on('error', function(err) {
throw err;
})
.on('data', function(row) {
if (numRows == 0) {
numCols = Object.keys(row).length;
timeFirstByteMilli = new Date().getTime() - startMilli;
} else if (numCols != Object.keys(row).length) {
throw util.format("query %j: wrong number of columns, want %d got %d",
queryTxt,
numCols,
Object.keys(row).length);
}
numRows++;
})
.on('end', function() {
timeTotalMilli = new Date().getTime() - startMilli;
console.log(util.format("query %j: got %d rows, %d cols, first byte %d sec, total %d sec",
queryTxt,
numRows,
numCols,
timeFirstByteMilli/1000,
timeTotalMilli/1000));
});
}

for (queryTxt of queries) {
doQuery(queryTxt);
}
10 changes: 10 additions & 0 deletions packages/bigquery/benchmark/queries.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[
"SELECT * FROM `nyc-tlc.yellow.trips` LIMIT 10000",
"SELECT * FROM `nyc-tlc.yellow.trips` LIMIT 100000",
"SELECT * FROM `nyc-tlc.yellow.trips` LIMIT 1000000",
"SELECT title FROM `bigquery-public-data.samples.wikipedia` ORDER BY title LIMIT 1000",
"SELECT title, id, timestamp, contributor_ip FROM `bigquery-public-data.samples.wikipedia` WHERE title like 'Blo%' ORDER BY id",
"SELECT * FROM `bigquery-public-data.baseball.games_post_wide` ORDER BY gameId",
"SELECT * FROM `bigquery-public-data.samples.github_nested` WHERE repository.has_downloads ORDER BY repository.created_at LIMIT 10000",
"SELECT repo_name, path FROM `bigquery-public-data.github_repos.files` WHERE path LIKE '%.java' ORDER BY id LIMIT 1000000"
]
3 changes: 2 additions & 1 deletion packages/bigquery/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@
"scripts": {
"publish-module": "node ../../scripts/publish.js bigquery",
"test": "mocha test/*.js",
"system-test": "mocha system-test/*.js --no-timeouts --bail"
"system-test": "mocha system-test/*.js --no-timeouts --bail",
"benchmark": "time node benchmark/bench.js benchmark/queries.json"
},
"license": "Apache-2.0",
"engines": {
Expand Down

0 comments on commit 7a77b6b

Please sign in to comment.