~percona-core/percona-server/5.1

« back to all changes in this revision

Viewing changes to patches/innodb_thread_concurrency_timer_based.patch

  • Committer: Stewart Smith
  • Date: 2011-11-24 08:14:40 UTC
  • Revision ID: stewart@flamingspork.com-20111124081440-jffloqgkbgytzgl5
remove now unneeded patches as we're part of a happy bzr tree

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# name       : innodb_thread_concurrency_timer_based.patch
2
 
# introduced : 11 or before
3
 
# maintainer : Yasufumi
4
 
#
5
 
#!!! notice !!!
6
 
# Any small change to this file in the main branch
7
 
# should be done or reviewed by the maintainer!
8
 
--- a/storage/innodb_plugin/handler/ha_innodb.cc
9
 
+++ b/storage/innodb_plugin/handler/ha_innodb.cc
10
 
@@ -151,6 +151,7 @@
11
 
 static ulong innobase_read_io_threads;
12
 
 static ulong innobase_write_io_threads;
13
 
 
14
 
+static my_bool innobase_thread_concurrency_timer_based;
15
 
 static long long innobase_buffer_pool_size, innobase_log_file_size;
16
 
 
17
 
 /** Percentage of the buffer pool to reserve for 'old' blocks.
18
 
@@ -2343,6 +2344,9 @@
19
 
        srv_n_log_files = (ulint) innobase_log_files_in_group;
20
 
        srv_log_file_size = (ulint) innobase_log_file_size;
21
 
 
22
 
+       srv_thread_concurrency_timer_based =
23
 
+               (ibool) innobase_thread_concurrency_timer_based;
24
 
+
25
 
 #ifdef UNIV_LOG_ARCHIVE
26
 
        srv_log_archive_on = (ulint) innobase_log_archive;
27
 
 #endif /* UNIV_LOG_ARCHIVE */
28
 
@@ -11202,6 +11206,12 @@
29
 
   "Maximum delay between polling for a spin lock (6 by default)",
30
 
   NULL, NULL, 6L, 0L, ~0L, 0);
31
 
 
32
 
+static MYSQL_SYSVAR_BOOL(thread_concurrency_timer_based,
33
 
+  innobase_thread_concurrency_timer_based,
34
 
+  PLUGIN_VAR_NOCMDARG | PLUGIN_VAR_READONLY,
35
 
+  "Use InnoDB timer based concurrency throttling. ",
36
 
+  NULL, NULL, FALSE);
37
 
+
38
 
 static MYSQL_SYSVAR_ULONG(thread_concurrency, srv_thread_concurrency,
39
 
   PLUGIN_VAR_RQCMDARG,
40
 
   "Helps in performance tuning in heavily concurrent environments. Sets the maximum number of threads allowed inside InnoDB. Value 0 will disable the thread throttling.",
41
 
@@ -11423,6 +11433,7 @@
42
 
   MYSQL_SYSVAR(spin_wait_delay),
43
 
   MYSQL_SYSVAR(table_locks),
44
 
   MYSQL_SYSVAR(thread_concurrency),
45
 
+  MYSQL_SYSVAR(thread_concurrency_timer_based),
46
 
   MYSQL_SYSVAR(thread_sleep_delay),
47
 
   MYSQL_SYSVAR(autoinc_lock_mode),
48
 
   MYSQL_SYSVAR(show_verbose_locks),
49
 
--- a/storage/innodb_plugin/handler/innodb_patch_info.h
50
 
+++ b/storage/innodb_plugin/handler/innodb_patch_info.h
51
 
@@ -31,5 +31,6 @@
52
 
 {"innodb_expand_undo_slots","expandable maximum number of undo slots","from 1024 (default) to about 4000","http://www.percona.com/docs/wiki/percona-xtradb"},
53
 
 {"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"},
54
 
 {"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"},
55
 
+{"innodb_thread_concurrency_timer_based","use InnoDB timer based concurrency throttling (backport from MySQL 5.4.0)","",""},
56
 
 {NULL, NULL, NULL, NULL}
57
 
 };
58
 
--- a/storage/innodb_plugin/include/srv0srv.h
59
 
+++ b/storage/innodb_plugin/include/srv0srv.h
60
 
@@ -147,6 +147,8 @@
61
 
 extern ulint   srv_mem_pool_size;
62
 
 extern ulint   srv_lock_table_size;
63
 
 
64
 
+extern ibool   srv_thread_concurrency_timer_based;
65
 
+
66
 
 extern ulint   srv_n_file_io_threads;
67
 
 extern my_bool srv_random_read_ahead;
68
 
 extern ulong   srv_read_ahead_threshold;
69
 
--- a/storage/innodb_plugin/srv/srv0srv.c
70
 
+++ b/storage/innodb_plugin/srv/srv0srv.c
71
 
@@ -320,6 +320,7 @@
72
 
 computer. Bigger computers need bigger values. Value 0 will disable the
73
 
 concurrency check. */
74
 
 
75
 
+UNIV_INTERN ibool      srv_thread_concurrency_timer_based = FALSE;
76
 
 UNIV_INTERN ulong      srv_thread_concurrency  = 0;
77
 
 
78
 
 /* this mutex protects srv_conc data structures */
79
 
