diff --git a/phpunit-perf.xml.dist b/phpunit-perf.xml.dist index b817ae4d4925..576e4cdaf7d8 100644 --- a/phpunit-perf.xml.dist +++ b/phpunit-perf.xml.dist @@ -13,4 +13,7 @@ + + + diff --git a/tests/perf/BigQueryTest.php b/tests/perf/BigQueryTest.php new file mode 100644 index 000000000000..7e2879b53d14 --- /dev/null +++ b/tests/perf/BigQueryTest.php @@ -0,0 +1,78 @@ +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; + } +} diff --git a/tests/perf/LoggingPerfTestCase.php b/tests/perf/LoggingPerfTest.php similarity index 96% rename from tests/perf/LoggingPerfTestCase.php rename to tests/perf/LoggingPerfTest.php index e967f13480ae..2150a55d9a10 100644 --- a/tests/perf/LoggingPerfTestCase.php +++ b/tests/perf/LoggingPerfTest.php @@ -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; diff --git a/tests/perf/README.md b/tests/perf/README.md new file mode 100644 index 000000000000..699f35947221 --- /dev/null +++ b/tests/perf/README.md @@ -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= +``` + +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 +``` diff --git a/tests/perf/fixtures/bigquery.json b/tests/perf/fixtures/bigquery.json new file mode 100644 index 000000000000..ab6e6c5f82ad --- /dev/null +++ b/tests/perf/fixtures/bigquery.json @@ -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" +]