Thread: pgsql: Simplify calculation of Poisson distributed delays in pgbench --

pgsql: Simplify calculation of Poisson distributed delays in pgbench --

From
Heikki Linnakangas
Date:
Simplify calculation of Poisson distributed delays in pgbench --rate mode.

The previous coding first generated a uniform random value between 0.0 and
1.0, then converted that to an integer between 1 and 10000, and divided that
again by 10000. Those conversions are unnecessary; we can use the double
value that pg_erand48() returns directly. While we're at it, put the logic
into a helper function, getPoissonRand().

The largest delay generated by the old coding was about 9.2 times the
average, because of the way the uniformly distributed value used for the
calculation was truncated to 1/10000 granularity. The new coding doesn't
have such clamping. With my laptop's DBL_MIN value, the maximum delay with
the new coding is about 700x the average. That seems acceptable - any
reasonable pgbench session should last long enough to average that out.

Backpatch to 9.4.

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/54a2d5b37b790cbfaf568fbbe6d2cc89650551d1

Modified Files
--------------
contrib/pgbench/pgbench.c |   33 ++++++++++++++++++++++-----------
1 file changed, 22 insertions(+), 11 deletions(-)


Re: pgsql: Simplify calculation of Poisson distributed delays in pgbench --

From
Robert Haas
Date:
On Thu, Sep 11, 2014 at 6:14 AM, Heikki Linnakangas
<heikki.linnakangas@iki.fi> wrote:
> Simplify calculation of Poisson distributed delays in pgbench --rate mode.
>
> The previous coding first generated a uniform random value between 0.0 and
> 1.0, then converted that to an integer between 1 and 10000, and divided that
> again by 10000. Those conversions are unnecessary; we can use the double
> value that pg_erand48() returns directly. While we're at it, put the logic
> into a helper function, getPoissonRand().
>
> The largest delay generated by the old coding was about 9.2 times the
> average, because of the way the uniformly distributed value used for the
> calculation was truncated to 1/10000 granularity. The new coding doesn't
> have such clamping. With my laptop's DBL_MIN value, the maximum delay with
> the new coding is about 700x the average. That seems acceptable - any
> reasonable pgbench session should last long enough to average that out.
>
> Backpatch to 9.4.

This, or the other pgbench patch you just committed, but I think this
one, broke the pgbench build on Windows.  mastodon says:

.\contrib\pgbench\pgbench.c(1271): error C2065: 'usec' : undeclared identifier

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


Re: pgsql: Simplify calculation of Poisson distributed delays in pgbench --

From
Heikki Linnakangas
Date:
On 09/11/2014 03:08 PM, Robert Haas wrote:
> On Thu, Sep 11, 2014 at 6:14 AM, Heikki Linnakangas
> <heikki.linnakangas@iki.fi> wrote:
>> Simplify calculation of Poisson distributed delays in pgbench --rate mode.
>>
>> The previous coding first generated a uniform random value between 0.0 and
>> 1.0, then converted that to an integer between 1 and 10000, and divided that
>> again by 10000. Those conversions are unnecessary; we can use the double
>> value that pg_erand48() returns directly. While we're at it, put the logic
>> into a helper function, getPoissonRand().
>>
>> The largest delay generated by the old coding was about 9.2 times the
>> average, because of the way the uniformly distributed value used for the
>> calculation was truncated to 1/10000 granularity. The new coding doesn't
>> have such clamping. With my laptop's DBL_MIN value, the maximum delay with
>> the new coding is about 700x the average. That seems acceptable - any
>> reasonable pgbench session should last long enough to average that out.
>>
>> Backpatch to 9.4.
>
> This, or the other pgbench patch you just committed, but I think this
> one, broke the pgbench build on Windows.  mastodon says:
>
> .\contrib\pgbench\pgbench.c(1271): error C2065: 'usec' : undeclared identifier

Thanks, fixed. (it was the other patch)

- Heikki