1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315
|
/* Copyright (c) 2012, 2023, Oracle and/or its affiliates.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2.0,
as published by the Free Software Foundation.
This program is also distributed with certain software (including
but not limited to OpenSSL) that is licensed under separate terms,
as designated in a particular file or component or in included license
documentation. The authors of MySQL hereby grant you an additional
permission to link the program and your derivative works with the
separately licensed software that they have included with MySQL.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License, version 2.0, for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software Foundation,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA */
/**
@file storage/perfschema/pfs_autosize.cc
Private interface for the server (implementation).
*/
#include "my_global.h"
#include "sql_const.h"
#include "pfs_server.h"
#include "set_var.h"
#include "my_thread.h" /* For pthread_t */
/* Make sure HAVE_PSI_XXX_INTERFACE flags are set */
#include "mysql/psi/psi.h"
#include <algorithm>
using std::min;
using std::max;
/** Performance schema sizing heuristics. */
struct PFS_sizing_data
{
/** Default value for @c PFS_param.m_events_waits_history_sizing. */
ulong m_events_waits_history_sizing;
/** Default value for @c PFS_param.m_events_waits_history_long_sizing. */
ulong m_events_waits_history_long_sizing;
/** Default value for @c PFS_param.m_events_stages_history_sizing. */
ulong m_events_stages_history_sizing;
/** Default value for @c PFS_param.m_events_stages_history_long_sizing. */
ulong m_events_stages_history_long_sizing;
/** Default value for @c PFS_param.m_events_statements_history_sizing. */
ulong m_events_statements_history_sizing;
/** Default value for @c PFS_param.m_events_statements_history_long_sizing. */
ulong m_events_statements_history_long_sizing;
/** Default value for @c PFS_param.m_events_transactions_history_sizing. */
ulong m_events_transactions_history_sizing;
/** Default value for @c PFS_param.m_events_transactions_history_long_sizing. */
ulong m_events_transactions_history_long_sizing;
/** Default value for @c PFS_param.m_digest_sizing. */
ulong m_digest_sizing;
/** Default value for @c PFS_param.m_session_connect_attrs_sizing. */
ulong m_session_connect_attrs_sizing;
};
PFS_sizing_data small_data=
{
/* History sizes */
5, 100, 5, 100, 5, 100, 5, 100,
/* Digests */
1000,
/* Session connect attrs. */
512
};
PFS_sizing_data medium_data=
{
/* History sizes */
10, 1000, 10, 1000, 10, 1000, 10, 1000,
/* Digests */
5000,
/* Session connect attrs. */
512
};
PFS_sizing_data large_data=
{
/* History sizes */
10, 10000, 10, 10000, 10, 10000, 10, 10000,
/* Digests */
10000,
/* Session connect attrs. */
512
};
PFS_sizing_data *estimate_hints(PFS_global_param *param)
{
if ((param->m_hints.m_max_connections <= MAX_CONNECTIONS_DEFAULT) &&
(param->m_hints.m_table_definition_cache <= TABLE_DEF_CACHE_DEFAULT) &&
(param->m_hints.m_table_open_cache <= TABLE_OPEN_CACHE_DEFAULT))
{
/* The my.cnf used is either unchanged, or lower than factory defaults. */
return & small_data;
}
if ((param->m_hints.m_max_connections <= MAX_CONNECTIONS_DEFAULT * 2) &&
(param->m_hints.m_table_definition_cache <= TABLE_DEF_CACHE_DEFAULT * 2) &&
(param->m_hints.m_table_open_cache <= TABLE_OPEN_CACHE_DEFAULT * 2))
{
/* Some defaults have been increased, to "moderate" values. */
return & medium_data;
}
/* Looks like a server in production. */
return & large_data;
}
static void apply_heuristic(PFS_global_param *p, PFS_sizing_data *h)
{
if (p->m_events_waits_history_sizing < 0)
{
SYSVAR_AUTOSIZE(p->m_events_waits_history_sizing,
h->m_events_waits_history_sizing);
}
if (p->m_events_waits_history_long_sizing < 0)
{
SYSVAR_AUTOSIZE(p->m_events_waits_history_long_sizing,
h->m_events_waits_history_long_sizing);
}
if (p->m_events_stages_history_sizing < 0)
{
SYSVAR_AUTOSIZE(p->m_events_stages_history_sizing,
h->m_events_stages_history_sizing);
}
if (p->m_events_stages_history_long_sizing < 0)
{
SYSVAR_AUTOSIZE(p->m_events_stages_history_long_sizing,
h->m_events_stages_history_long_sizing);
}
if (p->m_events_statements_history_sizing < 0)
{
SYSVAR_AUTOSIZE(p->m_events_statements_history_sizing,
h->m_events_statements_history_sizing);
}
if (p->m_events_statements_history_long_sizing < 0)
{
SYSVAR_AUTOSIZE(p->m_events_statements_history_long_sizing,
h->m_events_statements_history_long_sizing);
}
if (p->m_digest_sizing < 0)
{
SYSVAR_AUTOSIZE(p->m_digest_sizing,
h->m_digest_sizing);
}
if (p->m_events_transactions_history_sizing < 0)
{
SYSVAR_AUTOSIZE(p->m_events_transactions_history_sizing,
h->m_events_transactions_history_sizing);
}
if (p->m_events_transactions_history_long_sizing < 0)
{
SYSVAR_AUTOSIZE(p->m_events_transactions_history_long_sizing,
h->m_events_transactions_history_long_sizing);
}
if (p->m_session_connect_attrs_sizing < 0)
{
SYSVAR_AUTOSIZE(p->m_session_connect_attrs_sizing,
h->m_session_connect_attrs_sizing);
}
}
void pfs_automated_sizing(PFS_global_param *param)
{
if (param->m_enabled)
{
#ifndef HAVE_PSI_MUTEX_INTERFACE
param->m_mutex_class_sizing= 0;
param->m_mutex_sizing= 0;
#endif
#ifndef HAVE_PSI_RWLOCK_INTERFACE
param->m_rwlock_class_sizing= 0;
param->m_rwlock_sizing= 0;
#endif
#ifndef HAVE_PSI_COND_INTERFACE
param->m_cond_class_sizing= 0;
param->m_cond_sizing= 0;
#endif
#ifndef HAVE_PSI_FILE_INTERFACE
param->m_file_class_sizing= 0;
param->m_file_sizing= 0;
param->m_file_handle_sizing= 0;
#endif
#ifndef HAVE_PSI_TABLE_INTERFACE
param->m_table_share_sizing= 0;
param->m_table_sizing= 0;
param->m_table_lock_stat_sizing= 0;
param->m_index_stat_sizing= 0;
#endif
#ifndef HAVE_PSI_SOCKET_INTERFACE
param->m_socket_class_sizing= 0;
param->m_socket_sizing= 0;
#endif
#ifndef HAVE_PSI_STAGE_INTERFACE
param->m_stage_class_sizing= 0;
param->m_events_stages_history_sizing= 0;
param->m_events_stages_history_long_sizing= 0;
#endif
#ifndef HAVE_PSI_STATEMENT_INTERFACE
param->m_statement_class_sizing= 0;
param->m_events_statements_history_sizing= 0;
param->m_events_statements_history_long_sizing= 0;
#endif
#ifndef HAVE_PSI_SP_INTERFACE
param->m_program_sizing= 0;
if (param->m_statement_stack_sizing > 1)
param->m_statement_stack_sizing= 1;
#endif
#ifndef HAVE_PSI_PS_INTERFACE
param->m_prepared_stmt_sizing= 0;
#endif
#ifndef HAVE_PSI_STATEMENT_DIGEST_INTERFACE
param->m_digest_sizing= 0;
#endif
#ifndef HAVE_PSI_METADATA_INTERFACE
param->m_metadata_lock_sizing= 0;
#endif
#ifndef HAVE_PSI_MEMORY_INTERFACE
param->m_memory_class_sizing= 0;
#endif
PFS_sizing_data *heuristic;
heuristic= estimate_hints(param);
apply_heuristic(param, heuristic);
assert(param->m_events_waits_history_sizing >= 0);
assert(param->m_events_waits_history_long_sizing >= 0);
assert(param->m_events_stages_history_sizing >= 0);
assert(param->m_events_stages_history_long_sizing >= 0);
assert(param->m_events_statements_history_sizing >= 0);
assert(param->m_events_statements_history_long_sizing >= 0);
assert(param->m_events_transactions_history_sizing >= 0);
assert(param->m_events_transactions_history_long_sizing >= 0);
assert(param->m_session_connect_attrs_sizing >= 0);
}
else
{
/*
The Performance Schema is disabled. Set the instrument sizings to zero to
disable all instrumentation while retaining support for the status and
system variable tables, the host cache table and the replication tables.
*/
SYSVAR_AUTOSIZE(param->m_mutex_class_sizing, 0);
SYSVAR_AUTOSIZE(param->m_rwlock_class_sizing, 0);
SYSVAR_AUTOSIZE(param->m_cond_class_sizing, 0);
SYSVAR_AUTOSIZE(param->m_thread_class_sizing, 0);
SYSVAR_AUTOSIZE(param->m_table_share_sizing, 0);
SYSVAR_AUTOSIZE(param->m_table_lock_stat_sizing, 0);
SYSVAR_AUTOSIZE(param->m_index_stat_sizing, 0);
SYSVAR_AUTOSIZE(param->m_file_class_sizing, 0);
SYSVAR_AUTOSIZE(param->m_mutex_sizing, 0);
SYSVAR_AUTOSIZE(param->m_rwlock_sizing, 0);
SYSVAR_AUTOSIZE(param->m_cond_sizing, 0);
SYSVAR_AUTOSIZE(param->m_thread_sizing, 0);
SYSVAR_AUTOSIZE(param->m_table_sizing, 0);
SYSVAR_AUTOSIZE(param->m_file_sizing, 0);
SYSVAR_AUTOSIZE(param->m_file_handle_sizing, 0);
SYSVAR_AUTOSIZE(param->m_socket_sizing, 0);
SYSVAR_AUTOSIZE(param->m_socket_class_sizing, 0);
SYSVAR_AUTOSIZE(param->m_events_waits_history_sizing, 0);
SYSVAR_AUTOSIZE(param->m_events_waits_history_long_sizing, 0);
SYSVAR_AUTOSIZE(param->m_setup_actor_sizing, 0);
SYSVAR_AUTOSIZE(param->m_setup_object_sizing, 0);
SYSVAR_AUTOSIZE(param->m_host_sizing, 0);
SYSVAR_AUTOSIZE(param->m_user_sizing, 0);
SYSVAR_AUTOSIZE(param->m_account_sizing, 0);
SYSVAR_AUTOSIZE(param->m_stage_class_sizing, 0);
SYSVAR_AUTOSIZE(param->m_events_stages_history_sizing, 0);
SYSVAR_AUTOSIZE(param->m_events_stages_history_long_sizing, 0);
SYSVAR_AUTOSIZE(param->m_statement_class_sizing, 0);
SYSVAR_AUTOSIZE(param->m_events_statements_history_sizing, 0);
SYSVAR_AUTOSIZE(param->m_events_statements_history_long_sizing, 0);
SYSVAR_AUTOSIZE(param->m_digest_sizing, 0);
SYSVAR_AUTOSIZE(param->m_program_sizing, 0);
SYSVAR_AUTOSIZE(param->m_prepared_stmt_sizing, 0);
SYSVAR_AUTOSIZE(param->m_events_transactions_history_sizing, 0);
SYSVAR_AUTOSIZE(param->m_events_transactions_history_long_sizing, 0);
SYSVAR_AUTOSIZE(param->m_session_connect_attrs_sizing, 0);
SYSVAR_AUTOSIZE(param->m_statement_stack_sizing, 0);
SYSVAR_AUTOSIZE(param->m_memory_class_sizing, 0);
SYSVAR_AUTOSIZE(param->m_metadata_lock_sizing, 0);
SYSVAR_AUTOSIZE(param->m_max_digest_length, 0);
SYSVAR_AUTOSIZE(param->m_max_sql_text_length, 0);
}
}
|