Performance diagnostics in Managed Service for MySQL®
Managed Service for MySQL® has a built-in tool for collecting session and query statistics. These metrics can be useful when analyzing the cluster’s performance and optimizing its settings.
Enabling statistics collection
When creating a cluster or updating its settings:
- Enable Statistics sampling (disabled by default).
- Set the Sessions sampling interval and Statements sampling interval. The possible values range from
1to86400seconds.
If you do not have the Yandex Cloud CLI installed yet, install and initialize it.
By default, the CLI uses the folder specified when creating the profile. To change the default folder, use the yc config set folder-id <folder_ID> command. You can also set a different folder for any specific command using the --folder-name or --folder-id parameter.
To enable and configure statistics collection, provide the --performance-diagnostics parameter in the cluster update command:
yc managed-mysql cluster update <cluster_name_or_ID> \
...
--performance-diagnostics enabled=true,`
`sessions-sampling-interval=<session_sampling_interval>,`
`statements-sampling-interval=<statement_sampling_interval> \
...
For sessions-sampling-interval and statements-sampling-interval, the valid values range from 1 to 86400 seconds.
-
Open the current Terraform configuration file describing your infrastructure.
For more information on how to create this file, see this guide.
-
To enable and configure statistics collection, add the
performance_diagnosticssection to the cluster configuration:resource "yandex_mdb_mysql_cluster" "<cluster_name>" { ... performance_diagnostics { enabled = true sessions_sampling_interval = <session_sampling_interval> statements_sampling_interval = <statement_sampling_interval> } ... }For
sessions_sampling_intervalandstatements_sampling_interval, the valid values range from1to86400seconds. -
Make sure the settings are correct.
-
In the command line, navigate to the directory that contains the current Terraform configuration files defining the infrastructure.
-
Run this command:
terraform validateTerraform will show any errors found in your configuration files.
-
-
Confirm updating the resources.
-
Run this command to view the planned changes:
terraform planIf you described the configuration correctly, the terminal will display a list of the resources to update and their parameters. This is a verification step that does not apply changes to your resources.
-
If everything looks correct, apply the changes:
-
Run this command:
terraform apply -
Confirm updating the resources.
-
Wait for the operation to complete.
-
-
Timeouts
The Terraform provider sets the following timeouts for Managed Service for MySQL® cluster operations:
- Creating a cluster, including by restoring it from a backup: 15 minutes.
- Updating a cluster, including the MySQL® version update: 60 minutes.
- Deleting a cluster: 15 minutes.
Operations exceeding the timeout are aborted.
How do I change these limits?
Add the timeouts section to the cluster description, such as the following:
resource "yandex_mdb_mysql_cluster" "<cluster_name>" {
...
timeouts {
create = "1h30m" # 1 hour 30 minutes
update = "2h" # 2 hours
delete = "30m" # 30 minutes
}
}
-
Get an IAM token for API authentication and set it as an environment variable:
export IAM_TOKEN="<IAM_token>" -
To enable statistics collection when creating a cluster:
-
Use the Cluster.create method and add the
configSpec.performanceDiagnosticsparameter to the cURL cluster creation command:curl \ --request POST \ --header "Authorization: Bearer $IAM_TOKEN" \ --header "Content-Type: application/json" \ --url 'https://mdb.api.cloud.yandex.net/managed-mysql/v1/clusters' \ --data '{ "configSpec": { "performanceDiagnostics": { "enabled": <enable_statistics_collection>, "sessionsSamplingInterval": "<session_sampling_interval>", "statementsSamplingInterval": "<statement_sampling_interval>" }, ... }, ... }'Where
configSpec.performanceDiagnosticsis the statistics collection settings:enabled: Enables statistics collection,trueorfalse.sessionsSamplingInterval: Session sampling interval, from1to86400seconds.statementsSamplingInterval: Statement sampling interval, from60to86400seconds.
-
Check the server response to make sure your request was successful.
-
-
To enable statistics collection when updating an existing cluster:
-
Call the Cluster.update method, e.g., via the following cURL
request:Warning
The API method will assign default values to all the parameters of the object you are modifying unless you explicitly provide them in your request. To avoid this, list the settings you want to change in the
updateMaskparameter as a single comma-separated string.curl \ --request PATCH \ --header "Authorization: Bearer $IAM_TOKEN" \ --header "Content-Type: application/json" \ --url 'https://mdb.api.cloud.yandex.net/managed-mysql/v1/clusters/<cluster_ID>' \ --data '{ "updateMask": "configSpec.performanceDiagnostics", "configSpec": { "performanceDiagnostics": { "enabled": <enable_statistics_collection>, "sessionsSamplingInterval": "<session_sampling_interval>", "statementsSamplingInterval": "<statement_sampling_interval>" } } }'Where
configSpec.performanceDiagnosticsis the statistics collection settings:enabled: Enables statistics collection,trueorfalse.sessionsSamplingInterval: Session sampling interval, from1to86400seconds.statementsSamplingInterval: Statement sampling interval, from60to86400seconds.
-
Check the server response to make sure your request was successful.
-
-
Get an IAM token for API authentication and set it as an environment variable:
export IAM_TOKEN="<IAM_token>" -
Clone the cloudapi
repository:cd ~/ && git clone --depth=1 https://github.com/yandex-cloud/cloudapiBelow, we assume the repository contents are stored in the
~/cloudapi/directory. -
To enable statistics collection when creating a cluster:
-
Use the ClusterService/Create method and add the
config_spec.performance_diagnosticsparameter to the gRPCurl cluster creation command:grpcurl \ -format json \ -import-path ~/cloudapi/ \ -import-path ~/cloudapi/third_party/googleapis/ \ -proto ~/cloudapi/yandex/cloud/mdb/mysql/v1/cluster_service.proto \ -rpc-header "Authorization: Bearer $IAM_TOKEN" \ -d '{ "config_spec": { "performance_diagnostics": { "enabled": <enable_statistics_collection>, "sessions_sampling_interval": "<session_sampling_interval>", "statements_sampling_interval": "<statement_sampling_interval>" }, ... }, ... }' \ mdb.api.cloud.yandex.net:443 \ yandex.cloud.mdb.mysql.v1.ClusterService.CreateWhere
config_spec.performance_diagnosticsis the statistics collection settings:enabled: Enables statistics collection,trueorfalse.sessions_sampling_interval: Session sampling interval, from1to86400seconds.statements_sampling_interval: Statement sampling interval, from60to86400seconds.
-
Check the server response to make sure your request was successful.
-
-
To enable statistics collection when updating an existing cluster:
-
Call the ClusterService/Update method, e.g., via the following gRPCurl
request:Warning
The API method will assign default values to all the parameters of the object you are modifying unless you explicitly provide them in your request. To avoid this, list the settings you want to change in the
update_maskparameter as an array ofpaths[]strings.Format for listing settings
"update_mask": { "paths": [ "<setting_1>", "<setting_2>", ... "<setting_N>" ] }grpcurl \ -format json \ -import-path ~/cloudapi/ \ -import-path ~/cloudapi/third_party/googleapis/ \ -proto ~/cloudapi/yandex/cloud/mdb/mysql/v1/cluster_service.proto \ -rpc-header "Authorization: Bearer $IAM_TOKEN" \ -d '{ "cluster_id": "<cluster_ID>", "update_mask": { "paths": [ "config_spec.performance_diagnostics" ] }, "config_spec": { "performance_diagnostics": { "enabled": <enable_statistics_collection>, "sessions_sampling_interval": "<session_sampling_interval>", "statements_sampling_interval": "<statement_sampling_interval>" } } }' \ mdb.api.cloud.yandex.net:443 \ yandex.cloud.mdb.mysql.v1.ClusterService.UpdateWhere
config_spec.performance_diagnosticsis the statistics collection settings:enabled: Enables statistics collection,trueorfalse.sessions_sampling_interval: Session sampling interval, from1to86400seconds.statements_sampling_interval: Statement sampling interval, from60to86400seconds.
-
Check the server response to make sure your request was successful.
-
Getting session statistics
-
In the management console
, navigate to the folder dashboard and select Managed Service for MySQL. -
Click the name of your cluster and select Performance diagnostics → Sessions.
To view session statistics or the history of queries run within a session, select the relevant tab.
StatisticsHistoryTo view session statistics:
- Specify the time interval.
- Optionally, set filters.
- Select the data slice
.
To show or hide individual categories, click the category name in the chart legend.
To view the history of queries run within a session:
- Specify the time interval.
- Optionally, set filters.
Getting query statistics
-
In the management console
, navigate to the folder dashboard and select Managed Service for MySQL. -
Click the name of your cluster and select Performance diagnostics → Queries.
To view query statistics or compare them across two time intervals, select the relevant tab.
IntervalTwo intervalsTo view query statistics:
- Select the time interval.
- Optionally, set filters.
To get information about the relative changes in query statistics:
- In the Interval 1 field, select the time interval whose statistics will serve as the basis for calculations.
- In the Interval 2 field, select the time interval whose statistics will be compared with those of the first interval.
- Optionally, set filters.
Let’s assume, 10
SELECT * FROM citiesqueries were made in the first interval and 20, in the second one. When comparing statistics, the difference in the number of queries (theCallscolumn in the table) will be+100%.
Available metrics
This section lists metrics used to collect query statistics and the associated Managed Service for MySQL® metrics in Monitoring.
| Statistic metric | Monitoring metric | Description |
|---|---|---|
| Total query latency | - | Total query execution time |
| Total lock latency | - | Total lock wait time |
| Avg query latency | mysql_latency_query_avgDGAUGE, milliseconds |
Average query execution time |
| Avg lock latency | - | Average lock wait time |
| Rows examined | - | Number of rows read |
| Calls | - | Number of database calls |
| Rows sent | - | Number of rows returned |
| Rows affected | - | Number of rows changed, deleted, added, or returned |
| Tmp tables | mysql_Created_tmp_tables_rateDGAUGE, tables per second |
Rate of temporary tables created during query processing |
| Tmp disk tables | mysql_Created_tmp_disk_tables_rateDGAUGE, tables per second |
Rate of temporary tables created on the disk during query processing |
| Select full join | mysql_Select_full_join_rateDGAUGE, queries per second |
Rate of joins using table scans rather than indexes |
| Select full range join | mysql_Select_full_range_join_rateDGAUGE, queries per second |
Rate of joins searching by range in the reference table |
| Select range | - | Number of range selects |
| Select scan | - | Number of selects using table scans |
| Sort merge passes | - | Number of merge sorts on tables |
| Sort range | mysql_Sort_range_rateDGAUGE, queries per second |
Number of range sorts per unit of time |
| Sort rows | mysql_Sort_rows_rateDGAUGE, queries per second |
Number of rows sorted per unit of time |
| Sort scan | mysql_Sort_scan_rateDGAUGE, queries per second |
Number of sorts using table scans per unit of time |
| No index used | - | 1 if no index was used for the table scan, 0 otherwise |
| No good index used | - | 1 if no suitable index was found for the query, 0 otherwise |
| Errors | - | Number of query execution errors |
| Warnings | - | Number of query execution warnings |
For more information about the statistics you can get, see this MySQL® article