pgbench-tools automates running PostgreSQL's built-in pgbench tool in a useful ways. It will run some number of database sizes (the database scale) and various concurrent client count combinations. Scale/client runs with some common characteristic--perhaps one configuration of the postgresql.conf--can be organized into a "set" of runs. The program graphs transaction rate during each test, latency, and comparisons between test sets.
Create databases for your test and for the results:
createdb results createdb pgbench
- Both databases can be the same, but there may be more shared_buffers cache churn in that case. Some amount of cache disruption is unavoidable unless the result database is remote, because of the OS cache. The recommended and default configuration is to have a pgbench database and a results database. This also keeps the size of the result dataset from being included in the total database size figure recorded by the test.
Initialize the results database by executing:
psql -f init/resultdb.sql -d results
Make sure to reference the correct database.
You need to create a test set with a descritption:
./newset 'Initial Config'
Running the "newset" utility without any parameters will list all of the existing test sets.
Edit the config file to reference the test and results database, as well as list the test you want to run. The default test is a SELECT-only one that runs for 60 seconds.
In order to execute all the tests
You can check results even as the test is running with:
psql -d results -f reports/report.sql
This is unlikely to disrupt the test results very much unless you've run an enormous number of tests already. There is also a helper script named summary that shows reports/summary.sql
A helper script named set-times will show how long past tests have taken to complete. This can be useful to get an idea how long the currently running test or test set will actually take to finish.
- Other useful reports you can run are in the reports/ directory, including:
Once the tests are done, the results/ directory will include a HTML subdirectory for each test giving its results, in addition to the summary information in the results database.
The results directory will also include its own index HTML file (named index.html) that shows summary information and plots for all the tests.
If you manually adjust the test result database, you can then manually regenerate the summary graphs by running:
Test sets comparison
Runs of pgbench via the runset command are oriented into test sets. Each test that is run will be put into the same test set until you tell the program to switch to a new set. Each test set is assigned both a serial number and a test description.
New test sets are added like this:
psql -d results -c "INSERT INTO testset (info) VALUES ('set name')"
pgbench-tools aims to help compare multiple setups of PostgreSQL. That might be different configuration parameters, different source code builds, or even different versions of the database. One reason the results database is separate from the test database is that you can use a shared results database across multiple test sets, while connecting to multiple test database installations.
The graphs generated by the program will generate a seperate graph pair for each test set, as well as a master graph pair that compares all of them. The graphs in each pair are graphed with a X axis of client count and database scale (size) respectively. The idea is that you might see whether an alternate configuration is better at handling larger data sets, or if it handles concurrency at high client counts better.
Note that all of the built-in pgbench tests use very simple queries. The results can be useful for testing read-only SELECT scaling at different client counts. They can also be useful for seeing how the server handles heavy write volume. But none of these results will change if you alter server parameters that adjust query execution, such as work_mem or effective_cache_size. Many of the useful PostgreSQL parameters to tune for better query execution on larger servers in particular fall into this category. You will not always be able to compare configurations usefully using the built-in pgbench tests. Even for parameters that should impact results, such as shared_buffers or checkpoint_segments, making useful comparisons with pgbench is often difficult.
There is more information about what pgbench is useful for, as well as how to adjust the program to get better results, in the pgbench documentation: http://www.postgresql.org/docs/current/static/pgbench.html
The default configuration now aims to support the pgbench that ships with PostgreSQL 8.4 and later versions, which uses names such as "pgbench_accounts" for its tables. There are commented out settings in the config file that show what changes need to be made in order to make the program compatible with PostgreSQL 8.3, where the names were like "accounts" instead.
Support for PostgreSQL versions before 8.3 is not possible, because a change was made to the pgbench client in that version that is needed by the program to work properly. It is possible to use the PostgreSQL 8.3 pgbench client against a newer database server, or to copy the pgbench.c program from 8.3 into a 8.2 source code build and use it instead (with some fixes--it won't compile unless you comment out code that refers to optional newer features added in 8.3).
Multiple worker support
Starting in PostgreSQL 9.0, pgbench allows splitting up the work pgbench does into multiple worker threads or processes (which depends on whether the database client libraries haves been compiled with thread-safe behavior or not).
This feature is extremely valuable, as it's likely to give at least a 15% speedup on common hardware. And it can more than double throughput on operating systems that are particularly hostile to running the pgbench client. One known source of this problem is Linux kernels using the Completely Fair Scheduler introduced in 2.6.23, which does not schedule the pgbench program very well when it's connecting to the database using the default method, Unix-domain sockets.
(Note that pgbench-tools doesn't suffer greatly from this problem itself, as it connects over TCP/IP using the "-H" parameter. Manual pgbench runs that do not specify a host, and therefore connect via a local socket can be extremely slow on recent Linux kernels.)
Taking advantage of this feature is done in pgbench-tools by increasing the MAX_WORKERS setting in the configuration file. It takes the value of nproc by default, or where that isn't available (typically on systems without a recent version of GNU coreutils), the default can be set to blank, which avoids using this feature altogether -- thereby remaining compatible not only with systems lacking the nproc program, but also with PostgreSQL/pgbench versions before this capability was added.
When using multiple workers, each must be allocated an equal number of clients. That means that client counts that are not a multiple of the worker count will result in pgbench not running at all.
Accordingly, if you set MAX_WORKERS to a number to enable this capability, pgbench-tools picks the maximum integer of that value or lower that the client count is evenly divisible by. For example, if MAX_WORKERS is 4, running with 8 clients will use 4 workers, while 9 clients will shift downward to 3 workers as the best option.
A reasonable setting for MAX_WORKERS is the number of physical cores on the server, typically giving best performance. And when using this feature, it's better to tweak test client counts toward ones that are divisible by as many factors as possible. For example, if you wanted approximately 15 clients, it would be best to use 16, allowing worker counts of 2, 4, or 8, all likely to match common core counts. Second choice would be 14, compatible with 2 workers. Third is 15, which would allow 3 workers--not improving upon a single worker on common dual-core systems. The worst choices would be 13 or 17 clients, which are prime and therefore cannot be usefully allocated more than one worker on common hardware.
Removing bad tests
If you abort a test in the middle of running, you will end up with a bad test result entry in the results database. These will look odd and can distort averages and graphs. Ideally you would erase the entire directory each of those bad test results are in, followed by removing their main entry from the results database. You can do that at a shell prompt like this:
cd results psql -d results -At -c "SELECT test FROM tests WHERE tps=0" | xargs rm -rf psql -d results -At -c "DELETE FROM tests WHERE tps=0" ./webreport
- On Solaris, where the benchwarmer script calls tail it may need to use /usr/xpg4/bin/tail instead
- The client+scale data table used to generate the 3D report would be useful to generate in tabular text format as well.
README.rst for the program is in ReST markup. Tools
that operate on ReST can be used to make versions of it formatted
for other purposes, such as rst2html to make a HTML version.
If you have any hints, changes or improvements, please contact:
- Greg Smith firstname.lastname@example.org
Copyright (c) 2007-2014, Gregory Smith All rights reserved. See COPYRIGHT file for full license details and HISTORY for a list of other contributors to the program.