Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions phpunit-perf.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,7 @@
</exclude>
</whitelist>
</filter>
<php>
<ini name="memory_limit" value="2048M"/>
</php>
</phpunit>
78 changes: 78 additions & 0 deletions tests/perf/BigQueryTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?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 = 'bigquery.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__ .'/fixtures/'. self::SOURCE), true);
foreach ($queries as $key => $q) {
$queries[$key] = is_array($q)
? $q
: [$q];
}

return $queries;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@
use Google\Cloud\Logging\LoggingClient;
use Google\Cloud\Logging\PsrLogger;

class LoggingPerfTestCase extends \PHPUnit_Framework_TestCase
/**
* @group logging
*/
class LoggingPerfTest extends \PHPUnit_Framework_TestCase
{
/* @var PsrLogger */
private $restClient;
Expand Down
29 changes: 29 additions & 0 deletions tests/perf/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
## Performance Tests

Some services contained in Google Cloud PHP provide a performance test, to allow
Google engineers and others to measure the performance of a client library.

Like other test suites in Google Cloud PHP, performance tests are implemented
using PHPUnit. Due to the memory-intensive nature of many of these tests, however,
and the time required to run all tests, it is recommended that you use the test
group feature to run only the tests required at a given time.

Running the tests is easy, once you have cloned the repository and run
`composer install` to install all required dependencies.

From the repository root, run the following command:

```sh
$ vendor/bin/phpunit -c phpunit-perf.xml.dist --group=<group-name>
```

The group name can be identified by opening a test file (i.e.
`tests/perf/BigQueryTest.php`), and looking for the `@group` annotation found
immediately before the class declaration:

```php
/**
* @group bigquery
*/
class BigQueryTest extends \PHPUnit_Framework_TestCase
```
10 changes: 10 additions & 0 deletions tests/perf/fixtures/bigquery.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"
]