Re: pgsql: Make pgbench use erand48() rather than random().

From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-committers(at)postgresql(dot)org
Subject: Re: pgsql: Make pgbench use erand48() rather than random().
Date: 2011-08-03 22:16:23
Message-ID: CA+TgmoY0-M_mx23460gMmWj_2Niia6ec5YkL2R21HvSuQ=i96g@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

On Wed, Aug 3, 2011 at 5:53 PM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> Robert Haas <rhaas(at)postgresql(dot)org> writes:
>> Make pgbench use erand48() rather than random().
>
> Hmm.  I find the pgbench part of this a bit questionable, specifically
> your decision to remove the code around line 2590 that installed a
> variable srandom() seed in child processes.  That would be okay if we
> were no longer depending on random() at all, but you are still depending
> on it to initialize the "per thread" state near line 2240.  AFAICS, this
> will result in each child process generating the same random
> sequence(s), which is exactly what we don't want.
>
> IOW, please put this back:
>
> -   /*
> -    * Set a different random seed in each child process.  Otherwise they all
> -    * inherit the parent's state and generate the same "random" sequence. (In
> -    * the threaded case, the different threads will obtain subsets of the
> -    * output of a single random() sequence, which should be okay for our
> -    * purposes.)
> -    */
> -   INSTR_TIME_SET_CURRENT(start_time);
> -   srandom(((unsigned int) INSTR_TIME_GET_MICROSEC(start_time)) +
> -           ((unsigned int) getpid()));
>
> or provide a credible explanation why we don't need it.

Unless I'm asleep at the switch, the srandom() calls you're worrying
about execute in the parent thread, which still makes its own call to
srandom().

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

In response to

Responses

Browse pgsql-committers by date

  From Date Subject
Next Message Tom Lane 2011-08-03 22:36:56 Re: pgsql: Make pgbench use erand48() rather than random().
Previous Message User Andrewsn 2011-08-03 22:08:41 ip4r - ip4r: fix some VARDATA / VARDATA_ANY misuses