MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
pfs_autosize.cc
Go to the documentation of this file.
1 /* Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
2 
3  This program is free software; you can redistribute it and/or modify
4  it under the terms of the GNU General Public License as published by
5  the Free Software Foundation; version 2 of the License.
6 
7  This program is distributed in the hope that it will be useful,
8  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  GNU General Public License for more details.
11 
12  You should have received a copy of the GNU General Public License
13  along with this program; if not, write to the Free Software Foundation,
14  51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */
15 
21 #include "my_global.h"
22 #include "sql_const.h"
23 #include "pfs_server.h"
24 
25 #include <algorithm>
26 using std::min;
27 using std::max;
28 
29 static const ulong fixed_mutex_instances= 500;
30 static const ulong fixed_rwlock_instances= 200;
31 static const ulong fixed_cond_instances= 50;
32 static const ulong fixed_file_instances= 200;
33 static const ulong fixed_socket_instances= 10;
34 static const ulong fixed_thread_instances= 50;
35 
36 static const ulong mutex_per_connection= 3;
37 static const ulong rwlock_per_connection= 1;
38 static const ulong cond_per_connection= 2;
39 static const ulong file_per_connection= 0;
40 static const ulong socket_per_connection= 1;
41 static const ulong thread_per_connection= 1;
42 
43 static const ulong mutex_per_handle= 0;
44 static const ulong rwlock_per_handle= 0;
45 static const ulong cond_per_handle= 0;
46 static const ulong file_per_handle= 0;
47 static const ulong socket_per_handle= 0;
48 static const ulong thread_per_handle= 0;
49 
50 static const ulong mutex_per_share= 5;
51 static const ulong rwlock_per_share= 3;
52 static const ulong cond_per_share= 1;
53 static const ulong file_per_share= 3;
54 static const ulong socket_per_share= 0;
55 static const ulong thread_per_share= 0;
56 
58 {
65 
82 
91 
119 };
120 
121 PFS_sizing_data small_data=
122 {
123  /* Account / user / host */
124  10, 5, 20,
125  /* History sizes */
126  5, 100, 5, 100, 5, 100,
127  /* Digests */
128  1000,
129  /* Session connect attrs. */
130  512,
131  /* Min tables */
132  200,
133  /* Load factors */
134  0.90, 0.90, 0.90
135 };
136 
137 PFS_sizing_data medium_data=
138 {
139  /* Account / user / host */
140  100, 100, 100,
141  /* History sizes */
142  10, 1000, 10, 1000, 10, 1000,
143  /* Digests */
144  5000,
145  /* Session connect attrs. */
146  512,
147  /* Min tables */
148  500,
149  /* Load factors */
150  0.70, 0.80, 0.90
151 };
152 
153 PFS_sizing_data large_data=
154 {
155  /* Account / user / host */
156  100, 100, 100,
157  /* History sizes */
158  10, 10000, 10, 10000, 10, 10000,
159  /* Digests */
160  10000,
161  /* Session connect attrs. */
162  512,
163  /* Min tables */
164  10000,
165  /* Load factors */
166  0.50, 0.65, 0.80
167 };
168 
169 static inline ulong apply_load_factor(ulong raw_value, float factor)
170 {
171  float value = ((float) raw_value) / factor;
172  return (ulong) ceil(value);
173 }
174 
175 PFS_sizing_data *estimate_hints(PFS_global_param *param)
176 {
177  if ((param->m_hints.m_max_connections <= MAX_CONNECTIONS_DEFAULT) &&
178  (param->m_hints.m_table_definition_cache <= TABLE_DEF_CACHE_DEFAULT) &&
179  (param->m_hints.m_table_open_cache <= TABLE_OPEN_CACHE_DEFAULT))
180  {
181  /* The my.cnf used is either unchanged, or lower than factory defaults. */
182  return & small_data;
183  }
184 
185  if ((param->m_hints.m_max_connections <= MAX_CONNECTIONS_DEFAULT * 2) &&
186  (param->m_hints.m_table_definition_cache <= TABLE_DEF_CACHE_DEFAULT * 2) &&
187  (param->m_hints.m_table_open_cache <= TABLE_OPEN_CACHE_DEFAULT * 2))
188  {
189  /* Some defaults have been increased, to "moderate" values. */
190  return & medium_data;
191  }
192 
193  /* Looks like a server in production. */
194  return & large_data;
195 }
196 
197 static void apply_heuristic(PFS_global_param *p, PFS_sizing_data *h)
198 {
199  ulong count;
200  ulong con = p->m_hints.m_max_connections;
201  ulong handle = p->m_hints.m_table_open_cache;
202  ulong share = p->m_hints.m_table_definition_cache;
203  ulong file = p->m_hints.m_open_files_limit;
204 
205  if (p->m_table_sizing < 0)
206  {
207  count= handle;
208 
209  p->m_table_sizing= apply_load_factor(count, h->m_load_factor_volatile);
210  }
211 
212  if (p->m_table_share_sizing < 0)
213  {
214  count= share;
215 
216  count= max<ulong>(count, h->m_min_number_of_tables);
217  p->m_table_share_sizing= apply_load_factor(count, h->m_load_factor_static);
218  }
219 
220  if (p->m_account_sizing < 0)
221  {
223  }
224 
225  if (p->m_user_sizing < 0)
226  {
228  }
229 
230  if (p->m_host_sizing < 0)
231  {
233  }
234 
236  {
238  }
239 
241  {
243  }
244 
246  {
248  }
249 
251  {
253  }
254 
256  {
258  }
259 
261  {
263  }
264 
265  if (p->m_digest_sizing < 0)
266  {
268  }
269 
271  {
273  }
274 
275  if (p->m_mutex_sizing < 0)
276  {
277  count= fixed_mutex_instances
278  + con * mutex_per_connection
279  + handle * mutex_per_handle
280  + share * mutex_per_share;
281 
282  p->m_mutex_sizing= apply_load_factor(count, h->m_load_factor_volatile);
283  }
284 
285  if (p->m_rwlock_sizing < 0)
286  {
287  count= fixed_rwlock_instances
288  + con * rwlock_per_connection
289  + handle * rwlock_per_handle
290  + share * rwlock_per_share;
291 
292  p->m_rwlock_sizing= apply_load_factor(count, h->m_load_factor_volatile);
293  }
294 
295  if (p->m_cond_sizing < 0)
296  {
297  ulong count;
298  count= fixed_cond_instances
299  + con * cond_per_connection
300  + handle * cond_per_handle
301  + share * cond_per_share;
302 
303  p->m_cond_sizing= apply_load_factor(count, h->m_load_factor_volatile);
304  }
305 
306  if (p->m_file_sizing < 0)
307  {
308  count= fixed_file_instances
309  + con * file_per_connection
310  + handle * file_per_handle
311  + share * file_per_share;
312 
313  count= max<ulong>(count, file);
314  p->m_file_sizing= apply_load_factor(count, h->m_load_factor_normal);
315  }
316 
317  if (p->m_socket_sizing < 0)
318  {
319  count= fixed_socket_instances
320  + con * socket_per_connection
321  + handle * socket_per_handle
322  + share * socket_per_share;
323 
324  p->m_socket_sizing= apply_load_factor(count, h->m_load_factor_volatile);
325  }
326 
327  if (p->m_thread_sizing < 0)
328  {
329  count= fixed_thread_instances
330  + con * thread_per_connection
331  + handle * thread_per_handle
332  + share * thread_per_share;
333 
334  p->m_thread_sizing= apply_load_factor(count, h->m_load_factor_volatile);
335  }
336 }
337 
338 void pfs_automated_sizing(PFS_global_param *param)
339 {
340  PFS_sizing_data *heuristic;
341  heuristic= estimate_hints(param);
342  apply_heuristic(param, heuristic);
343 
344  DBUG_ASSERT(param->m_account_sizing >= 0);
345  DBUG_ASSERT(param->m_digest_sizing >= 0);
346  DBUG_ASSERT(param->m_host_sizing >= 0);
347  DBUG_ASSERT(param->m_user_sizing >= 0);
348 
349  DBUG_ASSERT(param->m_events_waits_history_sizing >= 0);
350  DBUG_ASSERT(param->m_events_waits_history_long_sizing >= 0);
351  DBUG_ASSERT(param->m_events_stages_history_sizing >= 0);
352  DBUG_ASSERT(param->m_events_stages_history_long_sizing >= 0);
353  DBUG_ASSERT(param->m_events_statements_history_sizing >= 0);
354  DBUG_ASSERT(param->m_events_statements_history_long_sizing >= 0);
355  DBUG_ASSERT(param->m_session_connect_attrs_sizing >= 0);
356 
357  DBUG_ASSERT(param->m_mutex_sizing >= 0);
358  DBUG_ASSERT(param->m_rwlock_sizing >= 0);
359  DBUG_ASSERT(param->m_cond_sizing >= 0);
360  DBUG_ASSERT(param->m_file_sizing >= 0);
361  DBUG_ASSERT(param->m_socket_sizing >= 0);
362  DBUG_ASSERT(param->m_thread_sizing >= 0);
363  DBUG_ASSERT(param->m_table_sizing >= 0);
364  DBUG_ASSERT(param->m_table_share_sizing >= 0);
365 }
366