# dbbench Stupid simple db benchmarking utility. ## Why? 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. ## What? Two scripts: * `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 ## Limitations * 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 .csv`. Each file will contain the query generated as well as the timing in seconds. ### Analyze results 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 ``` You're done. ## License ``` 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. ```