@@ -1071,6 +1072,75 @@
80
 
 /*********************************************************************//**
81
 
 Puts an OS thread to wait if there are too many concurrent threads
82
 
 (>= srv_thread_concurrency) inside InnoDB. The threads wait in a FIFO queue. */
83
 
+
84
 
+#ifdef HAVE_ATOMIC_BUILTINS
85
 
+static void
86
 
+enter_innodb_with_tickets(trx_t* trx)
87
 
+{
88
 
+       trx->declared_to_be_inside_innodb = TRUE;
89
 
+       trx->n_tickets_to_enter_innodb = SRV_FREE_TICKETS_TO_ENTER;
90
 
+       return;
91
 
+}
92
 
+
93
 
+static void
94
 
+srv_conc_enter_innodb_timer_based(trx_t* trx)
95
 
+{
96
 
+       lint    conc_n_threads;
97
 
+       ibool   has_yielded = FALSE;
98
 
+       ulint   has_slept = 0;
99
 
+
100
 
+       if (trx->declared_to_be_inside_innodb) {
101
 
+               ut_print_timestamp(stderr);
102
 
+               fputs(
103
 
+"  InnoDB: Error: trying to declare trx to enter InnoDB, but\n"
104
 
+"InnoDB: it already is declared.\n", stderr);
105
 
+               trx_print(stderr, trx, 0);
106
 
+               putc('\n', stderr);
107
 
+       }
108
 
+retry:
109
 
+       if (srv_conc_n_threads < (lint) srv_thread_concurrency) {
110
 
+               conc_n_threads = os_atomic_increment_lint(&srv_conc_n_threads, 1);
111
 
+               if (conc_n_threads <= (lint) srv_thread_concurrency) {
112
 
+                       enter_innodb_with_tickets(trx);
113
 
+                       return;
114
 
+               }
115
 
+               (void) os_atomic_increment_lint(&srv_conc_n_threads, -1);
116
 
+       }
117
 
+       if (!has_yielded)
118
 
+       {
119
 
+               has_yielded = TRUE;
120
 
+               os_thread_yield();
121
 
+               goto retry;
122
 
+       }
123
 
+       if (trx->has_search_latch
124
 
+           || NULL != UT_LIST_GET_FIRST(trx->trx_locks)) {
125
 
+
126
 
+               conc_n_threads = os_atomic_increment_lint(&srv_conc_n_threads, 1);
127
 
+               enter_innodb_with_tickets(trx);
128
 
+               return;
129
 
+       }
130
 
+       if (has_slept < 2)
131
 
+       {
132
 
+               trx->op_info = "sleeping before entering InnoDB";
133
 
+               os_thread_sleep(10000);
134
 
+               trx->op_info = "";
135
 
+               has_slept++;
136
 
+       }
137
 
+       conc_n_threads = os_atomic_increment_lint(&srv_conc_n_threads, 1);
138
 
+       enter_innodb_with_tickets(trx);
139
 
+       return;
140
 
+}
141
 
+
142
 
+static void
143
 
+srv_conc_exit_innodb_timer_based(trx_t* trx)
144
 
+{
145
 
+       (void) os_atomic_increment_lint(&srv_conc_n_threads, -1);
146
 
+       trx->declared_to_be_inside_innodb = FALSE;
147
 
+       trx->n_tickets_to_enter_innodb = 0;
148
 
+       return;
149
 
+}
150
 
+#endif
151
 
+
152
 
 UNIV_INTERN
153
 
 void
154
 
 srv_conc_enter_innodb(
155
 
@@ -1101,6 +1171,13 @@
156
 
                return;
157
 
        }
158
 
 
159
 
+#ifdef HAVE_ATOMIC_BUILTINS
160
 
+       if (srv_thread_concurrency_timer_based) {
161
 
+               srv_conc_enter_innodb_timer_based(trx);
162
 
+               return;
163
 
+       }
164
 
+#endif
165
 
+
166
 
        os_fast_mutex_lock(&srv_conc_mutex);
167
 
 retry:
168
 
        if (trx->declared_to_be_inside_innodb) {
169
 
@@ -1244,6 +1321,14 @@
170
 
        }
171
 
 
172
 
        ut_ad(srv_conc_n_threads >= 0);
173
 
+#ifdef HAVE_ATOMIC_BUILTINS
174
 
+       if (srv_thread_concurrency_timer_based) {
175
 
+               (void) os_atomic_increment_lint(&srv_conc_n_threads, 1);
176
 
+               trx->declared_to_be_inside_innodb = TRUE;
177
 
+               trx->n_tickets_to_enter_innodb = 1;
178
 
+               return;
179
 
+       }
180
 
+#endif
181
 
 
182
 
        os_fast_mutex_lock(&srv_conc_mutex);
183
 
 
184
 
@@ -1277,6 +1362,13 @@
185
 
                return;
186
 
        }
187
 
 
188
 
+#ifdef HAVE_ATOMIC_BUILTINS
189
 
+       if (srv_thread_concurrency_timer_based) {
190
 
+               srv_conc_exit_innodb_timer_based(trx);
191
 
+               return;
192
 
+       }
193
 
+#endif
194
 
+
195
 
        os_fast_mutex_lock(&srv_conc_mutex);
196
 
 
197
 
        ut_ad(srv_conc_n_threads > 0);