1
diff -ruN a/storage/innodb_plugin/handler/ha_innodb.cc b/storage/innodb_plugin/handler/ha_innodb.cc
2
--- a/storage/innodb_plugin/handler/ha_innodb.cc 2010-04-29 16:43:16.000000000 +0900
3
+++ b/storage/innodb_plugin/handler/ha_innodb.cc 2010-04-29 16:43:53.000000000 +0900
5
static ulong innobase_read_io_threads;
6
static ulong innobase_write_io_threads;
8
+static my_bool innobase_thread_concurrency_timer_based;
9
static long long innobase_buffer_pool_size, innobase_log_file_size;
11
/** Percentage of the buffer pool to reserve for 'old' blocks.
13
srv_n_log_files = (ulint) innobase_log_files_in_group;
14
srv_log_file_size = (ulint) innobase_log_file_size;
16
+ srv_thread_concurrency_timer_based =
17
+ (ibool) innobase_thread_concurrency_timer_based;
19
#ifdef UNIV_LOG_ARCHIVE
20
srv_log_archive_on = (ulint) innobase_log_archive;
21
#endif /* UNIV_LOG_ARCHIVE */
22
@@ -10910,6 +10914,12 @@
23
"Maximum delay between polling for a spin lock (6 by default)",
24
NULL, NULL, 6L, 0L, ~0L, 0);
26
+static MYSQL_SYSVAR_BOOL(thread_concurrency_timer_based,
27
+ innobase_thread_concurrency_timer_based,
28
+ PLUGIN_VAR_NOCMDARG | PLUGIN_VAR_READONLY,
29
+ "Use InnoDB timer based concurrency throttling. ",
32
static MYSQL_SYSVAR_ULONG(thread_concurrency, srv_thread_concurrency,
34
"Helps in performance tuning in heavily concurrent environments. Sets the maximum number of threads allowed inside InnoDB. Value 0 will disable the thread throttling.",
35
@@ -11109,6 +11119,7 @@
36
MYSQL_SYSVAR(spin_wait_delay),
37
MYSQL_SYSVAR(table_locks),
38
MYSQL_SYSVAR(thread_concurrency),
39
+ MYSQL_SYSVAR(thread_concurrency_timer_based),
40
MYSQL_SYSVAR(thread_sleep_delay),
41
MYSQL_SYSVAR(autoinc_lock_mode),
42
MYSQL_SYSVAR(show_verbose_locks),
43
diff -ruN a/storage/innodb_plugin/handler/innodb_patch_info.h b/storage/innodb_plugin/handler/innodb_patch_info.h
44
--- a/storage/innodb_plugin/handler/innodb_patch_info.h 2010-04-29 16:43:16.000000000 +0900
45
+++ b/storage/innodb_plugin/handler/innodb_patch_info.h 2010-04-29 16:43:53.000000000 +0900
47
{"innodb_expand_undo_slots","expandable maximum number of undo slots","from 1024 (default) to about 4000","http://www.percona.com/docs/wiki/percona-xtradb"},
48
{"innodb_extra_rseg","allow to create extra rollback segments","When create new db, the new parameter allows to create more rollback segments","http://www.percona.com/docs/wiki/percona-xtradb"},
49
{"innodb_overwrite_relay_log_info","overwrite relay-log.info when slave recovery","Building as plugin, it is not used.","http://www.percona.com/docs/wiki/percona-xtradb:innodb_overwrite_relay_log_info"},
50
+{"innodb_thread_concurrency_timer_based","use InnoDB timer based concurrency throttling (backport from MySQL 5.4.0)","",""},
51
{NULL, NULL, NULL, NULL}
53
diff -ruN a/storage/innodb_plugin/include/srv0srv.h b/storage/innodb_plugin/include/srv0srv.h
54
--- a/storage/innodb_plugin/include/srv0srv.h 2010-04-29 16:39:34.000000000 +0900
55
+++ b/storage/innodb_plugin/include/srv0srv.h 2010-04-29 16:43:53.000000000 +0900
57
extern ulint srv_mem_pool_size;
58
extern ulint srv_lock_table_size;
60
+extern ibool srv_thread_concurrency_timer_based;
62
extern ulint srv_n_file_io_threads;
63
extern ulong srv_read_ahead_threshold;
64
extern ulint srv_n_read_io_threads;
65
diff -ruN a/storage/innodb_plugin/srv/srv0srv.c b/storage/innodb_plugin/srv/srv0srv.c
66
--- a/storage/innodb_plugin/srv/srv0srv.c 2010-04-29 16:39:34.000000000 +0900
67
+++ b/storage/innodb_plugin/srv/srv0srv.c 2010-04-29 16:43:53.000000000 +0900
69
computer. Bigger computers need bigger values. Value 0 will disable the
72
+UNIV_INTERN ibool srv_thread_concurrency_timer_based = FALSE;
73
UNIV_INTERN ulong srv_thread_concurrency = 0;
75
/* this mutex protects srv_conc data structures */
76
@@ -1064,6 +1065,75 @@
77
/*********************************************************************//**
78
Puts an OS thread to wait if there are too many concurrent threads
79
(>= srv_thread_concurrency) inside InnoDB. The threads wait in a FIFO queue. */
81
+#ifdef HAVE_ATOMIC_BUILTINS
83
+enter_innodb_with_tickets(trx_t* trx)
85
+ trx->declared_to_be_inside_innodb = TRUE;
86
+ trx->n_tickets_to_enter_innodb = SRV_FREE_TICKETS_TO_ENTER;
91
+srv_conc_enter_innodb_timer_based(trx_t* trx)
93
+ lint conc_n_threads;
94
+ ibool has_yielded = FALSE;
95
+ ulint has_slept = 0;
97
+ if (trx->declared_to_be_inside_innodb) {
98
+ ut_print_timestamp(stderr);
100
+" InnoDB: Error: trying to declare trx to enter InnoDB, but\n"
101
+"InnoDB: it already is declared.\n", stderr);
102
+ trx_print(stderr, trx, 0);
103
+ putc('\n', stderr);
106
+ if (srv_conc_n_threads < (lint) srv_thread_concurrency) {
107
+ conc_n_threads = os_atomic_increment_lint(&srv_conc_n_threads, 1);
108
+ if (conc_n_threads <= (lint) srv_thread_concurrency) {
109
+ enter_innodb_with_tickets(trx);
112
+ os_atomic_increment_lint(&srv_conc_n_threads, -1);
116
+ has_yielded = TRUE;
120
+ if (trx->has_search_latch
121
+ || NULL != UT_LIST_GET_FIRST(trx->trx_locks)) {
123
+ conc_n_threads = os_atomic_increment_lint(&srv_conc_n_threads, 1);
124
+ enter_innodb_with_tickets(trx);
129
+ trx->op_info = "sleeping before entering InnoDB";
130
+ os_thread_sleep(10000);
134
+ conc_n_threads = os_atomic_increment_lint(&srv_conc_n_threads, 1);
135
+ enter_innodb_with_tickets(trx);
140
+srv_conc_exit_innodb_timer_based(trx_t* trx)
142
+ os_atomic_increment_lint(&srv_conc_n_threads, -1);
143
+ trx->declared_to_be_inside_innodb = FALSE;
144
+ trx->n_tickets_to_enter_innodb = 0;
151
srv_conc_enter_innodb(
152
@@ -1094,6 +1164,13 @@
156
+#ifdef HAVE_ATOMIC_BUILTINS
157
+ if (srv_thread_concurrency_timer_based) {
158
+ srv_conc_enter_innodb_timer_based(trx);
163
os_fast_mutex_lock(&srv_conc_mutex);
165
if (trx->declared_to_be_inside_innodb) {
166
@@ -1237,6 +1314,14 @@
169
ut_ad(srv_conc_n_threads >= 0);
170
+#ifdef HAVE_ATOMIC_BUILTINS
171
+ if (srv_thread_concurrency_timer_based) {
172
+ os_atomic_increment_lint(&srv_conc_n_threads, 1);
173
+ trx->declared_to_be_inside_innodb = TRUE;
174
+ trx->n_tickets_to_enter_innodb = 1;
179
os_fast_mutex_lock(&srv_conc_mutex);
181
@@ -1270,6 +1355,13 @@
185
+#ifdef HAVE_ATOMIC_BUILTINS
186
+ if (srv_thread_concurrency_timer_based) {
187
+ srv_conc_exit_innodb_timer_based(trx);
192
os_fast_mutex_lock(&srv_conc_mutex);
194
ut_ad(srv_conc_n_threads > 0);