Skip site navigation (1) Skip section navigation (2)

Re: pgbench internal contention

From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: pgbench internal contention
Date: 2011-07-30 13:08:00
Message-ID: CA+Tgmob0fkX533F7bFoTws0n-SkpjjCP8_16Edqez_wL_=B10Q@mail.gmail.com (view raw or flat)
Thread:
Lists: pgsql-hackers
On Sat, Jul 30, 2011 at 2:32 AM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> Robert Haas <robertmhaas(at)gmail(dot)com> writes:
>> On Fri, Jul 29, 2011 at 5:25 PM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>>> Portability, or rather lack of it.  What about using erand48, which we
>>> already have a dependency on (and substitute code for)?
>
>> Neither our implementation nor glibc's appears to be thread-safe,
>
> I think you're confusing srand48 with erand48.  The latter relies on a
> caller-supplied state value, so if it's not thread-safe the caller has
> only itself to blame.

I may be confused, but I'm not mixing it up with srand48.  On my
Fedora 12 VM, the man page says for erand48_r says, in relevant part:

SYNOPSIS
       #include <stdlib.h>

       int erand48_r(unsigned short xsubi[3],
                     struct drand48_data *buffer, double *result);

DESCRIPTION
       These functions are the reentrant analogs of the functions described in
       drand48(3).   Instead  of  modifying the global random generator state,
       they use the supplied data buffer.

And the glibc implementation of erand48 is this:

double
erand48 (xsubi)
     unsigned short int xsubi[3];
{
  double result;

  (void) __erand48_r (xsubi, &__libc_drand48_data, &result);

  return result;
}

On second look, I think our version is probably safe in this regard
since it appears modify only the state passed in and not anything
else.

*pokes a little more*

If I'm reading the code right, it only modifies __libc_drand48_data on
first call, so as long as we called erand48() at least once before
spawning the child threads, it would probably work.  That seems pretty
fragile in the face of the fact that they explicitly state that
they're modifying the global random generator state and that you
should use erand48_r() if you want reentrant behavior.  So I think if
we're going to go the erand48() route we probably ought to force
pgbench to always use our version rather than any OS-supplied version.

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

In response to

Responses

pgsql-hackers by date

Next:From: Andy ColsonDate: 2011-07-30 13:40:48
Subject: Re: pgbench internal contention
Previous:From: Martin AtukundaDate: 2011-07-30 09:56:39
Subject: Re: RC1 / Beta4?

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group