Skip to content

Commit d760d94

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 b7ad093 commit d760d94

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
@@ -3552,8 +3552,12 @@ advanceConnectionState(TState *thread, CState *st, StatsData *agg)
35523552

35533553
if (is_connect)
35543554
{
3555+
pg_time_usec_t start = now;
3556+
3557+
pg_time_now_lazy(&start);
35553558
finishCon(st);
3556-
now = 0;
3559+
now = pg_time_now();
3560+
thread->conn_duration += now - start;
35573561
}
35583562

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

6560-
/* XXX should this be connection time? */
6577+
/*
6578+
* All connections should be already closed in threadRun(), so this
6579+
* disconnect_all() will be a no-op, but clean up the connecions just to
6580+
* be sure. We don't need to measure the disconnection delays here.
6581+
*/
65616582
disconnect_all(state, nclients);
65626583

65636584
/*
@@ -6846,9 +6867,7 @@ threadRun(void *arg)
68466867
}
68476868

68486869
done:
6849-
start = pg_time_now();
68506870
disconnect_all(state, nstate);
6851-
thread->conn_duration += pg_time_now() - start;
68526871

68536872
if (thread->logfile)
68546873
{

0 commit comments

Comments
 (0)