1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-31 22:22:30 +03:00

Bug#38941: fast mutexes in MySQL 5.1 have mutex contention when calling random()

The problem is that MySQL's 'fast' mutex implementation uses the
random() routine to determine the spin delay. Unfortunately, the
routine interface is not thead-safe and some implementations (eg:
glibc) might use a internal lock to protect the RNG state, causing
excessive locking contention if lots of threads are spinning on
a MySQL's 'fast' mutex. The code was also misusing the value
of the RAND_MAX macro, this macro represents the largest value
that can be returned from the rand() function, not random().

The solution is to use the quite simple Park-Miller random number
generator. The initial seed is set to 1 because the previously used
generator wasn't being seeded -- the initial seed is 1 if srandom()
is not called.

Futhermore, the 'fast' mutex implementation has several shortcomings
and provides no measurable performance benefit. Therefore, its use is
not recommended unless it provides directly measurable results.
This commit is contained in:
Davi Arnaut
2008-10-15 19:21:00 -03:00
parent d320ca5c48
commit 28f29b7313
2 changed files with 26 additions and 2 deletions

View File

@@ -519,6 +519,7 @@ typedef struct st_my_pthread_fastmutex_t
{
pthread_mutex_t mutex;
uint spins;
uint rng_state;
} my_pthread_fastmutex_t;
void fastmutex_global_init(void);