diff options
author | Vladislav Vaintroub <vvaintroub@mysql.com> | 2010-10-04 13:03:11 +0200 |
---|---|---|
committer | Vladislav Vaintroub <vvaintroub@mysql.com> | 2010-10-04 13:03:11 +0200 |
commit | 367bfa41066bfe88b720f530e938e2c4cbf79205 (patch) | |
tree | 54feedb66cda23603b48232147274cefc03564cf /mysys/my_winthread.c | |
parent | 34388f53153b309ad4cb925e392c13dfb1bb62dc (diff) | |
download | mariadb-git-367bfa41066bfe88b720f530e938e2c4cbf79205.tar.gz |
A follow-up to the patch for bug #56405 "Deadlock in the MDL deadlock
detector". This patch addresses performance regression in OLTP_RO/MyISAM
test on Windows introduced by the fix for bug #56405. Thus it makes
original patch acceptable as a solution for bug #56585 "Slowdown of
readonly sysbench benchmarks (e.g point_select) on Windows 5.5".
With this patch, MySQL will use native Windows condition variables and
reader-writer locks if they are supported by the OS.
This speeds up MyISAM and the effect comes mostly from using native
rwlocks. Native conditions improve scalability with higher number of
concurrent users in other situations, e.g for prlocks.
Benchmark numbers for this patch as measured on Win2008R2 quad
core machine are attached to the bug report.
( direct link http://bugs.mysql.com/file.php?id=15883 )
Note that currently we require at least Windows7/WS2008R2 for
reader-writer locks, even though native rwlock is available also on Vista.
Reason is that "trylock" APIs are missing on Vista, and trylock is used in
the server (in a single place in query cache).
While this patch could have been written differently, to enable the native
rwlock optimization also on Vista/WS2008 (e.g using native locks everywhere
but portable implementation in query cache), this would come at the
expense of the code clarity, as it would introduce a new "try-able" rwlock
type, to handle Vista case.
Another way to improve performance for the special case
(OLTP_RO/MYISAM/Vista) would be to eliminate "trylock" usage from server,
but this is outside of the scope here.
Native conditions variables are used beginning with Vista though the effect
of using condition variables alone is not measurable in this benchmark.
But when used together with native rwlocks on Win7, native conditions improve
performance in high-concurrency OLTP_RO/MyISAM (128 and more sysbench
users).
Diffstat (limited to 'mysys/my_winthread.c')
-rw-r--r-- | mysys/my_winthread.c | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/mysys/my_winthread.c b/mysys/my_winthread.c index aecb2f7cc78..49534370a2f 100644 --- a/mysys/my_winthread.c +++ b/mysys/my_winthread.c @@ -155,8 +155,19 @@ int pthread_cancel(pthread_t thread) int my_pthread_once(my_pthread_once_t *once_control, void (*init_routine)(void)) { - LONG state= InterlockedCompareExchange(once_control, MY_PTHREAD_ONCE_INPROGRESS, - MY_PTHREAD_ONCE_INIT); + LONG state; + + /* + Do "dirty" read to find out if initialization is already done, to + save an interlocked operation in common case. Memory barriers are ensured by + Visual C++ volatile implementation. + */ + if (*once_control == MY_PTHREAD_ONCE_DONE) + return 0; + + state= InterlockedCompareExchange(once_control, MY_PTHREAD_ONCE_INPROGRESS, + MY_PTHREAD_ONCE_INIT); + switch(state) { case MY_PTHREAD_ONCE_INIT: |