~percona-dev/percona-server/release-5.1.49-11

« back to all changes in this revision

Viewing changes to innodb_thread_concurrency_timer_based.patch

  • Committer: kinoyasu
  • Date: 2010-04-30 10:17:55 UTC
  • Revision ID: kinoyasu@gauntlet3-20100430101755-h27x25t4uax76lv4
merge, reorder and port patches based on mysql 5.1.46 innodb 1.0.7

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
4
@@ -152,6 +152,7 @@
 
5
 static ulong innobase_read_io_threads;
 
6
 static ulong innobase_write_io_threads;
 
7
 
 
8
+static my_bool innobase_thread_concurrency_timer_based;
 
9
 static long long innobase_buffer_pool_size, innobase_log_file_size;
 
10
 
 
11
 /** Percentage of the buffer pool to reserve for 'old' blocks.
 
12
@@ -2257,6 +2258,9 @@
 
13
        srv_n_log_files = (ulint) innobase_log_files_in_group;
 
14
        srv_log_file_size = (ulint) innobase_log_file_size;
 
15
 
 
16
+       srv_thread_concurrency_timer_based =
 
17
+               (ibool) innobase_thread_concurrency_timer_based;
 
18
+
 
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);
 
25
 
 
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. ",
 
30
+  NULL, NULL, FALSE);
 
31
+
 
32
 static MYSQL_SYSVAR_ULONG(thread_concurrency, srv_thread_concurrency,
 
33
   PLUGIN_VAR_RQCMDARG,
 
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
 
46
@@ -31,5 +31,6 @@
 
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}
 
52
 };
 
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
 
56
@@ -147,6 +147,8 @@
 
57
 extern ulint   srv_mem_pool_size;
 
58
 extern ulint   srv_lock_table_size;
 
59
 
 
60
+extern ibool   srv_thread_concurrency_timer_based;
 
61
+
 
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
 
68
@@ -313,6 +313,7 @@
 
69
 computer. Bigger computers need bigger values. Value 0 will disable the
 
70
 concurrency check. */
 
71
 
 
72
+UNIV_INTERN ibool      srv_thread_concurrency_timer_based = FALSE;
 
73
 UNIV_INTERN ulong      srv_thread_concurrency  = 0;
 
74
 
 
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. */
 
80
+
 
81
+#ifdef HAVE_ATOMIC_BUILTINS
 
82
+static void
 
83
+enter_innodb_with_tickets(trx_t* trx)
 
84
+{
 
85
+       trx->declared_to_be_inside_innodb = TRUE;
 
86
+       trx->n_tickets_to_enter_innodb = SRV_FREE_TICKETS_TO_ENTER;
 
87
+       return;
 
88
+}
 
89
+
 
90
+static void
 
91
+srv_conc_enter_innodb_timer_based(trx_t* trx)
 
92
+{
 
93
+       lint    conc_n_threads;
 
94
+       ibool   has_yielded = FALSE;
 
95
+       ulint   has_slept = 0;
 
96
+
 
97
+       if (trx->declared_to_be_inside_innodb) {
 
98
+               ut_print_timestamp(stderr);
 
99
+               fputs(
 
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);
 
104
+       }
 
105
+retry:
 
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);
 
110
+                       return;
 
111
+               }
 
112
+               os_atomic_increment_lint(&srv_conc_n_threads, -1);
 
113
+       }
 
114
+       if (!has_yielded)
 
115
+       {
 
116
+               has_yielded = TRUE;
 
117
+               os_thread_yield();
 
118
+               goto retry;
 
119
+       }
 
120
+       if (trx->has_search_latch
 
121
+           || NULL != UT_LIST_GET_FIRST(trx->trx_locks)) {
 
122
+
 
123
+               conc_n_threads = os_atomic_increment_lint(&srv_conc_n_threads, 1);
 
124
+               enter_innodb_with_tickets(trx);
 
125
+               return;
 
126
+       }
 
127
+       if (has_slept < 2)
 
128
+       {
 
129
+               trx->op_info = "sleeping before entering InnoDB";
 
130
+               os_thread_sleep(10000);
 
131
+               trx->op_info = "";
 
132
+               has_slept++;
 
133
+       }
 
134
+       conc_n_threads = os_atomic_increment_lint(&srv_conc_n_threads, 1);
 
135
+       enter_innodb_with_tickets(trx);
 
136
+       return;
 
137
+}
 
138
+
 
139
+static void
 
140
+srv_conc_exit_innodb_timer_based(trx_t* trx)
 
141
+{
 
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;
 
145
+       return;
 
146
+}
 
147
+#endif
 
148
+
 
149
 UNIV_INTERN
 
150
 void
 
151
 srv_conc_enter_innodb(
 
152
@@ -1094,6 +1164,13 @@
 
153
                return;
 
154
        }
 
155
 
 
156
+#ifdef HAVE_ATOMIC_BUILTINS
 
157
+       if (srv_thread_concurrency_timer_based) {
 
158
+               srv_conc_enter_innodb_timer_based(trx);
 
159
+               return;
 
160
+       }
 
161
+#endif
 
162
+
 
163
        os_fast_mutex_lock(&srv_conc_mutex);
 
164
 retry:
 
165
        if (trx->declared_to_be_inside_innodb) {
 
166
@@ -1237,6 +1314,14 @@
 
167
        }
 
168
 
 
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;
 
175
+               return;
 
176
+       }
 
177
+#endif
 
178
 
 
179
        os_fast_mutex_lock(&srv_conc_mutex);
 
180
 
 
181
@@ -1270,6 +1355,13 @@
 
182
                return;
 
183
        }
 
184
 
 
185
+#ifdef HAVE_ATOMIC_BUILTINS
 
186
+       if (srv_thread_concurrency_timer_based) {
 
187
+               srv_conc_exit_innodb_timer_based(trx);
 
188
+               return;
 
189
+       }
 
190
+#endif
 
191
+
 
192
        os_fast_mutex_lock(&srv_conc_mutex);
 
193
 
 
194
        ut_ad(srv_conc_n_threads > 0);