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

From: Robert Haas <rhaas(at)postgresql(dot)org>
To: pgsql-committers(at)postgresql(dot)org
Subject: pgsql: Make pgbench use erand48() rather than random().
Date: 2011-08-03 20:29:51
Message-ID: E1Qoi4d-0005mC-25@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Make pgbench use erand48() rather than random().

glibc renders random() thread-safe by wrapping a futex lock around it;
testing reveals that this limits the performance of pgbench on machines
with many CPU cores. Rather than switching to random_r(), which is
only available on GNU systems and crashes unless you use undocumented
alchemy to initialize the random state properly, switch to our built-in
implementation of erand48(), which is both thread-safe and concurrent.

Since the list of reasons not to use the operating system's erand48()
is getting rather long, rename ours to pg_erand48() (and similarly
for our implementations of lrand48() and srand48()) and just always
use those. We were already doing this on Cygwin anyway, and the
glibc implementation is not quite thread-safe, so pgbench wouldn't
be able to use that either.

Per discussion with Tom Lane.

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/4af43ee3f165c8e4b332a7e680a44f4b7ba2d3c1

Modified Files
--------------
configure | 14 +-----------
configure.in | 8 +------
contrib/pgbench/pgbench.c | 32 ++++++++++++--------------
src/backend/optimizer/geqo/geqo_random.c | 2 +-
src/backend/optimizer/geqo/geqo_selection.c | 6 ++--
src/include/optimizer/geqo.h | 2 +-
src/include/pg_config.h.in | 3 --
src/include/port.h | 9 ++-----
src/port/Makefile | 4 +-
src/port/erand48.c | 18 +++++++++------
src/port/random.c | 2 +-
src/port/srandom.c | 2 +-
12 files changed, 40 insertions(+), 62 deletions(-)

Responses

Browse pgsql-committers by date

  From Date Subject
Next Message Tom Lane 2011-08-03 21:53:40 Re: pgsql: Make pgbench use erand48() rather than random().
Previous Message User Andrewsn 2011-08-03 20:16:03 ip4r - ip4r: First cut at ip6/ip6r/ipaddress/iprange support (2.0