List:Commits« Previous MessageNext Message »
From:Vladislav Vaintroub Date:March 28 2010 1:43pm
Subject:bzr commit into mysql-trunk-windows-performance branch
(vvaintroub:2996) Bug#52102
View as plain text  
#At file:///H:/bzr/mysql-trunk-windows-performance/ based on revid:alik@stripped

 2996 Vladislav Vaintroub	2010-03-28
      Bug #52102 InnoDB Plugin shows performance drop compared to InnoDB 
      (Windows) 
      
      Based on benchmark results, removed Innodb's usage of 
      heavyweight Windows kernel object  (Mutex), replaced with 
      lightweight user-mode mostly CRITICAL_SECTION, aka os_fast_mutex_t 
      in Innodb terminology.
      
      Problem:
      In high concurrency situations innodb on Windows shows unusually high
      context switching,  resulting from locking  kernel mutexes. xperf 
      profiler sampled on context switches shows the highest usage rate 
      coming  from WaitForSingleObject). The CPU usage drops to ~60%, as do 
      the benchmark values  (# of transaction per second drops at about the 
      same rate).Note also that the performance drop was mostly seen after the 
      "atomics" patch was checked in, which would use slow kernel mutex more 
      often, after a short atomics spinning.
      
       Solution:Use CRITICAL_SECTION. It is is highly   optimized for the 
      purpose of serializing threads inside of the same process, so there is 
      no reason to fallback to kernel objects (which is designedto serialize 
      different processes) and expensive syscalls . Note, that fast mutexes 
      were also used   on any system other than Windows up to now, and the 
      patch mainlly removes the Windows  specific code.
      
      Also, fix os_fast_mutex_trylock to actually match the definition (it
      should be TryEnterCriticalSection, not EnterCriticalSection)
      
      Also, fix os_thread_yield to use SwitchToThread() instead of Sleep(0). 
      Sleep(0) does not  yield  to lower priority threads on older Windows.

    modified:
      storage/innobase/include/os0sync.ic
      storage/innobase/os/os0sync.c
      storage/innobase/os/os0thread.c
=== modified file 'storage/innobase/include/os0sync.ic'
--- a/storage/innobase/include/os0sync.ic	2009-05-27 09:45:59 +0000
+++ b/storage/innobase/include/os0sync.ic	2010-03-28 13:43:40 +0000
@@ -28,8 +28,7 @@ Created 9/6/1995 Heikki Tuuri
 #endif
 
 /**********************************************************//**
-Acquires ownership of a fast mutex. Currently in Windows this is the same
-as os_fast_mutex_lock!
+Acquires ownership of a fast mutex.
 @return	0 if success, != 0 if was reserved by another thread */
 UNIV_INLINE
 ulint
@@ -38,9 +37,9 @@ os_fast_mutex_trylock(
 	os_fast_mutex_t*	fast_mutex)	/*!< in: mutex to acquire */
 {
 #ifdef __WIN__
-	EnterCriticalSection(fast_mutex);
-
-	return(0);
+	if (TryEnterCriticalSection(fast_mutex))
+		return 0;
+	return(1);
 #else
 	/* NOTE that the MySQL my_pthread.h redefines pthread_mutex_trylock
 	so that it returns 0 on success. In the operating system

=== modified file 'storage/innobase/os/os0sync.c'
--- a/storage/innobase/os/os0sync.c	2009-11-30 11:32:05 +0000
+++ b/storage/innobase/os/os0sync.c	2010-03-28 13:43:40 +0000
@@ -495,15 +495,6 @@ os_mutex_create(
 	const char*	name)	/*!< in: the name of the mutex, if NULL
 				the mutex is created without a name */
 {
-#ifdef __WIN__
-	HANDLE		mutex;
-	os_mutex_t	mutex_str;
-
-	mutex = CreateMutex(NULL,	/* No security attributes */
-			    FALSE,		/* Initial state: no owner */
-			    (LPCTSTR) name);
-	ut_a(mutex);
-#else
 	os_fast_mutex_t*	mutex;
 	os_mutex_t		mutex_str;
 
@@ -512,7 +503,6 @@ os_mutex_create(
 	mutex = ut_malloc(sizeof(os_fast_mutex_t));
 
 	os_fast_mutex_init(mutex);
-#endif
 	mutex_str = ut_malloc(sizeof(os_mutex_str_t));
 
 	mutex_str->handle = mutex;
@@ -543,25 +533,11 @@ os_mutex_enter(
 /*===========*/
 	os_mutex_t	mutex)	/*!< in: mutex to acquire */
 {
-#ifdef __WIN__
-	DWORD	err;
-
-	ut_a(mutex);
-
-	/* Specify infinite time limit for waiting */
-	err = WaitForSingleObject(mutex->handle, INFINITE);
-
-	ut_a(err == WAIT_OBJECT_0);
-
-	(mutex->count)++;
-	ut_a(mutex->count == 1);
-#else
 	os_fast_mutex_lock(mutex->handle);
 
 	(mutex->count)++;
 
 	ut_a(mutex->count == 1);
-#endif
 }
 
 /**********************************************************//**
@@ -577,11 +553,7 @@ os_mutex_exit(
 	ut_a(mutex->count == 1);
 
 	(mutex->count)--;
-#ifdef __WIN__
-	ut_a(ReleaseMutex(mutex->handle));
-#else
 	os_fast_mutex_unlock(mutex->handle);
-#endif
 }
 
 /**********************************************************//**
@@ -610,15 +582,9 @@ os_mutex_free(
 		os_mutex_exit(os_sync_mutex);
 	}
 
-#ifdef __WIN__
-	ut_a(CloseHandle(mutex->handle));
-
-	ut_free(mutex);
-#else
 	os_fast_mutex_free(mutex->handle);
 	ut_free(mutex->handle);
 	ut_free(mutex);
-#endif
 }
 
 /*********************************************************//**

=== modified file 'storage/innobase/os/os0thread.c'
--- a/storage/innobase/os/os0thread.c	2009-12-12 20:38:59 +0000
+++ b/storage/innobase/os/os0thread.c	2010-03-28 13:43:40 +0000
@@ -247,7 +247,7 @@ os_thread_yield(void)
 /*=================*/
 {
 #if defined(__WIN__)
-	Sleep(0);
+	SwitchToThread();
 #elif (defined(HAVE_SCHED_YIELD) && defined(HAVE_SCHED_H))
 	sched_yield();
 #elif defined(HAVE_PTHREAD_YIELD_ZERO_ARG)


Attachment: [text/bzr-bundle] bzr/vvaintroub@mysql.com-20100328134340-fkuxo20vv4mbko0o.bundle
Thread
bzr commit into mysql-trunk-windows-performance branch(vvaintroub:2996) Bug#52102Vladislav Vaintroub28 Mar