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

Commit 9d6352a

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 0eaa49a commit 9d6352a

File tree

1 file changed

+45
-2
lines changed

1 file changed

+45
-2
lines changed

contrib/pgbench/pgbench.c

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3213,6 +3213,33 @@ threadRun(void *arg)
32133213
maxsock = sock;
32143214
}
32153215

3216+
/* also wake up to print the next progress report on time */
3217+
if (progress && min_usec > 0
3218+
#if !defined(PTHREAD_FORK_EMULATION)
3219+
&& thread->tid == 0
3220+
#endif /* !PTHREAD_FORK_EMULATION */
3221+
)
3222+
{
3223+
/* get current time if needed */
3224+
if (now_usec == 0)
3225+
{
3226+
instr_time now;
3227+
3228+
INSTR_TIME_SET_CURRENT(now);
3229+
now_usec = INSTR_TIME_GET_MICROSEC(now);
3230+
}
3231+
3232+
if (now_usec >= next_report)
3233+
min_usec = 0;
3234+
else if ((next_report - now_usec) < min_usec)
3235+
min_usec = next_report - now_usec;
3236+
}
3237+
3238+
/*
3239+
* Sleep until we receive data from the server, or a nap-time
3240+
* specified in the script ends, or it's time to print a progress
3241+
* report.
3242+
*/
32163243
if (min_usec > 0 && maxsock != -1)
32173244
{
32183245
int nsocks; /* return from select(2) */
@@ -3314,7 +3341,15 @@ threadRun(void *arg)
33143341
last_sqlats = sqlats;
33153342
last_lags = lags;
33163343
last_report = now;
3317-
next_report += (int64) progress *1000000;
3344+
3345+
/*
3346+
* Ensure that the next report is in the future, in case
3347+
* pgbench/postgres got stuck somewhere.
3348+
*/
3349+
do
3350+
{
3351+
next_report += (int64) progress *1000000;
3352+
} while (now >= next_report);
33183353
}
33193354
}
33203355
#else
@@ -3374,7 +3409,15 @@ threadRun(void *arg)
33743409
last_sqlats = sqlats;
33753410
last_lags = lags;
33763411
last_report = now;
3377-
next_report += (int64) progress *1000000;
3412+
3413+
/*
3414+
* Ensure that the next report is in the future, in case
3415+
* pgbench/postgres got stuck somewhere.
3416+
*/
3417+
do
3418+
{
3419+
next_report += (int64) progress *1000000;
3420+
} while (now >= next_report);
33783421
}
33793422
}
33803423
#endif /* PTHREAD_FORK_EMULATION */

0 commit comments

Comments
 (0)