Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f65764a

Browse files
committed
Fix latency calculation when there are \sleep commands in the script.
We can't use txn_scheduled to hold the sleep-until time for \sleep, because that interferes with calculation of the latency of the transaction as whole. Backpatch to 9.4, where this bug was introduced. Fabien COELHO Discussion: <alpine.DEB.2.20.1608231622170.7102@lancre>
1 parent 156f974 commit f65764a

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/bin/pgbench/pgbench.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ typedef struct
250250
int nvariables; /* number of variables */
251251
bool vars_sorted; /* are variables sorted by name? */
252252
int64 txn_scheduled; /* scheduled start time of transaction (usec) */
253+
int64 sleep_until; /* scheduled start time of next cmd (usec) */
253254
instr_time txn_begin; /* used for measuring schedule lag times */
254255
instr_time stmt_begin; /* used for measuring statement latencies */
255256
int use_file; /* index in sql_scripts for this client */
@@ -1828,6 +1829,7 @@ doCustom(TState *thread, CState *st, StatsData *agg)
18281829
}
18291830
}
18301831

1832+
st->sleep_until = st->txn_scheduled;
18311833
st->sleeping = true;
18321834
st->throttling = true;
18331835
st->is_throttled = true;
@@ -1840,7 +1842,7 @@ doCustom(TState *thread, CState *st, StatsData *agg)
18401842
{ /* are we sleeping? */
18411843
if (INSTR_TIME_IS_ZERO(now))
18421844
INSTR_TIME_SET_CURRENT(now);
1843-
if (INSTR_TIME_GET_MICROSEC(now) < st->txn_scheduled)
1845+
if (INSTR_TIME_GET_MICROSEC(now) < st->sleep_until)
18441846
return true; /* Still sleeping, nothing to do here */
18451847
/* Else done sleeping, go ahead with next command */
18461848
st->sleeping = false;
@@ -2138,7 +2140,7 @@ doCustom(TState *thread, CState *st, StatsData *agg)
21382140
usec *= 1000000;
21392141

21402142
INSTR_TIME_SET_CURRENT(now);
2141-
st->txn_scheduled = INSTR_TIME_GET_MICROSEC(now) + usec;
2143+
st->sleep_until = INSTR_TIME_GET_MICROSEC(now) + usec;
21422144
st->sleeping = true;
21432145

21442146
st->listen = true;

0 commit comments

Comments
 (0)