List:Commits« Previous MessageNext Message »
From:Kelly Long Date:July 28 2009 9:54pm
Subject:bzr commit into mysql-5.4 branch (k.long:2865) WL#4976
View as plain text  
#At file:///FC/MYSQL/wa-2008-BZR/lcl/mysql-summit-0.3-innodb_plugin/ based on revid:k.long@stripped

 2865 Kelly Long	2009-07-28
      WL#4976 - Introduce timer-based InnoDB Thread Concurrency applied to innodb_plugin

    modified:
      storage/innobase/plug.in
      storage/innodb_plugin/handler/ha_innodb.cc
      storage/innodb_plugin/include/srv0srv.h
      storage/innodb_plugin/srv/srv0srv.c
=== modified file 'storage/innobase/plug.in'
--- a/storage/innobase/plug.in	2008-12-14 18:54:01 +0000
+++ b/storage/innobase/plug.in	2009-07-28 21:53:58 +0000
@@ -1,7 +1,7 @@
 MYSQL_STORAGE_ENGINE(innobase,  innodb, [InnoDB Storage Engine],
         [Transactional Tables using InnoDB], [max,max-no-ndb])
 MYSQL_PLUGIN_DIRECTORY(innobase, [storage/innobase])
-MYSQL_PLUGIN_STATIC(innobase,   [libinnobase.a])
+#MYSQL_PLUGIN_STATIC(innobase,   [libinnobase.a])
 MYSQL_PLUGIN_DYNAMIC(innobase,  [ha_innodb.la])
 MYSQL_PLUGIN_ACTIONS(innobase,  [
   AC_CHECK_LIB(rt, aio_read, [innodb_system_libs="-lrt"])

=== modified file 'storage/innodb_plugin/handler/ha_innodb.cc'
--- a/storage/innodb_plugin/handler/ha_innodb.cc	2009-07-28 21:03:58 +0000
+++ b/storage/innodb_plugin/handler/ha_innodb.cc	2009-07-28 21:53:58 +0000
@@ -159,6 +159,9 @@ static char*	internal_innobase_data_file
 
 static char*	innodb_version_str = (char*) INNODB_VERSION_STR;
 
+/* Use timer based InnoDB concurrency throttling flag */
+static my_bool innobase_thread_concurrency_timer_based;
+
 /* The following counter is used to convey information to InnoDB
 about server activity: in selects it is not sensible to call
 srv_active_wake_master_thread after each fetch or search, we only do
@@ -2114,6 +2117,9 @@ innobase_change_buffering_inited_ok:
 	srv_n_log_files = (ulint) innobase_log_files_in_group;
 	srv_log_file_size = (ulint) innobase_log_file_size;
 
+        srv_thread_concurrency_timer_based =
+          (ibool) innobase_thread_concurrency_timer_based;
+
 #ifdef UNIV_LOG_ARCHIVE
 	srv_log_archive_on = (ulint) innobase_log_archive;
 #endif /* UNIV_LOG_ARCHIVE */
@@ -9688,6 +9694,12 @@ static MYSQL_SYSVAR_ULONG(spin_wait_dela
   "Maximum delay between polling for a spin lock (5 by default)",
   NULL, NULL, 5L, 0L, ~0L, 0);
 
+static MYSQL_SYSVAR_BOOL(thread_concurrency_timer_based,
+                         innobase_thread_concurrency_timer_based,
+                         PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY,
+  "Use InnoDB timer based concurrency throttling. ",
+  NULL, NULL, TRUE);
+
 static MYSQL_SYSVAR_ULONG(thread_concurrency, srv_thread_concurrency,
   PLUGIN_VAR_RQCMDARG,
   "Helps in performance tuning in heavily concurrent environments. Sets the maximum number of threads allowed inside InnoDB. Value 0 will disable the thread throttling.",
@@ -9774,6 +9786,7 @@ static struct st_mysql_sys_var* innobase
   MYSQL_SYSVAR(sync_spin_loops),
   MYSQL_SYSVAR(spin_wait_delay),
   MYSQL_SYSVAR(table_locks),
+  MYSQL_SYSVAR(thread_concurrency_timer_based),
   MYSQL_SYSVAR(thread_concurrency),
   MYSQL_SYSVAR(thread_sleep_delay),
   MYSQL_SYSVAR(autoinc_lock_mode),

=== modified file 'storage/innodb_plugin/include/srv0srv.h'
--- a/storage/innodb_plugin/include/srv0srv.h	2009-07-28 21:03:58 +0000
+++ b/storage/innodb_plugin/include/srv0srv.h	2009-07-28 21:53:58 +0000
@@ -122,6 +122,8 @@ extern ulint	srv_buf_pool_curr_size;	/*!
 extern ulint	srv_mem_pool_size;
 extern ulint	srv_lock_table_size;
 
+extern ibool    srv_thread_concurrency_timer_based;
+
 extern ulint	srv_n_file_io_threads;
 
 #ifdef UNIV_LOG_ARCHIVE

=== modified file 'storage/innodb_plugin/srv/srv0srv.c'
--- a/storage/innodb_plugin/srv/srv0srv.c	2009-07-28 21:03:58 +0000
+++ b/storage/innodb_plugin/srv/srv0srv.c	2009-07-28 21:53:58 +0000
@@ -278,6 +278,7 @@ Value 10 should be good if there are les
 computer. Bigger computers need bigger values. Value 0 will disable the
 concurrency check. */
 
+ibool   srv_thread_concurrency_timer_based = TRUE;
 UNIV_INTERN ulong	srv_thread_concurrency	= 0;
 
 /* this mutex protects srv_conc data structures */
@@ -956,6 +957,91 @@ UNIV_INTERN ulong	srv_max_purge_lag		= 0
 /*********************************************************************//**
 Puts an OS thread to wait if there are too many concurrent threads
 (>= srv_thread_concurrency) inside InnoDB. The threads wait in a FIFO queue. */
+static void
+inc_srv_conc_n_threads(lint *n_threads)
+{
+  *n_threads = os_atomic_increment(&srv_conc_n_threads, 1);
+}
+
+static void
+dec_srv_conc_n_threads()
+{
+  os_atomic_increment(&srv_conc_n_threads, -1);
+}
+
+static void
+print_already_in_error(trx_t* trx)
+{
+	ut_print_timestamp(stderr);
+	fputs("  InnoDB: Error: trying to declare trx"
+	      " to enter InnoDB, but\n"
+	      "InnoDB: it already is declared.\n", stderr);
+	trx_print(stderr, trx, 0);
+	putc('\n', stderr);
+        return;
+}
+
+static void
+enter_innodb_with_tickets(trx_t* trx)
+{
+	trx->declared_to_be_inside_innodb = TRUE;
+	trx->n_tickets_to_enter_innodb = SRV_FREE_TICKETS_TO_ENTER;
+        return;
+}
+
+static void
+srv_conc_enter_innodb_timer_based(trx_t* trx)
+{
+        lint               conc_n_threads;
+        ibool              has_yielded = FALSE;
+        ulint              has_slept = 0;
+
+	if (trx->declared_to_be_inside_innodb) {
+                print_already_in_error(trx);
+        }
+retry:
+	if (srv_conc_n_threads < (lint) srv_thread_concurrency) {
+                inc_srv_conc_n_threads(&conc_n_threads);
+	        if (conc_n_threads <= srv_thread_concurrency) {
+                       enter_innodb_with_tickets(trx);
+                       return;
+                }
+                dec_srv_conc_n_threads(&conc_n_threads);
+       }
+       if (!has_yielded)
+       {
+               has_yielded = TRUE;
+               os_thread_yield();
+               goto retry;
+       }
+       if (trx->has_search_latch
+           || NULL != UT_LIST_GET_FIRST(trx->trx_locks)) {
+
+                inc_srv_conc_n_threads(&conc_n_threads);
+                enter_innodb_with_tickets(trx);
+                return;
+       }
+       if (has_slept < 2)
+       {
+               trx->op_info = "sleeping before entering InnoDB";
+               os_thread_sleep(10000);
+               trx->op_info = "";
+               has_slept++;
+       }
+       inc_srv_conc_n_threads(&conc_n_threads);
+       enter_innodb_with_tickets(trx);
+       return;
+}
+
+static void
+srv_conc_exit_innodb_timer_based(trx_t* trx)
+{
+        dec_srv_conc_n_threads();
+	trx->declared_to_be_inside_innodb = FALSE;
+	trx->n_tickets_to_enter_innodb = 0;
+        return;
+}
+
 UNIV_INTERN
 void
 srv_conc_enter_innodb(
@@ -986,15 +1072,17 @@ srv_conc_enter_innodb(
 		return;
 	}
 
+#ifdef UNIV_SYNC_ATOMIC
+        if (srv_thread_concurrency_timer_based) {
+          srv_conc_enter_innodb_timer_based(trx);
+          return;
+        }
+#endif
+
 	os_fast_mutex_lock(&srv_conc_mutex);
 retry:
 	if (trx->declared_to_be_inside_innodb) {
-		ut_print_timestamp(stderr);
-		fputs("  InnoDB: Error: trying to declare trx"
-		      " to enter InnoDB, but\n"
-		      "InnoDB: it already is declared.\n", stderr);
-		trx_print(stderr, trx, 0);
-		putc('\n', stderr);
+                print_already_in_error(trx);
 		os_fast_mutex_unlock(&srv_conc_mutex);
 
 		return;
@@ -1123,10 +1211,20 @@ srv_conc_force_enter_innodb(
 	trx_t*	trx)	/*!< in: transaction object associated with the
 			thread */
 {
+	lint               conc_n_threads;
+
 	if (UNIV_LIKELY(!srv_thread_concurrency)) {
 
 		return;
 	}
+#ifdef UNIV_SYNC_ATOMIC
+        if (srv_thread_concurrency_timer_based) {
+                inc_srv_conc_n_threads(&conc_n_threads);
+	        trx->declared_to_be_inside_innodb = TRUE;
+	        trx->n_tickets_to_enter_innodb = 1;
+                return;
+        }
+#endif
 
 	ut_ad(srv_conc_n_threads >= 0);
 
@@ -1162,6 +1260,14 @@ srv_conc_force_exit_innodb(
 		return;
 	}
 
+#ifdef UNIV_SYNC_ATOMIC
+        if (srv_thread_concurrency_timer_based)
+        {
+                srv_conc_exit_innodb_timer_based(trx);
+                return;
+        }
+#endif
+
 	os_fast_mutex_lock(&srv_conc_mutex);
 
 	ut_ad(srv_conc_n_threads > 0);


Attachment: [text/bzr-bundle] bzr/k.long@sun.com-20090728215358-xrl3dyap1os8x52o.bundle
Thread
bzr commit into mysql-5.4 branch (k.long:2865) WL#4976Kelly Long28 Jul