summaryrefslogtreecommitdiff
path: root/contrib/pgbench/pgbench.c
AgeCommit message (Collapse)Author
2015-04-13Move pgbench from contrib/ to src/bin/Peter Eisentraut
Reviewed-by: Michael Paquier <michael.paquier@gmail.com>
2015-04-02Improve pgbench error reporting.Robert Haas
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
2015-04-02Define integer limits independently from the system definitions.Andres Freund
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
2015-03-25Centralize definition of integer limits.Andres Freund
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
2015-03-02pgbench: Add a real expression syntax to \setRobert Haas
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
2015-01-24Replace a bunch more uses of strncpy() with safer coding.Tom Lane
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.
2015-01-06Update copyright for 2015Bruce Momjian
Backpatch certain files through 9.0
2014-12-30Fix resource leak pointed out by Coverity.Tatsuo Ishii
2014-12-24pgbench: remove odd trailing period in init progress outputBruce Momjian
2014-12-16Suppress bogus statistics when pgbench failed to complete any transactions.Tom Lane
Code added in 9.4 would attempt to divide by zero in such cases. Noted while testing fix for missing-pclose problem.
2014-12-16Fix file descriptor leak after failure of a \setshell command in pgbench.Tom Lane
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.
2014-10-13Add --latency-limit option to pgbench.Heikki Linnakangas
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.
2014-10-02Fix typo in error message.Heikki Linnakangas
2014-10-02Refactor pgbench log-writing code to a separate function.Heikki Linnakangas
The doCustom function was incredibly long, this makes it a little bit more readable.
2014-09-11Fix Windows build.Heikki Linnakangas
I renamed a variable, but missed an #ifdef WIN32 block.
2014-09-11Simplify calculation of Poisson distributed delays in pgbench --rate mode.Heikki Linnakangas
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.
2014-09-11Change the way latency is calculated with pgbench --rate option.Heikki Linnakangas
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.
2014-08-12Enhance pgbench's option checking.Tatsuo Ishii
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.
2014-08-04Windows doesn't have M_PI; define it ourselves when needed.Heikki Linnakangas
This should fix the Windows build, broken by commit ed802e7d.
2014-07-30pgbench: Allow \setrandom to generate Gaussian/exponential distributions.Robert Haas
Mitsumasa KONDO and Fabien COELHO, with further wordsmithing by me.
2014-05-25Allow total number of transactions in pgbench to exceed INT_MAX.Tom Lane
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
2014-05-19Fix non-C89-compatible coding in pgbench.Tom Lane
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
2014-05-06pgindent run for 9.4Bruce Momjian
This includes removing tabs after periods in C comments, which was applied to back branches, so this change should not effect backpatching.
2014-02-28pgbench: Fix help messagePeter Eisentraut
Add NUM placeholder to -t option in help message. It got lost in 79cddb18419778be3202c971b3f21cdd90f7b719. Author: Fabien COELHO <coelho@cri.ensmp.fr>
2014-02-15Centralize getopt-related declarations in a new header file pg_getopt.h.Tom Lane
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
2014-01-17Prevent integer overflow with --progress >= 2148Heikki Linnakangas
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
2014-01-07Update copyright for 2014Bruce Momjian
Update all files in head, and files COPYRIGHT and legal.sgml in all back branches.
2013-12-12Fix progress logging when scale factor is large.Tatsuo Ishii
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).
2013-11-16Remove pgbench's hardwired limit on line length in custom script files.Tom Lane
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
2013-11-10Fix whitespace issues found by git diff --check, add gitattributesPeter Eisentraut
Set per file type attributes in .gitattributes to fine-tune whitespace checks. With the associated cleanups, the tree is now clean for git
2013-10-06pgbench: Comment on thread timing hazards.Noah Misch
Reviewed by Fabien COELHO.
2013-10-05pgbench: Elaborate latency reporting.Noah Misch
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.
2013-10-05pgbench: Remove stray use of "float" math.Noah Misch
Oversight in commit 4a87f308b33457670f9ab4bc622678e5d285b9c2. Fabien COELHO
2013-09-30Correct comment of pgbench "filler" columns.Fujii Masao
Pavan Deolasee
2013-09-26pgbench: Correct for bias in --rate schedule generation.Noah Misch
Previous code gave a mean delay 0.44% below target. This change also has the effect of increasing the maximum possible delay. Fabien COELHO
2013-09-23pgbench: Tweak documentation.Noah Misch
Fabien COELHO
2013-07-22Add --rate option.Tatsuo Ishii
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.
2013-07-17Fix typo in previous pgbench --progress patch.Fujii Masao
2013-07-16Add --progress option to show progress reportTatsuo Ishii
Patch contributed by Fabien COELHO, reviewed by KONDO Mitsumasa.
2013-07-07pgbench: Silence compiler warningPeter Eisentraut
Explicitly ignore return value from write(), to silence warning. This warning only appeared under --disable-thread-safety.
2013-06-27pgbench: Fix inadvertent inconsistency in help message.Robert Haas
Per report from Fujii Masao.
2013-06-27pgbench: Add long options for all existing short options.Robert Haas
Fabien Coelho, reviewed by Fabrízio de Royes Mello, with some further changes by me
2013-06-14Add :client_id automatic variable for custom pgbench scripts.Heikki Linnakangas
This makes it easier to write custom scripts that have different logic for each client. Gurjeet Singh, with some changes by me.
2013-06-01Post-pgindent cleanupStephen Frost
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.
2013-05-29pgindent run for release 9.3Bruce Momjian
This is the first run of the Perl-based pgindent script. Also update pgindent instructions.
2013-05-12pgbench: Fix order of options in --help outputPeter Eisentraut
2013-03-17Fix inclusions in pgbench.c.Tom Lane
Apparently this was depending on pqsignal.h for <signal.h>. Not sure why I didn't see the failure on my other machine.
2013-03-17Move pqsignal() to libpgport.Tom Lane
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.
2013-02-12Create libpgcommon, and move pg_malloc et al to itAlvaro Herrera
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.
2013-01-31Add --aggregate-interval option.Tatsuo Ishii
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.