Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 5174ca1

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 eeaf1b6 commit 5174ca1

File tree

1 file changed

+45
-2
lines changed

1 file changed

+45
-2
lines changed

src/bin/pgbench/pgbench.c

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3638,6 +3638,33 @@ threadRun(void *arg)
36383638
maxsock = sock;
36393639
}
36403640

3641+
/* also wake up to print the next progress report on time */
3642+
if (progress && min_usec > 0
3643+
#if !defined(PTHREAD_FORK_EMULATION)
3644+
&& thread->tid == 0
3645+
#endif /* !PTHREAD_FORK_EMULATION */
3646+
)
3647+
{
3648+
/* get current time if needed */
3649+
if (now_usec == 0)
3650+
{
3651+
instr_time now;
3652+
3653+
INSTR_TIME_SET_CURRENT(now);
3654+
now_usec = INSTR_TIME_GET_MICROSEC(now);
3655+
}
3656+
3657+
if (now_usec >= next_report)
3658+
min_usec = 0;
3659+
else if ((next_report - now_usec) < min_usec)
3660+
min_usec = next_report - now_usec;
3661+
}
3662+
3663+
/*
3664+
* Sleep until we receive data from the server, or a nap-time
3665+
* specified in the script ends, or it's time to print a progress
3666+
* report.
3667+
*/
36413668
if (min_usec > 0 && maxsock != -1)
36423669
{
36433670
int nsocks; /* return from select(2) */
@@ -3743,7 +3770,15 @@ threadRun(void *arg)
37433770
last_lags = lags;
37443771
last_report = now;
37453772
last_skipped = thread->throttle_latency_skipped;
3746-
next_report += (int64) progress *1000000;
3773+
3774+
/*
3775+
* Ensure that the next report is in the future, in case
3776+
* pgbench/postgres got stuck somewhere.
3777+
*/
3778+
do
3779+
{
3780+
next_report += (int64) progress *1000000;
3781+
} while (now >= next_report);
37473782
}
37483783
}
37493784
#else
@@ -3807,7 +3842,15 @@ threadRun(void *arg)
38073842
last_lags = lags;
38083843
last_report = now;
38093844
last_skipped = thread->throttle_latency_skipped;
3810-
next_report += (int64) progress *1000000;
3845+
3846+
/*
3847+
* Ensure that the next report is in the future, in case
3848+
* pgbench/postgres got stuck somewhere.
3849+
*/
3850+
do
3851+
{
3852+
next_report += (int64) progress *1000000;
3853+
} while (now >= next_report);
38113854
}
38123855
}
38133856
#endif /* PTHREAD_FORK_EMULATION */

0 commit comments

Comments
 (0)