Commit 547f04e7 authored by Thomas Munro's avatar Thomas Munro

pgbench: Improve time logic.

Instead of instr_time (struct timespec) and the INSTR_XXX macros,
introduce pg_time_usec_t and use integer arithmetic.  Don't include the
connection time in TPS unless using -C mode, but report it separately.

Author: Fabien COELHO <coelho@cri.ensmp.fr>
Reviewed-by: default avatarKyotaro Horiguchi <horikyota.ntt@gmail.com>
Reviewed-by: default avatarHayato Kuroda <kuroda.hayato@fujitsu.com>
Discussion: https://postgr.es/m/20200227180100.zyvjwzcpiokfsqm2%40alap3.anarazel.de
parent b1d6a8f8
...@@ -58,8 +58,10 @@ number of clients: 10 ...@@ -58,8 +58,10 @@ number of clients: 10
number of threads: 1 number of threads: 1
number of transactions per client: 1000 number of transactions per client: 1000
number of transactions actually processed: 10000/10000 number of transactions actually processed: 10000/10000
tps = 85.184871 (including connections establishing) latency average = 11.013 ms
tps = 85.296346 (excluding connections establishing) latency stddev = 7.351 ms
initial connection time = 45.758 ms
tps = 896.967014 (without initial connection time)
</screen> </screen>
The first six lines report some of the most important parameter The first six lines report some of the most important parameter
...@@ -68,8 +70,7 @@ tps = 85.296346 (excluding connections establishing) ...@@ -68,8 +70,7 @@ tps = 85.296346 (excluding connections establishing)
and number of transactions per client); these will be equal unless the run and number of transactions per client); these will be equal unless the run
failed before completion. (In <option>-T</option> mode, only the actual failed before completion. (In <option>-T</option> mode, only the actual
number of transactions is printed.) number of transactions is printed.)
The last two lines report the number of transactions per second, The last line reports the number of transactions per second.
figured with and without counting the time to start database sessions.
</para> </para>
<para> <para>
...@@ -2257,22 +2258,22 @@ number of clients: 10 ...@@ -2257,22 +2258,22 @@ number of clients: 10
number of threads: 1 number of threads: 1
number of transactions per client: 1000 number of transactions per client: 1000
number of transactions actually processed: 10000/10000 number of transactions actually processed: 10000/10000
latency average = 15.844 ms latency average = 10.870 ms
latency stddev = 2.715 ms latency stddev = 7.341 ms
tps = 618.764555 (including connections establishing) initial connection time = 30.954 ms
tps = 622.977698 (excluding connections establishing) tps = 907.949122 (without initial connection time)
statement latencies in milliseconds: statement latencies in milliseconds:
0.002 \set aid random(1, 100000 * :scale) 0.001 \set aid random(1, 100000 * :scale)
0.005 \set bid random(1, 1 * :scale) 0.001 \set bid random(1, 1 * :scale)
0.002 \set tid random(1, 10 * :scale) 0.001 \set tid random(1, 10 * :scale)
0.001 \set delta random(-5000, 5000) 0.000 \set delta random(-5000, 5000)
0.326 BEGIN; 0.046 BEGIN;
0.603 UPDATE pgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid; 0.151 UPDATE pgbench_accounts SET abalance = abalance + :delta WHERE aid = :aid;
0.454 SELECT abalance FROM pgbench_accounts WHERE aid = :aid; 0.107 SELECT abalance FROM pgbench_accounts WHERE aid = :aid;
5.528 UPDATE pgbench_tellers SET tbalance = tbalance + :delta WHERE tid = :tid; 4.241 UPDATE pgbench_tellers SET tbalance = tbalance + :delta WHERE tid = :tid;
7.335 UPDATE pgbench_branches SET bbalance = bbalance + :delta WHERE bid = :bid; 5.245 UPDATE pgbench_branches SET bbalance = bbalance + :delta WHERE bid = :bid;
0.371 INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (:tid, :bid, :aid, :delta, CURRENT_TIMESTAMP); 0.102 INSERT INTO pgbench_history (tid, bid, aid, delta, mtime) VALUES (:tid, :bid, :aid, :delta, CURRENT_TIMESTAMP);
1.212 END; 0.974 END;
</screen> </screen>
</para> </para>
......
This diff is collapsed.
...@@ -253,4 +253,32 @@ GetTimerFrequency(void) ...@@ -253,4 +253,32 @@ GetTimerFrequency(void)
#define INSTR_TIME_SET_CURRENT_LAZY(t) \ #define INSTR_TIME_SET_CURRENT_LAZY(t) \
(INSTR_TIME_IS_ZERO(t) ? INSTR_TIME_SET_CURRENT(t), true : false) (INSTR_TIME_IS_ZERO(t) ? INSTR_TIME_SET_CURRENT(t), true : false)
/*
* Simpler convenient interface
*
* The instr_time type is expensive when dealing with time arithmetic.
* Define a type to hold microseconds on top of this, suitable for
* benchmarking performance measures, eg in "pgbench".
*
* Type int64 is good enough for about 584500 years.
*/
typedef int64 pg_time_usec_t;
static inline pg_time_usec_t
pg_time_now(void)
{
instr_time now;
INSTR_TIME_SET_CURRENT(now);
return (pg_time_usec_t) INSTR_TIME_GET_MICROSEC(now);
}
static inline void
pg_time_now_lazy(pg_time_usec_t *now)
{
if ((*now) == 0)
(*now) = pg_time_now();
}
#define PG_TIME_GET_DOUBLE(t) (0.000001 * (t))
#endif /* INSTR_TIME_H */ #endif /* INSTR_TIME_H */
...@@ -3225,6 +3225,7 @@ pg_sha512_ctx ...@@ -3225,6 +3225,7 @@ pg_sha512_ctx
pg_snapshot pg_snapshot
pg_stack_base_t pg_stack_base_t
pg_time_t pg_time_t
pg_time_usec_t
pg_tz pg_tz
pg_tz_cache pg_tz_cache
pg_tzenum pg_tzenum
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment