Re: random() (was Re: New GUC to sample log queries)
Fabien COELHO <coelho@cri.ensmp.fr>
From: Fabien COELHO <coelho@cri.ensmp.fr>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Alvaro Herrera <alvherre@2ndquadrant.com>,
Adrien Nayrat <adrien.nayrat@anayrat.info>,
Thomas Munro <thomas.munro@enterprisedb.com>,
Dmitry Dolgov <9erthalion6@gmail.com>,
Tomas Vondra <tomas.vondra@2ndquadrant.com>, vik.fearing@2ndquadrant.com,
Robert Haas <robertmhaas@gmail.com>,
Michael Paquier <michael@paquier.xyz>,
David Rowley <david.rowley@2ndquadrant.com>,
Pg Hackers <pgsql-hackers@postgresql.org>
Date: 2018-12-28T11:07:30Z
Lists: pgsql-hackers
Attachments
- test_pg_erand48.c (text/x-csrc)
- test_xoroshi256ss.c (text/x-csrc)
>> - lrand48 (48 bits state as 3 uint16) is 29 ops >> (10 =, 8 *, 7 +, 4 >>) > > - xoshiro256** (256 bits states as 4 uint64) is 24 ops (18 if rot in hw) > 8 =, 2 *, 2 +, 5 <<, 5 ^, 2 | > > See http://vigna.di.unimi.it/xorshift/ Small benchmark on my laptop with gcc-7.3 -O3: - pg_lrand48 takes 4.0 seconds to generate 1 billion 32-bit ints - xoshiro256** takes 1.6 seconds to generate 1 billion 64-bit ints With -O2 it is 4.8 and 3.4 seconds, respectively. So significantly better speed _and_ quality are quite achievable. Note that small attempt at optimizing these functions (inline constants, array replaced with scalars) did not yield significant improvements. -- Fabien.
Commits
-
Use pg_strong_random() to select each server process's random seed.
- 4203842a1cd0 12.0 landed
-
Use a separate random seed for SQL random()/setseed() functions.
- 6645ad6bdd81 12.0 landed
-
Marginal performance hacking in erand48.c.
- 6b9bba2df8d4 12.0 landed
-
Fix latent problem with pg_jrand48().
- e09046641114 12.0 landed
- f256995e33d2 10.7 landed
- d58e01f8abe2 11.2 landed
-
Silence compiler warning
- 9dc122585551 12.0 landed
-
Add log_statement_sample_rate parameter
- 88bdbd3f7460 12.0 landed