diff options
author | Robert Haas <rhaas@postgresql.org> | 2016-03-09 13:09:12 -0500 |
---|---|---|
committer | Robert Haas <rhaas@postgresql.org> | 2016-03-09 13:11:05 -0500 |
commit | accf7616ff2854640523d5e42ffa5420cc5a3b51 (patch) | |
tree | e73382d17c6db7c4a9ec8351ba1f89869cf97a68 /src | |
parent | 188f359d39ed65b5f3ddc1f397140fb9d153e61a (diff) | |
download | postgresql-accf7616ff2854640523d5e42ffa5420cc5a3b51.tar.gz postgresql-accf7616ff2854640523d5e42ffa5420cc5a3b51.zip |
pgbench: When -T is used, don't wait for transactions beyond end of run.
At low rates, this can lead to pgbench taking significantly longer to
terminate than the user might expect. Repair.
Fabien Coelho, reviewed by Aleksander Alekseev, Álvaro Herrera, and me.
Diffstat (limited to 'src')
-rw-r--r-- | src/bin/pgbench/pgbench.c | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/bin/pgbench/pgbench.c b/src/bin/pgbench/pgbench.c index 92df7504ad5..e3d0d69b3f2 100644 --- a/src/bin/pgbench/pgbench.c +++ b/src/bin/pgbench/pgbench.c @@ -94,6 +94,7 @@ static int pthread_join(pthread_t th, void **thread_return); int nxacts = 0; /* number of transactions per client */ int duration = 0; /* duration in seconds */ +int64 end_time = 0; /* when to stop in micro seconds, under -T */ /* * scaling factor. for example, scale = 10 will make 1000000 tuples in @@ -1362,6 +1363,10 @@ top: thread->throttle_trigger += wait; st->txn_scheduled = thread->throttle_trigger; + /* stop client if next transaction is beyond pgbench end of execution */ + if (duration > 0 && st->txn_scheduled > end_time) + return clientDone(st, true); + /* * If this --latency-limit is used, and this slot is already late so * that the transaction will miss the latency limit even if it @@ -3582,6 +3587,11 @@ main(int argc, char **argv) INSTR_TIME_SET_CURRENT(thread->start_time); + /* compute when to stop */ + if (duration > 0) + end_time = INSTR_TIME_GET_MICROSEC(thread->start_time) + + (int64) 1000000 * duration; + /* the first thread (i = 0) is executed by main thread */ if (i > 0) { @@ -3600,6 +3610,10 @@ main(int argc, char **argv) } #else INSTR_TIME_SET_CURRENT(threads[0].start_time); + /* compute when to stop */ + if (duration > 0) + end_time = INSTR_TIME_GET_MICROSEC(threads[0].start_time) + + (int64) 1000000 * duration; threads[0].thread = INVALID_THREAD; #endif /* ENABLE_THREAD_SAFETY */ |