summaryrefslogtreecommitdiff
path: root/contrib/pgbench/pgbench.c
Commit message (Collapse)AuthorAgeFilesLines
* Move pgbench from contrib/ to src/bin/Peter Eisentraut2015-04-131-4004/+0
| | | | Reviewed-by: Michael Paquier <michael.paquier@gmail.com>
* Improve pgbench error reporting.Robert Haas2015-04-021-30/+57
| | | | | | | | This would have been worth doing on general principle anyway, but the recent addition of an expression syntax to pgbench makes it an even better idea than it would have been otherwise. Fabien Coelho
* Define integer limits independently from the system definitions.Andres Freund2015-04-021-4/+4
| | | | | | | | | | | | | | | | | | | | | In 83ff1618 we defined integer limits iff they're not provided by the system. That turns out not to be the greatest idea because there's different ways some datatypes can be represented. E.g. on OSX PG's 64bit datatype will be a 'long int', but OSX unconditionally uses 'long long'. That disparity then can lead to warnings, e.g. around printf formats. One way to fix that would be to back int64 using stdint.h's int64_t. While a good idea it's not that easy to implement. We would e.g. need to include stdint.h in our external headers, which we don't today. Also computing the correct int64 printf formats in that case is nontrivial. Instead simply prefix the integer limits with PG_ and define them unconditionally. I've adjusted all the references to them in code, but not the ones in comments; the latter seems unnecessary to me. Discussion: 20150331141423.GK4878@alap3.anarazel.de
* Centralize definition of integer limits.Andres Freund2015-03-251-5/+1
| | | | | | | | | | | | | | | | | Several submitted and even committed patches have run into the problem that C89, our baseline, does not provide minimum/maximum values for various integer datatypes. C99's stdint.h does, but we can't rely on it. Several parts of the code defined limits locally, so instead centralize the definitions to c.h. This patch also changes the more obvious usages of literal limit values; there's more places that could be changed, but it's less clear whether it's beneficial to change those. Author: Andrew Gierth Discussion: 87619tc5wc.fsf@news-spur.riddles.org.uk
* pgbench: Add a real expression syntax to \setRobert Haas2015-03-021-76/+139
| | | | | | | | | | | Previously, you could do \set variable operand1 operator operand2, but nothing more complicated. Now, you can \set variable expression, which makes it much simpler to do multi-step calculations here. This also adds support for the modulo operator (%), with the same semantics as in C. Robert Haas and Fabien Coelho, reviewed by Álvaro Herrera and Stephen Frost
* Replace a bunch more uses of strncpy() with safer coding.Tom Lane2015-01-241-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | strncpy() has a well-deserved reputation for being unsafe, so make an effort to get rid of nearly all occurrences in HEAD. A large fraction of the remaining uses were passing length less than or equal to the known strlen() of the source, in which case no null-padding can occur and the behavior is equivalent to memcpy(), though doubtless slower and certainly harder to reason about. So just use memcpy() in these cases. In other cases, use either StrNCpy() or strlcpy() as appropriate (depending on whether padding to the full length of the destination buffer seems useful). I left a few strncpy() calls alone in the src/timezone/ code, to keep it in sync with upstream (the IANA tzcode distribution). There are also a few such calls in ecpg that could possibly do with more analysis. AFAICT, none of these changes are more than cosmetic, except for the four occurrences in fe-secure-openssl.c, which are in fact buggy: an overlength source leads to a non-null-terminated destination buffer and ensuing misbehavior. These don't seem like security issues, first because no stack clobber is possible and second because if your values of sslcert etc are coming from untrusted sources then you've got problems way worse than this. Still, it's undesirable to have unpredictable behavior for overlength inputs, so back-patch those four changes to all active branches.
* Update copyright for 2015Bruce Momjian2015-01-061-1/+1
| | | | Backpatch certain files through 9.0
* Fix resource leak pointed out by Coverity.Tatsuo Ishii2014-12-301-0/+2
|
* pgbench: remove odd trailing period in init progress outputBruce Momjian2014-12-241-2/+2
|
* Suppress bogus statistics when pgbench failed to complete any transactions.Tom Lane2014-12-161-0/+4
| | | | | Code added in 9.4 would attempt to divide by zero in such cases. Noted while testing fix for missing-pclose problem.
* Fix file descriptor leak after failure of a \setshell command in pgbench.Tom Lane2014-12-161-0/+1
| | | | | | | | | If the called command fails to return data, runShellCommand forgot to pclose() the pipe before returning. This is fairly harmless in the current code, because pgbench would then abandon further processing of that client thread; so no more than nclients descriptors could be leaked this way. But it's not hard to imagine future improvements whereby that wouldn't be true. In any case, it's sloppy coding, so patch all branches. Found by Coverity.
* Add --latency-limit option to pgbench.Heikki Linnakangas2014-10-131-56/+175
| | | | | | | | | | This allows transactions that take longer than specified limit to be counted separately. With --rate, transactions that are already late by the time we get to execute them are skipped altogether. Using --latency-limit with --rate allows you to "catch up" more quickly, if there's a hickup in the server causing a lot of transactions to stall momentarily. Fabien COELHO, reviewed by Rukh Meski and heavily refactored by me.
* Fix typo in error message.Heikki Linnakangas2014-10-021-1/+1
|
* Refactor pgbench log-writing code to a separate function.Heikki Linnakangas2014-10-021-171/+169
| | | | | The doCustom function was incredibly long, this makes it a little bit more readable.
* Fix Windows build.Heikki Linnakangas2014-09-111-1/+1
| | | | I renamed a variable, but missed an #ifdef WIN32 block.
* Simplify calculation of Poisson distributed delays in pgbench --rate mode.Heikki Linnakangas2014-09-111-11/+22
| | | | | | | | | | | | | | | | | The previous coding first generated a uniform random value between 0.0 and 1.0, then converted that to an integer between 1 and 10000, and divided that again by 10000. Those conversions are unnecessary; we can use the double value that pg_erand48() returns directly. While we're at it, put the logic into a helper function, getPoissonRand(). The largest delay generated by the old coding was about 9.2 times the average, because of the way the uniformly distributed value used for the calculation was truncated to 1/10000 granularity. The new coding doesn't have such clamping. With my laptop's DBL_MIN value, the maximum delay with the new coding is about 700x the average. That seems acceptable - any reasonable pgbench session should last long enough to average that out. Backpatch to 9.4.
* Change the way latency is calculated with pgbench --rate option.Heikki Linnakangas2014-09-111-50/+114
| | | | | | | | | | | | | | The reported latency values now include the "schedule lag" time, that is, the time between the transaction's scheduled start time and the time it actually started. This relates better to a model where requests arrive at a certain rate, and we are interested in the response time to the end user or application, rather than the response time of the database itself. Also, when --rate is used, include the schedule lag time in the log output. The --rate option is new in 9.4, so backpatch to 9.4. It seems better to make this change in 9.4, while we're still in the beta period, than ship a 9.4 version that calculates the values differently than 9.5.
* Enhance pgbench's option checking.Tatsuo Ishii2014-08-121-7/+41
| | | | | | | | Now benchmarking options such as -c cannot be used if initializing option (-i) is specified. Also initializing options such as -F cannot be used if initializing option is not specified. Tatsuo Ishii and Fabien COELHO.
* Windows doesn't have M_PI; define it ourselves when needed.Heikki Linnakangas2014-08-041-0/+4
| | | | This should fix the Windows build, broken by commit ed802e7d.
* pgbench: Allow \setrandom to generate Gaussian/exponential distributions.Robert Haas2014-07-301-10/+173
| | | | Mitsumasa KONDO and Fabien COELHO, with further wordsmithing by me.
* Allow total number of transactions in pgbench to exceed INT_MAX.Tom Lane2014-05-251-6/+6
| | | | | | | | | | | | | Change the total-transactions counters from int32 to int64 to accommodate cases where we do more than 2^31 transactions during a run. This patch does not change the INT_MAX limit on explicit "-t" parameters, but it does allow the product of the -t and -c parameters to exceed INT_MAX, or allow a -T limit that is large enough that more than 2^31 transactions can be completed. While pgbench did not actually fail in such cases, it did print an incorrect total-transactions count, and some of the derived numbers such as TPS would have been wrong as well. Tomas Vondra
* Fix non-C89-compatible coding in pgbench.Tom Lane2014-05-191-27/+37
| | | | | | | | | | | | | | | | C89 says that compound initializers may only contain constant expressions; a restriction violated by commit 89d00cbe. While we've had no actual field complaints about this, C89 is still the project standard, and it's not saving all that much code to break compatibility here. So let's adhere to the old restriction. In passing, replace a bunch of hardwired constants "256" with sizeof(target-variable), just because the latter is more readable and less breakable. And const-ify where possible. Back-patch to 9.3 where the nonportable code was added. Andres Freund and Tom Lane
* pgindent run for 9.4Bruce Momjian2014-05-061-86/+116
| | | | | This includes removing tabs after periods in C comments, which was applied to back branches, so this change should not effect backpatching.
* pgbench: Fix help messagePeter Eisentraut2014-02-271-1/+1
| | | | | | | Add NUM placeholder to -t option in help message. It got lost in 79cddb18419778be3202c971b3f21cdd90f7b719. Author: Fabien COELHO <coelho@cri.ensmp.fr>
* Centralize getopt-related declarations in a new header file pg_getopt.h.Tom Lane2014-02-151-8/+0
| | | | | | | | | | | | We used to have externs for getopt() and its API variables scattered all over the place. Now that we find we're going to need to tweak the variable declarations for Cygwin, it seems like a good idea to have just one place to tweak. In this commit, the variables are declared "#ifndef HAVE_GETOPT_H". That may or may not work everywhere, but we'll soon find out. Andres Freund
* Prevent integer overflow with --progress >= 2148Heikki Linnakangas2014-01-171-3/+3
| | | | | | | | If --progress=2148 or higher was given, the calculation of the next time to report overflowed, and pgbench would print a progress report very frequently. Kingter Wang
* Update copyright for 2014Bruce Momjian2014-01-071-1/+1
| | | | | Update all files in head, and files COPYRIGHT and legal.sgml in all back branches.
* Fix progress logging when scale factor is large.Tatsuo Ishii2013-12-121-4/+4
| | | | | Integer overflow showed minus percent and minus remaining time something like this. 239300000 of 3800000000 tuples (-48%) done (elapsed 226.86 s, remaining -696.10 s).
* Remove pgbench's hardwired limit on line length in custom script files.Tom Lane2013-11-151-2/+48
| | | | | | | | pgbench formerly failed on lines longer than BUFSIZ, unexpectedly splitting them into multiple commands. Allow it to work with any length of input line. Sawada Masahiko
* Fix whitespace issues found by git diff --check, add gitattributesPeter Eisentraut2013-11-101-10/+8
| | | | | Set per file type attributes in .gitattributes to fine-tune whitespace checks. With the associated cleanups, the tree is now clean for git
* pgbench: Comment on thread timing hazards.Noah Misch2013-10-061-1/+10
| | | | Reviewed by Fabien COELHO.
* pgbench: Elaborate latency reporting.Noah Misch2013-10-051-17/+110
| | | | | | | | | | | Isolate transaction latency (elapsed time between submitting first command and receiving response to last command) from client-side delays pertaining to the --rate schedule. Under --rate, report schedule lag as defined in the documentation. Report latency standard deviation whenever we collect the measurements to do so. All of these changes affect --progress messages and the final report. Fabien COELHO, reviewed by Pavel Stehule.
* pgbench: Remove stray use of "float" math.Noah Misch2013-10-051-2/+2
| | | | | | Oversight in commit 4a87f308b33457670f9ab4bc622678e5d285b9c2. Fabien COELHO
* Correct comment of pgbench "filler" columns.Fujii Masao2013-09-301-5/+10
| | | | Pavan Deolasee
* pgbench: Correct for bias in --rate schedule generation.Noah Misch2013-09-251-3/+7
| | | | | | | Previous code gave a mean delay 0.44% below target. This change also has the effect of increasing the maximum possible delay. Fabien COELHO
* pgbench: Tweak documentation.Noah Misch2013-09-231-1/+1
| | | | Fabien COELHO
* Add --rate option.Tatsuo Ishii2013-07-231-19/+159
| | | | | | This controls the target transaction rate to certain tps, rather than maximum. Patch contributed by Fabien COELHO, reviewed by Greg Smith, and slight editing by me.
* Fix typo in previous pgbench --progress patch.Fujii Masao2013-07-181-1/+1
|
* Add --progress option to show progress reportTatsuo Ishii2013-07-171-2/+84
| | | | Patch contributed by Fabien COELHO, reviewed by KONDO Mitsumasa.
* pgbench: Silence compiler warningPeter Eisentraut2013-07-071-1/+3
| | | | | Explicitly ignore return value from write(), to silence warning. This warning only appeared under --disable-thread-safety.
* pgbench: Fix inadvertent inconsistency in help message.Robert Haas2013-06-271-1/+1
| | | | Per report from Fujii Masao.
* pgbench: Add long options for all existing short options.Robert Haas2013-06-271-39/+60
| | | | | Fabien Coelho, reviewed by Fabrízio de Royes Mello, with some further changes by me
* Add :client_id automatic variable for custom pgbench scripts.Heikki Linnakangas2013-06-141-0/+14
| | | | | | | This makes it easier to write custom scripts that have different logic for each client. Gurjeet Singh, with some changes by me.
* Post-pgindent cleanupStephen Frost2013-06-011-3/+6
| | | | | | | | | | Make slightly better decisions about indentation than what pgindent is capable of. Mostly breaking out long function calls into one line per argument, with a few other minor adjustments. No functional changes- all whitespace. pgindent ran cleanly (didn't change anything) after. Passes all regressions.
* pgindent run for release 9.3Bruce Momjian2013-05-291-51/+80
| | | | | This is the first run of the Perl-based pgindent script. Also update pgindent instructions.
* pgbench: Fix order of options in --help outputPeter Eisentraut2013-05-111-6/+6
|
* Fix inclusions in pgbench.c.Tom Lane2013-03-171-0/+1
| | | | | Apparently this was depending on pqsignal.h for <signal.h>. Not sure why I didn't see the failure on my other machine.
* Move pqsignal() to libpgport.Tom Lane2013-03-171-1/+0
| | | | | | | | | We had two copies of this function in the backend and libpq, which was already pretty bogus, but it turns out that we need it in some other programs that don't use libpq (such as pg_test_fsync). So put it where it probably should have been all along. The signal-mask-initialization support in src/backend/libpq/pqsignal.c stays where it is, though, since we only need that in the backend.
* Create libpgcommon, and move pg_malloc et al to itAlvaro Herrera2013-02-121-53/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | libpgcommon is a new static library to allow sharing code among the various frontend programs and backend; this lets us eliminate duplicate implementations of common routines. We avoid libpgport, because that's intended as a place for porting issues; per discussion, it seems better to keep them separate. The first use case, and the only implemented by this patch, is pg_malloc and friends, which many frontend programs were already using. At the same time, we can use this to provide palloc emulation functions for the frontend; this way, some palloc-using files in the backend can also be used by the frontend cleanly. To do this, we change palloc() in the backend to be a function instead of a macro on top of MemoryContextAlloc(). This was previously believed to cause loss of performance, but this implementation has been tweaked by Tom and Andres so that on modern compilers it provides a slight improvement over the previous one. This lets us clean up some places that were already with localized hacks. Most of the pg_malloc/palloc changes in this patch were authored by Andres Freund. Zoltán Böszörményi also independently provided a form of that. libpgcommon infrastructure was authored by Álvaro.
* Add --aggregate-interval option.Tatsuo Ishii2013-01-311-12/+135
| | | | | | | | | | | | The new option specifies length of aggregation interval (in seconds). May be used only together with -l. With this option, the log contains per-interval summary (number of transactions, min/max latency and two additional fields useful for variance estimation). Patch contributed by Tomas Vondra, reviewed by Pavel Stehule. Slight change by Tatsuo Ishii, suggested by Robert Hass to emit an error message indicating that the option is not currently supported on Windows.