[MDEV-21256] Improve InnoDB random number generator performance Created: 2019-12-09  Updated: 2020-02-01  Resolved: 2019-12-10

Status: Closed
Project: MariaDB Server
Component/s: Storage Engine - InnoDB
Affects Version/s: 5.5, 10.0, 10.1, 10.2, 10.3, 10.4, 10.5
Fix Version/s: 10.2.31, 10.3.22, 10.4.12

Type: Bug Priority: Major
Reporter: Marko Mäkelä Assignee: Marko Mäkelä
Resolution: Fixed Votes: 0
Labels: performance

Issue Links:
Relates
relates to MDEV-14482 Cache line contention on ut_rnd_ulint... Closed
relates to MDEV-21285 RAND()/ENCODE() lack of concurrency Open

 Description   

InnoDB appears to contain two different implementations of a random number generator: page_cur_lcg_prng() and ut_rnd_gen_next_ulint(). Both suffer from a scalability issue (and race condition) due to sharing the internal state between multiple threads.

We should investigate whether replacing the linear congruential generator with a Galois linear-feedback shift register would improve the performance, and we should attempt to use thread-local storage for the seed values.

Last but not least, the function page_cur_open_on_rnd_user_rec() is using a linear search for positioning the cursor, instead of invoking page_rec_get_nth().

Side note: It appears that pick_next() causes crashes in ./mtr --suite=innodb_gis if the sequence of random numbers is replaced with a constant.



 Comments   
Comment by Marko Mäkelä [ 2019-12-09 ]

Perhaps we should also backport the MDEV-14482 fix from 10.3 to 10.2. I believe that that was what originally caught the eye of danblack (and prompted me to clean up this code).

Comment by Daniel Black [ 2019-12-10 ]

Community related fix https://github.com/akopytov/sysbench/commit/e24a028409da3dc892f026a20ac371ecf8e2ef42

Generated at Thu Feb 08 09:05:46 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.