tencent cloud

TencentDB for MySQL

Release Notes and Announcements
Release Notes
Product Announcements
User Tutorial
Product Introduction
Overview
Strengths
Use Cases
Database Architecture
Resource Isolation Policy
Economical Instance
Feature List
Database Instance
High Availability (Multi-AZ)
Regions and AZs
Service Regions and Service Providers
Kernel Features
Overview
Kernel Version Release Notes
Functionality Features
Performance Features
Security Features
Stability Features
TXRocks Engine
LibraDB Engine
Checking and Fixing Kernel Issues
Purchase Guide
Billing Overview
Selection Guide
Purchase Methods
Renewal
Payment Overdue
Refund
Pay-as-You-Go to Monthly Subscription
Instance Adjustment Fee
Backup Space Billing
Database Audit Billing Overview
Commercial Billing and Activity Description for Database Proxy
Description of the Database Proxy Billing Cycle
Viewing Bills
Getting Started
Overview
Creating MySQL Instance
Connecting to MySQL Instance
SQL Insight (Database Audit)
Overview
Viewing Audit Instance List
Enabling Audit Service
Viewing Audit Log
Log Shipping
Configuring Post-Event Alarms
Modifying Audit Rule
Modifying Audit Services
Disabling Audit Service
Audit Rule Template
SQL Audit Rule (Legacy)
Viewing Audit Task
Authorizing Sub-User to Use Database Audit
MySQL Cluster Edition
Introduction to TencentDB for MySQL Cluster Edition
Creating TencentDB for MySQL Cluster Edition Instance
Maintenance Management Instance
Viewing Instance Monitoring
Adjusting Instance Configuration
Operations for Other Features
Migrate or upgrade to TencentDB for MySQL Cluster Edition
Operation Guide
Use Limits
Operation Overview
Instance Management and Maintenance
Instance Upgrade
CPU Elastic Expansion
Read-Only/Disaster Recovery Instances
Database Proxy
Database Management Center (DMC)
Account Management
Parameter Configuration
Backup and Rollback
Data Migration
Network and Security
Monitoring and Alarms
Log Center
Read-Only Analysis Engine
Tag
Practical Tutorial
Using TencentDB for MySQL to Upgrade MySQL 5.7 to MySQL 8.0
Methods and Instructions for Upgrading from MySQL 5.6 to MySQL 5.7
Cybersecurity Classified Protection Practice for Database Audit of TencentDB for MySQL
Building All-Scenario High-Availability Architecture
Usage Specifications of TencentDB for MySQL
Configuring Automatic Application Reconnection
Impact of Modifying MySQL Source Instance Parameters
Limits on Automatic Conversion from MyISAM to InnoDB
Creating VPCs for TencentDB for MySQL
Enhancing Business Load Capacity with TencentDB for MySQL
Setting up 2-Region-3-DC Disaster Recovery Architecture
Improving TencentDB for MySQL Performance with Read/Write Separation
Migrating Data from InnoDB to RocksDB with DTS
Building LAMP Stack for Web Application
Building Drupal Website
Calling MySQL APIs in Python
The primary and secondary instances have inconsistent query data
White Paper
Performance White Paper
Security White Paper
Troubleshooting
Connections
Performance
Instance Data Sync Delay
Failure to Enable Case Insensitivity
Failure to Obtain slow_query_log_file via a Command
API Documentation
History
Introduction
API Category
Instance APIs
Making API Requests
Data Import APIs
Database Proxy APIs
Database Audit APIs
Security APIs
Task APIs
Backup APIs
Account APIs
Rollback APIs
Parameter APIs
Database APIs
Monitoring APIs
Log-related API
Data Types
Error Codes
FAQs
Related to Selection
Billing
Backup
Rollback
Connection and Login
Parameter Modifications
Instance Upgrade
Account Permissions
Performance and Memory
Ops
Data Migration
Features
Console Operations
Logs
Event
Database audit
Instance Switch Impact
API 2.0 to 3.0 Switch Guide
Service Agreement
Service Level Agreement
Terms of Service
Reference
Standards and Certifications
Contact Us
Glossary

Memory Allocation

PDF
Focus Mode
Font Size
Last updated: 2024-07-24 09:29:54
Memory is an important performance parameter for TencentDB for MySQL. It is common to see the memory utilization increase due to the presence of exceptional SQL statements and lack of database optimization. In severe cases, OOM can even occur and cause master/slave switchover, which compromises business stability and availability.
In MySQL, memory can be roughly divided into two parts: globally shared memory and session-level private memory. Shared memory is allocated upon the creation of an instance and shared by all connections. Private memory is used to allocate cache upon connection to the MySQL server. In some special SQL statements or field types, cache may be allocated to a single thread repeatedly. Therefore, all OOM exceptions are caused by the private memory of each connection. The composition of each part is as detailed below:

Shared Memory

