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

Proposed by Alexey Kopytov
Status: Merged
Approved by: Alexey Kopytov
Approved revision: no longer in the source branch.
Merged at revision: 514
Proposed branch: lp:~akopytov/percona-server/tp-high-prio-mode-5.6
Merge into: lp:percona-server/5.6
Prerequisite: lp:~akopytov/percona-server/tp-low-prio-queue-throttling-5.6
Diff against target: 201 lines (+116/-4)
6 files modified
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.6
Reviewer Review Type Date Requested Status
Alexey Kopytov (community) Approve
George Ormond Lorch III (community) g2 Approve
Review via email: mp+198748@code.launchpad.net

Description of the change

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 :

Same comments as in the 5.5 MP.

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

Subscribers

People subscribed via source and target branches