summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHeikki Linnakangas <heikki.linnakangas@iki.fi>2015-07-03 11:04:57 +0300
committerHeikki Linnakangas <heikki.linnakangas@iki.fi>2015-07-03 11:15:27 +0300
commit9d6352aaae1bf43f06253dcc931534a5254a937a (patch)
tree424b029f4f977af19bff844ca5db994eb045dc45
parent0eaa49a5c4848f3f3fa5588dc58cb9af47779fb4 (diff)
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.
-rw-r--r--contrib/pgbench/pgbench.c47
1 files changed, 45 insertions, 2 deletions
diff --git a/contrib/pgbench/pgbench.c b/contrib/pgbench/pgbench.c
index f9e1549b23f..418ac58943f 100644
--- a/contrib/pgbench/pgbench.c
+++ b/contrib/pgbench/pgbench.c
@@ -3213,6 +3213,33 @@ threadRun(void *arg)
maxsock = sock;
}
+ /* also wake up to print the next progress report on time */
+ if (progress && min_usec > 0
+#if !defined(PTHREAD_FORK_EMULATION)
+ && thread->tid == 0
+#endif /* !PTHREAD_FORK_EMULATION */
+ )
+ {
+ /* get current time if needed */
+ if (now_usec == 0)
+ {
+ instr_time now;
+
+ INSTR_TIME_SET_CURRENT(now);
+ now_usec = INSTR_TIME_GET_MICROSEC(now);
+ }
+
+ if (now_usec >= next_report)
+ min_usec = 0;
+ else if ((next_report - now_usec) < min_usec)
+ min_usec = next_report - now_usec;
+ }
+
+ /*
+ * Sleep until we receive data from the server, or a nap-time
+ * specified in the script ends, or it's time to print a progress
+ * report.
+ */
if (min_usec > 0 && maxsock != -1)
{
int nsocks; /* return from select(2) */
@@ -3314,7 +3341,15 @@ threadRun(void *arg)
last_sqlats = sqlats;
last_lags = lags;
last_report = now;
- next_report += (int64) progress *1000000;
+
+ /*
+ * Ensure that the next report is in the future, in case
+ * pgbench/postgres got stuck somewhere.
+ */
+ do
+ {
+ next_report += (int64) progress *1000000;
+ } while (now >= next_report);
}
}
#else
@@ -3374,7 +3409,15 @@ threadRun(void *arg)
last_sqlats = sqlats;
last_lags = lags;
last_report = now;
- next_report += (int64) progress *1000000;
+
+ /*
+ * Ensure that the next report is in the future, in case
+ * pgbench/postgres got stuck somewhere.
+ */
+ do
+ {
+ next_report += (int64) progress *1000000;
+ } while (now >= next_report);
}
}
#endif /* PTHREAD_FORK_EMULATION */