On 09/09/2014 01:49 PM, Heikki Linnakangas wrote:
I think we have to reconsider what we're reporting in 9.4, when --rate
is enabled, even though it's already very late in the release cycle.
It's a bad idea to change the definition of latency between 9.4 and 9.5,
so let's get it right in 9.4.

As per the attached patch. I think we should commit this to 9.4. Any objections?

The text this patch adds to the documentation needs some rewording, though. As does this existing paragraph:

High rate limit schedule lag values, that is lag values that are
large compared to the actual transaction latency, indicate that
something is amiss in the throttling process. High schedule lag can
highlight a subtle problem there even if the target rate limit is met
in the end. One possible cause of schedule lag is insufficient
pgbench threads to handle all of the clients. To improve that,
consider reducing the number of clients, increasing the number of
threads in pgbench, or running pgbench on a separate host. Another
possibility is that the database is not keeping up with the load at
some point. When that happens, you will have to reduce the expected
transaction rate to lower schedule lag.

It took me ages to parse "high rate limit schedule lag values".

- Heikki

diff --git a/contrib/pgbench/pgbench.c b/contrib/pgbench/pgbench.c
index 2f7d80e..bf9c4ea 100644
--- a/contrib/pgbench/pgbench.c
+++ b/contrib/pgbench/pgbench.c
@@ -1087,8 +1087,22 @@ top:
 			int64		latency;
 
 			INSTR_TIME_SET_CURRENT(diff);
-			INSTR_TIME_SUBTRACT(diff, st->txn_begin);
-			latency = INSTR_TIME_GET_MICROSEC(diff);
+
+			if (throttle_delay)
+			{
+				/*
+				 * Under throttling, compute latency from the scheduled start
+				 * time, not the actual transaction start.
+				 */
+				int64 now = INSTR_TIME_GET_MICROSEC(diff);
+				latency = now - thread->throttle_trigger;
+			}
+			else
+			{
+				INSTR_TIME_SUBTRACT(diff, st->txn_begin);
+				latency = INSTR_TIME_GET_MICROSEC(diff);
+			}
+
 			st->txn_latencies += latency;
 
 			/*
diff --git a/doc/src/sgml/pgbench.sgml b/doc/src/sgml/pgbench.sgml
index b479105..75fd8ec 100644
--- a/doc/src/sgml/pgbench.sgml
+++ b/doc/src/sgml/pgbench.sgml
@@ -403,8 +403,10 @@ pgbench <optional> <replaceable>options</> </optional> <replaceable>dbname</>
         Show progress report every <literal>sec</> seconds.  The report
         includes the time since the beginning of the run, the tps since the
         last report, and the transaction latency average and standard
-        deviation since the last report.  Under throttling (<option>-R</>), it
-        also includes the average schedule lag time since the last report.
+        deviation since the last report.  Under throttling (<option>-R</>),
+        the latency is computed with respect to the transaction scheduled
+        start time, not the actual transaction beginning time, thus it also
+        includes the average schedule lag time.
        </para>
       </listitem>
      </varlistentry>
@@ -452,6 +454,17 @@ pgbench <optional> <replaceable>options</> </optional> <replaceable>dbname</>
         output.
        </para>
        <para>
+        Also, when throttling is active, the transaction latency reported
+        at the end of the run is computed from the scheduled start time, not
+        the actual transaction start time, so it includes the lag time.
+        The perspective is from the client point of view who wanted to perform
+        a transaction but could not even start it for some time.  Very high
+        latencies may be reported when the transactions are lagging behind
+        schedule.  The transaction latency with respect to the actual
+        transaction start time can be computed by substracting the transaction
+        lag time from the reported latency.
+       </para>
+       <para>
         High rate limit schedule lag values, that is lag values that are large
         compared to the actual transaction latency, indicate that something is
         amiss in the throttling process.  High schedule lag can highlight a subtle
-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to