Merge lp:~akopytov/percona-server/tp-high-prio-mode-5.5 into lp:percona-server/5.5

Proposed by Alexey Kopytov
Status: Merged
Merge reported by: Alexey Kopytov
Merged at revision: not available
Proposed branch: lp:~akopytov/percona-server/tp-high-prio-mode-5.5
Merge into: lp:percona-server/5.5
Prerequisite: lp:~akopytov/percona-server/tp-low-prio-queue-throttling-5.5
Diff against target: 225 lines (+118/-4)
8 files modified
Percona-Server/mysql-test/r/percona_server_variables_debug.result (+1/-0)
Percona-Server/mysql-test/r/percona_server_variables_release.result (+1/-0)
Percona-Server/mysql-test/suite/sys_vars/r/thread_pool_high_prio_mode_basic.result (+34/-0)
Percona-Server/mysql-test/suite/sys_vars/t/thread_pool_high_prio_mode_basic.test (+35/-0)
Percona-Server/sql/sql_class.h (+2/-1)
Percona-Server/sql/sys_vars.cc (+15/-0)
Percona-Server/sql/threadpool.h (+9/-0)
Percona-Server/sql/threadpool_unix.cc (+21/-3)
To merge this branch: bzr merge lp:~akopytov/percona-server/tp-high-prio-mode-5.5
Reviewer Review Type Date Requested Status
Alexey Kopytov (community) Approve
George Ormond Lorch III (community) g2 Approve
Review via email: mp+198746@code.launchpad.net

Description of the change

    Implementation of
    https://blueprints.launchpad.net/percona-server/+spec/tp-high-prio-mode-5.5

    Introduced a new Thread Pool option, thread_pool_high_prio_mode, which
    accepts the following values:

    - “transactions” (the default). In this mode only statements from
      already started transactions may go into the high priority queue
      depending on the number of high priority tickets currently available
      in a connection (see thread_pool_high_prio_tickets);

    - “statements”. In this mode all individual statements go into the high
      priority queue, regardless of connection’s transactional state and the
      number of available high priority tickets. This value can be used to
      prioritize AUTOCOMMIT transactions or other kinds of statements such
      as administrative ones for specific connections. Note that setting
      this value globally essentially disables high priority scheduling,
      since in this case all statements from all connections will use a
      single queue
      (the high priority one);

    - “none”. This mode disables high priority queue for a connection. Some
      connections (e.g. monitoring) may be insensitive to execution latency
      and/or never allocate any server resources that would otherwise impact
      performance in other connections and thus, do not really require high
      priority scheduling. Note that setting thread_pool_high_prio_mode to
      “none” globally has essentially the same effect as setting it to
      “statements” globally: all connections will always use a single queue
      (the low priority one in this case).

http://jenkins.percona.com/view/PS%205.5/job/percona-server-5.5-param/908/

To post a comment you must log in.
Revision history for this message
George Ormond Lorch III (gl-az) :
review: Approve (g2)
Revision history for this message
Alexey Kopytov (akopytov) wrote :

Spotted an inconsistency in naming (threadpool_high_prio_tickets vs. thread_pool_high_prio_mode). Will fix in a separate revision and push.

