Skip to content

Commit 9031ff9

Browse files
committed
Fix pgbench progress report behaviour when pgbench or a query gets stuck.
There were two issues here. First, if a query got stuck so that it took e.g. 5 seconds, and progress interval was 1 second, no progress reports were printed until the query returned. Fix so that we wake up specifically to print the progress report. Secondly, if pgbench got stuck so that it would nevertheless not print a progress report on time, and enough time passes that it's already time to print the next progress report, just skip the one that was missed. Before this patch, it would print the missed one with 0 TPS immediately after the previous one. Fabien Coelho. Backpatch to 9.4, where progress reports were added.
1 parent ba3deee commit 9031ff9

File tree

1 file changed

+45
-2
lines changed

1 file changed

+45
-2
lines changed

src/bin/pgbench/pgbench.c

+45-2
Original file line numberDiff line numberDiff line change
@@ -3649,6 +3649,33 @@ threadRun(void *arg)
36493649
maxsock = sock;
36503650
}
36513651

3652+
/* also wake up to print the next progress report on time */
3653+
if (progress && min_usec > 0
3654+
#if !defined(PTHREAD_FORK_EMULATION)
3655+
&& thread->tid == 0
3656+
#endif /* !PTHREAD_FORK_EMULATION */
3657+
)
3658+
{
3659+
/* get current time if needed */
3660+
if (now_usec == 0)
3661+
{
3662+
instr_time now;
3663+
3664+
INSTR_TIME_SET_CURRENT(now);
3665+
now_usec = INSTR_TIME_GET_MICROSEC(now);
3666+
}
3667+
3668+
if (now_usec >= next_report)
3669+
min_usec = 0;
3670+
else if ((next_report - now_usec) < min_usec)
3671+
min_usec = next_report - now_usec;
3672+
}
3673+
3674+
/*
3675+
* Sleep until we receive data from the server, or a nap-time
3676+
* specified in the script ends, or it's time to print a progress
3677+
* report.
3678+
*/
36523679
if (min_usec > 0 && maxsock != -1)
36533680
{
36543681
int nsocks; /* return from select(2) */
@@ -3754,7 +3781,15 @@ threadRun(void *arg)
37543781
last_lags = lags;
37553782
last_report = now;
37563783
last_skipped = thread->throttle_latency_skipped;
3757-
next_report += (int64) progress *1000000;
3784+
3785+
/*
3786+
* Ensure that the next report is in the future, in case
3787+
* pgbench/postgres got stuck somewhere.
3788+
*/
3789+
do
3790+
{
3791+
next_report += (int64) progress *1000000;
3792+
} while (now >= next_report);
37583793
}
37593794
}
37603795
#else
@@ -3818,7 +3853,15 @@ threadRun(void *arg)
38183853
last_lags = lags;
38193854
last_report = now;
38203855
last_skipped = thread->throttle_latency_skipped;
3821-
next_report += (int64) progress *1000000;
3856+
3857+
/*
3858+
* Ensure that the next report is in the future, in case
3859+
* pgbench/postgres got stuck somewhere.
3860+
*/
3861+
do
3862+
{
3863+
next_report += (int64) progress *1000000;
3864+
} while (now >= next_report);
38223865
}
38233866
}
38243867
#endif /* PTHREAD_FORK_EMULATION */

0 commit comments

Comments
 (0)