Run the following command to query how the shared memory in the sample is allocated:
show variables where variable_name in ('innodb_buffer_pool_size','innodb_log_buffer_size','innodb_additional_mem_pool_size','key_buffer_size','query_cache_size');
Note:
innodb_additional_mem_pool_size is not supported in v5.7.
The following parameters are the query results of how the shared memory is allocated in an instance with 1,000 MB memory (below is the configuration of the test instance):
1. +---------------------------------+-----------+
2. | Variable_name | Value |
3. +---------------------------------+-----------+
4. | innodb_additional_mem_pool_size | 8388608 |
5. | innodb_buffer_pool_size | 524288000 |
6. | innodb_log_buffer_size | 67108864 |
7. | key_buffer_size | 16777216 |
9. | query_cache_size | 0 |
10. +---------------------------------+-----------+
11. 5 rows in set (0.01 sec)
Parameter description:
innodb_buffer_pool_size It is the most important buffer area in InnoDB and also a major means to compensate physical data files through memory. For TencentDB for MySQL, it usually takes up 50-80% memory of an instance (1,000 MB*0.5=500 MB as shown in the above sample). This area mainly includes information such as data pages, index pages, undo pages, insert buffers, adaptive hash indexes, lock information, and data dictionaries. In SQL read/write operations, you should first manipulate buffer_pool rather than physical data files and then write back to data files through checkpoint or other mechanisms. This space can help improve database performance and accelerate SQL operations, but it may slow down failover.
innodb_log_buffer_size It is mainly used to store redo logs and takes up 64 MB in TencentDB for MySQL. InnoDB will first write redo logs here and refresh them back to redo log files at a certain frequency. This space doesn't need to be large, because the buffer there is usually refreshed to redo logs at a relatively high frequency. Specifically, it will be refreshed for master thread (once every second), upon transactions committing, and when its available space is less than 1/2.
innodb_additional_mem_pool_size It is mainly used to store some data structures within InnoDB and is uniformly set to 8 MB in TencentDB for MySQL. Generally, when applying for memory in buffer_pool, you also need to apply for space to store the object's structural information in additional memory. The size of this part is primarily dependent on the number of tables. The more tables, the larger the space should be.
key_buffer_size It is an important buffer area of MyISAM tables and mainly used to store MyISAM table keys. It is uniformly set to 16 MB for all instances. Unlike InnoDB tables, MyISAM tables store index cache in key_buffer and data cache in the operating system memory. As TencentDB for MySQL uses MyISAM, this part should be allocated with a certain amount of space.
query_cache_size It is used to cache query results to reduce the overhead of SQL parsing and execution. The caching feature of this part is disabled in TencentDB for MySQL. It is mainly suitable for application scenarios where there are more reads than writes, because it caches results based on the hash values of SQL statements and becomes invalid once table data changes.

Private Memory

Run the following command to query how the session private memory in the sample is allocated:
show variables where variable_name in ('read_buffer_size','read_rnd_buffer_size','sort_buffer_size','join_buffer_size','binlog_cache_size','tmp_table_size');
The query result is displayed as follows (below is the configuration of the test instance):
1. +----------------------+-----------+
2. | Variable_name | Value |
3. +----------------------+-----------+
4. | binlog_cache_size | 32768 |
5. | join_buffer_size | 262144 |
6. | read_buffer_size | 262144 |
7. | read_rnd_buffer_size | 524288 |
8. | sort_buffer_size | 524288 |
9. | tmp_table_size | 209715200 |
10. +----------------------+-----------+
11. 6 rows in set (0.00 sec)
Parameter description:
read_buffer_size It stores the cache of sequential scans separately. When a thread scans data sequentially, it will first scan the buffer space to avoid causing more physical reads.
read_rnd_buffer_size It stores the cache of random scans separately. When a thread scans data randomly, it will first scan the buffer space to avoid causing more physical reads.
sort_buffer_size All the SQL statements that need to execute ORDER BY and GROUP BY will be allocated with sort_buffer to store the immediate results of the sorting operations. During sorting, if the storage size exceeds sort_buffer_size, a temporary table will be generated on the disk to complete the operation.
join_buffer_size MySQL only supports the nested-loop join (NLJ) algorithm. The processing logic is to jointly search in one row of the driving table and the non-driving table, where the latter can be placed in join_buffer without having to access buffer_pool that has a concurrence protection mechanism.
binlog_cache_size It is used to cache the thread's binlogs. Before a transaction is committed, its log will be stored in binlog_cache. After the transaction is committed, its binlog will be refreshed back to the binlog file on the disk for persistent storage.
tmp_table_size Different from the above session-level buffer, this parameter can be modified in the console. It refers to the size of a temporary in-memory table. If the temporary table created by the thread exceeds the specified size, it will be converted to a MyISAM temporary table on the disk.

Help and Support

Was this page helpful?

Help us improve! Rate your documentation experience in 5 mins.

Feedback