review: Needs Fixing
Revision history for this message
Alexey Kopytov (akopytov) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'Percona-Server/mysql-test/r/percona_server_variables_debug.result'
2--- Percona-Server/mysql-test/r/percona_server_variables_debug.result 2013-09-24 12:47:59 +0000
3+++ Percona-Server/mysql-test/r/percona_server_variables_debug.result 2013-12-12 13:56:05 +0000
4@@ -385,6 +385,7 @@
5 THREAD_CACHE_SIZE
6 THREAD_CONCURRENCY
7 THREAD_HANDLING
8+THREAD_POOL_HIGH_PRIO_MODE
9 THREAD_POOL_HIGH_PRIO_TICKETS
10 THREAD_POOL_IDLE_TIMEOUT
11 THREAD_POOL_MAX_THREADS
12
13=== modified file 'Percona-Server/mysql-test/r/percona_server_variables_release.result'
14--- Percona-Server/mysql-test/r/percona_server_variables_release.result 2013-08-28 21:14:46 +0000
15+++ Percona-Server/mysql-test/r/percona_server_variables_release.result 2013-12-12 13:56:05 +0000
16@@ -373,6 +373,7 @@
17 THREAD_CACHE_SIZE
18 THREAD_CONCURRENCY
19 THREAD_HANDLING
20+THREAD_POOL_HIGH_PRIO_MODE
21 THREAD_POOL_HIGH_PRIO_TICKETS
22 THREAD_POOL_IDLE_TIMEOUT
23 THREAD_POOL_MAX_THREADS
24
25=== added file 'Percona-Server/mysql-test/suite/sys_vars/r/thread_pool_high_prio_mode_basic.result'
26--- Percona-Server/mysql-test/suite/sys_vars/r/thread_pool_high_prio_mode_basic.result 1970-01-01 00:00:00 +0000
27+++ Percona-Server/mysql-test/suite/sys_vars/r/thread_pool_high_prio_mode_basic.result 2013-12-12 13:56:05 +0000
28@@ -0,0 +1,34 @@
29+SET @start_global_value = @@GLOBAL.thread_pool_high_prio_mode;
30+SET @@GLOBAL.thread_pool_high_prio_mode=DEFAULT;
31+SELECT @@GLOBAL.thread_pool_high_prio_mode;
32+@@GLOBAL.thread_pool_high_prio_mode
33+transactions
34+SET @@SESSION.thread_pool_high_prio_mode=DEFAULT;
35+SELECT @@SESSION.thread_pool_high_prio_mode;
36+@@SESSION.thread_pool_high_prio_mode
37+transactions
38+SHOW GLOBAL VARIABLES LIKE 'thread_pool_high_prio_mode';
39+Variable_name Value
40+thread_pool_high_prio_mode transactions
41+SHOW SESSION VARIABLES LIKE 'thread_pool_high_prio_mode';
42+Variable_name Value
43+thread_pool_high_prio_mode transactions
44+SET @@thread_pool_high_prio_mode='transactions';
45+SELECT @@thread_pool_high_prio_mode;
46+@@thread_pool_high_prio_mode
47+transactions
48+SET @@thread_pool_high_prio_mode='statements';
49+SELECT @@thread_pool_high_prio_mode;
50+@@thread_pool_high_prio_mode
51+statements
52+SET @@thread_pool_high_prio_mode='none';
53+SELECT @@thread_pool_high_prio_mode;
54+@@thread_pool_high_prio_mode
55+none
56+SET @@thread_pool_high_prio_mode='foo';
57+ERROR 42000: Variable 'thread_pool_high_prio_mode' can't be set to the value of 'foo'
58+SET @@thread_pool_high_prio_mode=1.1;
59+ERROR 42000: Incorrect argument type to variable 'thread_pool_high_prio_mode'
60+SET @@thread_pool_high_prio_mode=1e1;
61+ERROR 42000: Incorrect argument type to variable 'thread_pool_high_prio_mode'
62+SET @@GLOBAL.thread_pool_high_prio_mode = @start_global_value;
63
64=== added file 'Percona-Server/mysql-test/suite/sys_vars/t/thread_pool_high_prio_mode_basic.test'
65--- Percona-Server/mysql-test/suite/sys_vars/t/thread_pool_high_prio_mode_basic.test 1970-01-01 00:00:00 +0000
66+++ Percona-Server/mysql-test/suite/sys_vars/t/thread_pool_high_prio_mode_basic.test 2013-12-12 13:56:05 +0000
67@@ -0,0 +1,35 @@
68+--source include/not_windows.inc
69+--source include/not_embedded.inc
70+
71+SET @start_global_value = @@GLOBAL.thread_pool_high_prio_mode;
72+
73+# Test the default value
74+SET @@GLOBAL.thread_pool_high_prio_mode=DEFAULT;
75+SELECT @@GLOBAL.thread_pool_high_prio_mode;
76+
77+# Test that the session value is accepted
78+SET @@SESSION.thread_pool_high_prio_mode=DEFAULT;
79+SELECT @@SESSION.thread_pool_high_prio_mode;
80+
81+SHOW GLOBAL VARIABLES LIKE 'thread_pool_high_prio_mode';
82+SHOW SESSION VARIABLES LIKE 'thread_pool_high_prio_mode';
83+
84+SET @@thread_pool_high_prio_mode='transactions';
85+SELECT @@thread_pool_high_prio_mode;
86+
87+SET @@thread_pool_high_prio_mode='statements';
88+SELECT @@thread_pool_high_prio_mode;
89+
90+SET @@thread_pool_high_prio_mode='none';
91+SELECT @@thread_pool_high_prio_mode;
92+
93+--error ER_WRONG_VALUE_FOR_VAR
94+SET @@thread_pool_high_prio_mode='foo';
95+
96+--error ER_WRONG_TYPE_FOR_VAR
97+SET @@thread_pool_high_prio_mode=1.1;
98+
99+--error ER_WRONG_TYPE_FOR_VAR
100+SET @@thread_pool_high_prio_mode=1e1;
101+
102+SET @@GLOBAL.thread_pool_high_prio_mode = @start_global_value;
103
104=== modified file 'Percona-Server/sql/sql_class.h'
105--- Percona-Server/sql/sql_class.h 2013-12-03 05:52:35 +0000
106+++ Percona-Server/sql/sql_class.h 2013-12-12 13:56:05 +0000
107@@ -562,7 +562,8 @@
108 my_bool expand_fast_index_creation;
109 my_bool pseudo_slave_mode;
110
111- uint threadpool_high_prio_tickets;
112+ uint threadpool_high_prio_tickets;
113+ ulong thread_pool_high_prio_mode;
114 } SV;
115
116
117
118=== modified file 'Percona-Server/sql/sys_vars.cc'
119--- Percona-Server/sql/sys_vars.cc 2013-12-03 05:52:35 +0000
120+++ Percona-Server/sql/sys_vars.cc 2013-12-12 13:56:05 +0000
121@@ -2388,6 +2388,21 @@
122 SESSION_VAR(threadpool_high_prio_tickets), CMD_LINE(REQUIRED_ARG),
123 VALID_RANGE(0, UINT_MAX), DEFAULT(UINT_MAX), BLOCK_SIZE(1)
124 );
125+
126+static Sys_var_enum Sys_threadpool_high_prio_mode(
127+ "thread_pool_high_prio_mode",
128+ "High priority queue mode: one of 'transactions', 'statements' or 'none'. "
129+ "In the 'transactions' mode the thread pool uses both high- and low-priority "
130+ "queues depending on whether an event is generated by an already started "
131+ "transaction and whether it has any high priority tickets (see "
132+ "thread_pool_high_prio_tickets). In the 'statements' mode all events (i.e. "
133+ "individual statements) always go to the high priority queue, regardless of "
134+ "the current transaction state and high priority tickets. "
135+ "'none' is the opposite of 'statements', i.e. disables the high priority queue "
136+ "completely.",
137+ SESSION_VAR(thread_pool_high_prio_mode), CMD_LINE(REQUIRED_ARG),
138+ thread_pool_high_prio_mode_names, DEFAULT(TP_HIGH_PRIO_MODE_TRANSACTIONS));
139+
140 #endif /* !WIN32 */
141 static Sys_var_uint Sys_threadpool_max_threads(
142 "thread_pool_max_threads",
143
144=== modified file 'Percona-Server/sql/threadpool.h'
145--- Percona-Server/sql/threadpool.h 2013-12-02 12:17:20 +0000
146+++ Percona-Server/sql/threadpool.h 2013-12-12 13:56:05 +0000
147@@ -15,6 +15,12 @@
148
149 #define MAX_THREAD_GROUPS 128
150
151+enum tp_high_prio_mode_t {
152+ TP_HIGH_PRIO_MODE_TRANSACTIONS,
153+ TP_HIGH_PRIO_MODE_STATEMENTS,
154+ TP_HIGH_PRIO_MODE_NONE
155+};
156+
157 /* Threadpool parameters */
158 extern uint threadpool_min_threads; /* Minimum threads in pool */
159 extern uint threadpool_idle_timeout; /* Shutdown idle worker threads after this timeout */
160@@ -23,6 +29,9 @@
161 extern uint threadpool_max_threads; /* Maximum threads in pool */
162 extern uint threadpool_oversubscribe; /* Maximum active threads in group */
163
164+/* Possible values for thread_pool_high_prio_mode */
165+extern const char *thread_pool_high_prio_mode_names[];
166+
167 /* Common thread pool routines, suitable for different implementations */
168 extern void threadpool_remove_connection(THD *thd);
169 extern int threadpool_process_request(THD *thd);
170
171=== modified file 'Percona-Server/sql/threadpool_unix.cc'
172--- Percona-Server/sql/threadpool_unix.cc 2013-12-12 13:56:05 +0000
173+++ Percona-Server/sql/threadpool_unix.cc 2013-12-12 13:56:05 +0000
174@@ -47,6 +47,10 @@
175 for stall detection to kick in */
176 #define THREADPOOL_CREATE_THREADS_ON_WAIT
177
178+/* Possible values for thread_pool_high_prio_mode */
179+const char *thread_pool_high_prio_mode_names[]= {"transactions", "statements",
180+ "none", NullS};
181+
182 /** Indicates that threadpool was initialized*/
183 static bool threadpool_started= false;
184
185@@ -427,6 +431,21 @@
186 > 1 + (int) threadpool_oversubscribe);
187 }
188
189+/*
190+ Checks if a given connection is eligible to enter the high priority queue
191+ based on its current thread_pool_high_prio_mode value, available high
192+ priority tickets and transactional state.
193+*/
194+
195+inline bool connection_is_high_prio(connection_t *c)
196+{
197+ const ulong mode= c->thd->variables.thread_pool_high_prio_mode;
198+
199+ return (mode == TP_HIGH_PRIO_MODE_STATEMENTS) ||
200+ (mode == TP_HIGH_PRIO_MODE_TRANSACTIONS &&
201+ c->tickets > 0 && thd_is_transaction_active(c->thd));
202+}
203+
204 } // namespace
205
206 /* Dequeue element from a workqueue */
207@@ -758,7 +777,7 @@
208 for(int i=(listener_picks_event)?1:0; i < cnt ; i++)
209 {
210 connection_t *c= (connection_t *)native_event_get_userdata(&ev[i]);
211- if (c->tickets > 0 && thd_is_transaction_active(c->thd))
212+ if (connection_is_high_prio(c))
213 {
214 c->tickets--;
215 thread_group->high_prio_queue.push_back(c);
216@@ -1150,8 +1169,7 @@
217 must either have a high priority ticket, or there must be not too many
218 busy threads (as if it was coming from a low priority queue).
219 */
220- if (connection->tickets > 0 &&
221- thd_is_transaction_active(connection->thd))
222+ if (connection_is_high_prio(connection))
223 connection->tickets--;
224 else if (too_many_busy_threads(thread_group))
225 {

Subscribers

People subscribed via source and target branches