pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Fabien COELHO <coelho@cri.ensmp.fr>
To: PostgreSQL Developers <pgsql-hackers@postgresql.org>
Subject: pgbench - fix stats when using \sleep
Date: Tue, 23 Aug 2016 16:47:19 +0200 (CEST)
Message-ID: <alpine.DEB.2.20.1608231622170.7102@lancre> (raw)
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-hackers>


Hello devs,

When \sleep is used within a pgbench script it resets txn_scheduled which 
is used for computing stats about the transaction, resulting in absurd 
statistics:

  latency average = 0.649 ms *** ??? ***
  ...
  script statistics:
   - statement latencies in milliseconds:
           0.235  BEGIN;
         100.301  \sleep 100 ms
           0.351  END;

I probably created this bug when adding "--rate" in 9.4 and trying to be 
too clever. As nobody complained yet about it, I'm not sure it is worth 
fixing it there, though.

The fix is that "\sleep" does not have to interfere with the txn_scheduled 
field, see the attached patch.

  latency average = 100.237 ms  *** BETTER ***
  ...
  script statistics:
   - statement latencies in milliseconds:
           0.099  BEGIN;
         100.001  \sleep 100 ms
           0.135  END;

-- 
Fabien.

-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Attachments:

pgbench-lat-sleep-1.patch (text/x-diff, 1.4K) download diff --git a/src/bin/pgbench/pgbench.c b/src/bin/pgbench/pgbench.c index 8027955..de9b1b6 100644 --- a/src/bin/pgbench/pgbench.c +++ b/src/bin/pgbench/pgbench.c @@ -250,6 +250,7 @@ typedef struct int nvariables; /* number of variables */ bool vars_sorted; /* are variables sorted by name? */ int64 txn_scheduled; /* scheduled start time of transaction (usec) */ + int64 sleep_until; /* scheduled start time of next cmd (usec) */ instr_time txn_begin; /* used for measuring schedule lag times */ instr_time stmt_begin; /* used for measuring statement latencies */ int use_file; /* index in sql_scripts for this client */ @@ -1828,6 +1829,7 @@ top: } } + st->sleep_until = st->txn_scheduled; st->sleeping = true; st->throttling = true; st->is_throttled = true; @@ -1840,7 +1842,7 @@ top: { /* are we sleeping? */ if (INSTR_TIME_IS_ZERO(now)) INSTR_TIME_SET_CURRENT(now); - if (INSTR_TIME_GET_MICROSEC(now) < st->txn_scheduled) + if (INSTR_TIME_GET_MICROSEC(now) < st->sleep_until) return true; /* Still sleeping, nothing to do here */ /* Else done sleeping, go ahead with next command */ st->sleeping = false; @@ -2139,7 +2141,7 @@ top: usec *= 1000000; INSTR_TIME_SET_CURRENT(now); - st->txn_scheduled = INSTR_TIME_GET_MICROSEC(now) + usec; + st->sleep_until = INSTR_TIME_GET_MICROSEC(now) + usec; st->sleeping = true; st->listen = true;

view thread (2+ messages)  latest in thread

Message-ID: <alpine.DEB.2.20.1608231622170.7102@lancre>
Permalink:  ../alpine.DEB.2.20.1608231622170.7102@lancre/
Also on:    postgresql.org/message-id/alpine.DEB.2.20.1608231622170.7102@lancre

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-hackers@postgresql.org
  Cc: coelho@cri.ensmp.fr
  Subject: Re: pgbench - fix stats when using \sleep
  In-Reply-To: <alpine.DEB.2.20.1608231622170.7102@lancre>
  References: <alpine.DEB.2.20.1608231622170.7102@lancre>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox