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

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



Modified Files
configure                                   |   14 +-----------                                |    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/                  |    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(-)


pgsql-committers by date

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

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