Skip to content

Commit 4dc528b

Browse files
committed
pgbench: Fix bug in measurement of disconnection delays.
When -C/--connect option is specified, pgbench establishes and closes the connection for each transaction. In this case pgbench needs to measure the times taken for all those connections and disconnections, to include the average connection time in the benchmark result. But previously pgbench could not measure those disconnection delays. To fix the bug, this commit makes pgbench measure the disconnection delays whenever the connection is closed at the end of transaction, if -C/--connect option is specified. Back-patch to v14. Per discussion, we concluded not to back-patch to v13 or before because changing that behavior in stable branches would surprise users rather than providing benefits. Author: Yugo Nagata Reviewed-by: Fabien COELHO, Tatsuo Ishii, Asif Rehman, Fujii Masao Discussion: https://postgr.es/m/20210614151155.a393bc7d8fed183e38c9f52a@sraoss.co.jp
1 parent 8d0138e commit 4dc528b

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

src/bin/pgbench/pgbench.c

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3553,8 +3553,12 @@ advanceConnectionState(TState *thread, CState *st, StatsData *agg)
35533553

35543554
if (is_connect)
35553555
{
3556+
pg_time_usec_t start = now;
3557+
3558+
pg_time_now_lazy(&start);
35563559
finishCon(st);
3557-
now = 0;
3560+
now = pg_time_now();
3561+
thread->conn_duration += now - start;
35583562
}
35593563

35603564
if ((st->cnt >= nxacts && duration <= 0) || timer_exceeded)
@@ -3578,6 +3582,19 @@ advanceConnectionState(TState *thread, CState *st, StatsData *agg)
35783582
*/
35793583
case CSTATE_ABORTED:
35803584
case CSTATE_FINISHED:
3585+
3586+
/*
3587+
* Don't measure the disconnection delays here even if in
3588+
* CSTATE_FINISHED and -C/--connect option is specified.
3589+
* Because in this case all the connections that this thread
3590+
* established are closed at the end of transactions and the
3591+
* disconnection delays should have already been measured at
3592+
* that moment.
3593+
*
3594+
* In CSTATE_ABORTED state, the measurement is no longer
3595+
* necessary because we cannot report complete results anyways
3596+
* in this case.
3597+
*/
35813598
finishCon(st);
35823599
return;
35833600
}
@@ -6538,7 +6555,11 @@ main(int argc, char **argv)
65386555
bench_start = thread->bench_start;
65396556
}
65406557

6541-
/* XXX should this be connection time? */
6558+
/*
6559+
* All connections should be already closed in threadRun(), so this
6560+
* disconnect_all() will be a no-op, but clean up the connecions just to
6561+
* be sure. We don't need to measure the disconnection delays here.
6562+
*/
65426563
disconnect_all(state, nclients);
65436564

65446565
/*
@@ -6827,9 +6848,7 @@ threadRun(void *arg)
68276848
}
68286849

68296850
done:
6830-
start = pg_time_now();
68316851
disconnect_all(state, nstate);
6832-
thread->conn_duration += pg_time_now() - start;
68336852

68346853
if (thread->logfile)
68356854
{

0 commit comments

Comments
 (0)