-
-
Notifications
You must be signed in to change notification settings - Fork 62
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
Initial implementation of benchmarks #60
Conversation
.travis.yml
Outdated
@@ -69,6 +69,8 @@ before_script: | |||
script: | |||
- phpdbg -qrr vendor/bin/phpunit --coverage-text --coverage-clover build/logs/clover.xml | |||
- PHP_CS_FIXER_IGNORE_ENV=1 php vendor/bin/php-cs-fixer --diff --dry-run -v fix | |||
- chmod +x benchmarks/bin/php_no_xdebug |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just commit the file go Git with chmod +x
and it will be fine. No need to run this each time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you. Never used this feature :) Fixed
.travis.yml
Outdated
@@ -69,6 +69,8 @@ before_script: | |||
script: | |||
- phpdbg -qrr vendor/bin/phpunit --coverage-text --coverage-clover build/logs/clover.xml | |||
- PHP_CS_FIXER_IGNORE_ENV=1 php vendor/bin/php-cs-fixer --diff --dry-run -v fix | |||
- chmod +x benchmarks/bin/php_no_xdebug | |||
- PATH=$PATH:$(pwd)/benchmarks/bin vendor/bin/phpbench run --report=aggregate |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure we have to run that for each build job. It's probably better to have a matrix that separates builds which run (unit) tests and then only one job (one PHP version is enough) to run these benchmarks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed. Fully agree :)
foreach (range(1, $this->maxQueries) as $i) { | ||
/** @var ResultSet $resultSet */ | ||
$resultSet = yield $connection->query("SELECT $i"); | ||
yield $resultSet->advance(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will fetch one row, while PDO fetches all rows.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed. Previously I have used fetchAll
, but in the new version it's not available.
benchmarks/QueryBench.php
Outdated
yield all(array_map(function ($resultSet) { | ||
/** @var ResultSet $resultSet */ | ||
return $resultSet->advance(); | ||
}, $resultSets)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can leave of the all
if you want, it will implicitly be applied if you yield an array of promises, but that's personal preference, just a hint if you didn't know.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you. Not sure, but probably a previous version of amp had required all
here. Cool, now much clearer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, 1.x didn't allow yielding array of promises.
benchmarks/bin/php_no_xdebug
Outdated
temporaryPath="$(mktemp -t php.XXXX).ini" | ||
|
||
# Using awk to ensure that files ending without newlines do not lead to configuration error | ||
php -i | grep "\.ini" | grep -o -e '\(/[a-z0-9._-]\+\)\+\.ini' | grep -v xdebug | xargs awk 'FNR==1{print ""}1' > "$temporaryPath" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no need for that on Travis at least:
Line 57 in 67f101e
- phpenv config-rm xdebug.ini || echo "No xdebug config." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As you suggested, now I remove all configuration with -n
, so think that there no need for this configuration anymore.
benchmarks/bin/php_no_xdebug
Outdated
# Using awk to ensure that files ending without newlines do not lead to configuration error | ||
php -i | grep "\.ini" | grep -o -e '\(/[a-z0-9._-]\+\)\+\.ini' | grep -v xdebug | xargs awk 'FNR==1{print ""}1' > "$temporaryPath" | ||
|
||
php -n -c "$temporaryPath" -dopcache.enable_cli=1 -dzend.assertions=-1 "$@" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about just doing -n
and not passing any config at all?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm... probably PDO
might not work, but let try :)
composer.json
Outdated
@@ -3,7 +3,8 @@ | |||
"description": "Asynchronous parallel Mysql client built on the Amp concurrency framework", | |||
"require": { | |||
"amphp/amp": "^2", | |||
"amphp/socket": "^0.10" | |||
"amphp/socket": "^0.10", | |||
"phpbench/phpbench": "^0.13.0" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should go into require-dev
, actually it's there, too, so delete it here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed. Probably during merge I have added this in both sections.
benchmarks/QueryBench.php
Outdated
wait(call(function() { | ||
$connection = $this->connectionPool; | ||
/** @var ResultSet[] $resultSets */ | ||
$resultSets = yield all(array_map(function ($i) use ($connection) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is also benching creating the connections to the database. Priming the pool would give more realistic benchmarks for a running application doing queries simultaneously.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@trowski I already have faced with this problem. To avoid such situation I have added @Warmup(1)
to create all needed connection during the first run and avoid connection overhead to be included in overall benchmark time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I copy the body of benchAsyncQueriesUsingPool
to init
, it reduces the time for the benchmark relative to the others significantly. Can you explain what's going on there?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@trowski in nutshell PHPBench does not count the time that was spent during init
execution.
To understand how it works need to describe how works Revs(revolutions), Iterations and BeforeMethods(read more http://phpbench.readthedocs.io/en/latest/writing-benchmarks.html)
During one Warmup(it is equivalent to one revolution) we create all needed connections in the pool(read more http://phpbench.readthedocs.io/en/latest/writing-benchmarks.html?highlight=Warmup)
@torinaki I think switching to stages could make the build way easier like https://travis-ci.org/FriendsOfPHP/PHP-CS-Fixer does it. |
@kelunik I did a migration to stages. The only issue is that I can't get build green due to unstable test: |
No, these tests should just be fixed. Could you add your new directory to Other than that, it looks pretty fine now. 👍 |
@kelunik done. Please check |
Thanks! |
I think it is important to see some benchmarks comparing with PDO due to pure PHP implementations usually are slow. It is important to know how much slower.
In case of the async driver, we can come up with a conclusion to use the async driver instead of PDO to get a performance boost by executing queries in an async way.
I'm proposing to run benchmarks right after each build to see the performance. Hope that in future PHP releases pure PHP driver implementation performance will be very close to PDO.
There is only one benchmark with simple query
SELECT $n
with following implementations: