Skip to content

Commit 40c3fe4

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 6cc54f3 commit 40c3fe4

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 */
@@ -1830,6 +1831,7 @@ doCustom(TState *thread, CState *st, StatsData *agg)
18301831
}
18311832
}
18321833

1834+
st->sleep_until = st->txn_scheduled;
18331835
st->sleeping = true;
18341836
st->throttling = true;
18351837
st->is_throttled = true;
@@ -1842,7 +1844,7 @@ doCustom(TState *thread, CState *st, StatsData *agg)
18421844
{ /* are we sleeping? */
18431845
if (INSTR_TIME_IS_ZERO(now))
18441846
INSTR_TIME_SET_CURRENT(now);
1845-
if (INSTR_TIME_GET_MICROSEC(now) < st->txn_scheduled)
1847+
if (INSTR_TIME_GET_MICROSEC(now) < st->sleep_until)
18461848
return true; /* Still sleeping, nothing to do here */
18471849
/* Else done sleeping, go ahead with next command */
18481850
st->sleeping = false;
@@ -2141,7 +2143,7 @@ doCustom(TState *thread, CState *st, StatsData *agg)
21412143
usec *= 1000000;
21422144

21432145
INSTR_TIME_SET_CURRENT(now);
2144-
st->txn_scheduled = INSTR_TIME_GET_MICROSEC(now) + usec;
2146+
st->sleep_until = INSTR_TIME_GET_MICROSEC(now) + usec;
21452147
st->sleeping = true;
21462148

21472149
st->listen = true;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy