||1 year ago|
|README.md||1 year ago|
|bench.php||1 year ago|
|common.php||1 year ago|
|generator.php||1 year ago|
|results.php||1 year ago|
|settings.ini||1 year ago|
Stupid simple db benchmarking utility.
pgbench, dbhammer, etc are all hard. I just need a ballpark idea of whether a database will fall over under a certain load and to get a order-of-magnitude idea of how it will perform.
bench.php-- fork a bunch of processes and run a bunch of queries against a database
results.php-- read the results that the workers have written out and provide aggregate statistics
- Right now this only supports Postgres. It would be trivial to modify to use anything else supported by PHP's PDO.
- It's very unscientific. Don't rely on this for anything more than a vague notion of how something is performing.
- The results script loads the entire set of queries + timings into RAM to process them. If you run this too long and generate too many results it will not be very performant or require a huge amount of RAM to actually generate the results.
- The results script uses the current settings file when calculating QPS, figuring out which worker files to read, etc. The settings.ini file should be kept alongside the results files if you plan on reprocessing them again later for any reason.
How do I use this?
$ mkdir test-1 $ cd test-1 $ cat > settings.ini workers=16 duration=30 [db] host=127.0.0.1 port=5432 username=postgres password=postgres database=my_database ^D $ cat > generator.php <?php return "select * from my_table where id=".mt_rand(1, 65000); ^D $ php path/to/bench.php generator.php [Worker 0] Start [Worker 1] Start [Worker 2] Start [Master] Start [Worker 3] Start [Worker 3] Stop [Worker 1] Stop [Worker 2] Stop [Master] Stop [Worker 0] Stop $ php path/to/results.php 5 percentile: 0.0417s 25 percentile: 0.042s 50 percentile: 0.0424s 75 percentile: 0.0431s 95 percentile: 0.0459s 99 percentile: 0.0505s QPS: 93.6 $
Set up test environment
The settings will be read from the current folder, and the results written back out to it. So probably create an empty folder to run it from.
- Create a
settings.inifile based off of the one included. Adjust workers/duration if desired. Configure your database's connection information.
- Create a generator file. This is just a plain PHP file that, at some point,
returns a SQL query to run.
workers=16 duration=30 [db] host=127.0.0.1 port=5432 username=postgres password=postgres database=my_database
<?php return "select * from my_table where id=".mt_rand(1, 65000);
Run the benchmarking tool.
$ php ~/path/to/bench.php [Worker 0] Start [Worker 1] Start [Worker 2] Start [Master] Start [Worker 3] Start [Worker 3] Stop [Worker 1] Stop [Worker 2] Stop [Master] Stop [Worker 0] Stop $
Results are written to
worker.<number>.csv. Each file will contain the query generated as well as the timing in
Run the results tool to aggregate all of the worker outputs.
$ php ~/path/to/results.php 5 percentile: 0.0417s 25 percentile: 0.042s 50 percentile: 0.0424s 75 percentile: 0.0431s 95 percentile: 0.0459s 99 percentile: 0.0505s QPS: 93.6
Copyright (c) 2020 Adam Pippin. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. All advertising materials mentioning features or use of this software must display the following acknowledgement: This product includes software developed by Adam Pippin. 4. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY COPYRIGHT HOLDER "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDER BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.