pgbench randomness initialization

From: Andres Freund <andres(at)anarazel(dot)de>
To: pgsql-hackers(at)postgresql(dot)org
Cc: Robert Haas <robertmhaas(at)gmail(dot)com>
Subject: pgbench randomness initialization
Date: 2016-04-07 08:27:11
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers


et al I was wondering why it's a good idea for pgbench to do
srandom((unsigned int) INSTR_TIME_GET_MICROSEC(start_time));
to initialize randomness and then
for (i = 0; i < nthreads; i++)
thread->random_state[0] = random();
thread->random_state[1] = random();
thread->random_state[2] = random();
to initialize the individual thread random state which is then used by

To me it seems better to instead initialize srandom() with a known value
(say, uh, 0). Or even better don't use random() at all, and fill a
global pg_erand48() with a known state; and use pg_erand48() to
initialize the thread states.

Obviously that doesn't make pgbench entirely reproducible, but it seems
a lot better than now. Individual threads would do work in a
reproducible order.

I see very little reason to have the current behaviour, or at the very
least not by default.


Andres Freund


Browse pgsql-hackers by date

  From Date Subject
Next Message Andres Freund 2016-04-07 08:43:24 Re: Move PinBuffer and UnpinBuffer to atomics
Previous Message Simon Riggs 2016-04-07 08:26:11 Re: WIP: Detecting SSI conflicts before reporting constraint violations