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: (view raw, whole thread or download thread mbox)
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:

       #include <stdlib.h>

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

       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:

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

*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
The Enterprise PostgreSQL Company

In response to


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-2017 The PostgreSQL Global Development Group