-
Notifications
You must be signed in to change notification settings - Fork 451
bigquery: add simple benchmarks #703
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
It runs a series of queries and report 1. How long until we get the first result back 2. How long we take to iterate through all results
|
Very nice, thanks @pongad! We have a similar benchmarking test for logging located at: https://github.com/GoogleCloudPlatform/google-cloud-php/tree/master/tests/perf. WDYT about having this benchmark live there as well? |
|
@dwsupplee Sounds good, thank you for letting me know |
|
@dwsupplee PTAL |
|
Hi @pongad, I took the liberty of modifying your test file to work as a PHPUnit test case (the test runner we use for all our test suites). I also modified things a bit to work with the latest changes in master (from our changes to BigQuery introduced in #686). Please take a look and tell me what you think.
<?php
/**
* Copyright 2017 Google Inc.
*
* 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.
*/
namespace Google\Cloud\Tests\Perf;
use Google\Cloud\BigQuery\BigQueryClient;
/**
* @group bigquery
*/
class BigQueryPerfTest extends \PHPUnit_Framework_TestCase
{
const SOURCE = 'queries.json';
private $client;
public function setUp()
{
$keyFilePath = getenv('GOOGLE_CLOUD_PHP_TESTS_KEY_PATH');
$this->client = new BigQueryClient([
'keyFilePath' => $keyFilePath
]);
}
/**
* @dataProvider queries
* @runInSeparateProcess
*/
public function testPerf($query)
{
$start = microtime(true);
$config = $this->client->query($query);
$queryResults = $this->client->runQuery($config);
$rows = 0;
$cols = 0;
$firstByteDur = 0;
foreach ($queryResults as $row) {
$rows++;
if ($cols == 0) {
$firstByteDur = microtime(true) - $start;
$cols = count($row);
} elseif ($cols != count($row)) {
throw new Exception("expected $cols cols, found " . count($row));
}
}
$totalDur = microtime(true)-$start;
echo "query $query: $rows rows, $cols cols, first byte $firstByteDur, total $totalDur" . PHP_EOL;
}
public function queries()
{
$queries = json_decode(file_get_contents(__DIR__ .'/'. self::SOURCE), true);
foreach ($queries as $key => $q) {
$queries[$key] = [$q];
}
return $queries;
}
}To run: |
|
note: to get this working, I had to bump up the PHP process memory limit by modifying <?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="./tests/perf/bootstrap.php" colors="true">
<testsuites>
<testsuite>
<directory>tests/perf</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">src</directory>
<exclude>
<directory suffix=".php">src/*/V[!a-zA-Z]*</directory>
</exclude>
</whitelist>
</filter>
<php>
<ini name="memory_limit" value="2048M"/>
</php>
</phpunit> |
|
@jdpedrie Thank you for picking up the work! A few comments.
|
|
|
@jdpedrie (1) sounds good to me. Sounds like you already made the changes and have this running right? Would you like to take over this PR? |
It runs a series of queries and report