mysql memory allocation problem

MySQL cloud database memory is an important performance parameters, the abnormal situation to be optimized SQL queries and database resulting in increased memory utilization often occurs, there will be instances occur because the OOM lead HA switch, affect the stability of the business and serious availability.

MySQL memory level can be divided into global shared memory and private memory level two session parts, create an instance of the shared memory is memory space that is allocated, and is shared by all connections. Private memory allocation for each of the cache when each connection to MySQL server, SQL or some special field types will lead to a single thread may allocate multiple buffers, so when an exception occurs OOM, are each connected by a private memory caused. The following describes the detailed configuration of each part.

mysql> show global variables like '%innodb_buffer%';
+-------------------------------------+----------------+
| Variable_name                       | Value          |
+-------------------------------------+----------------+
| innodb_buffer_pool_dump_at_shutdown | OFF            |
| innodb_buffer_pool_dump_now         | OFF            |
| innodb_buffer_pool_filename         | ib_buffer_pool |
| innodb_buffer_pool_instances        | 8              |
| innodb_buffer_pool_load_abort       | OFF            |
| innodb_buffer_pool_load_at_startup  | OFF            |
| innodb_buffer_pool_load_now         | OFF            |
| Innodb_buffer_pool_size | 16777216000 | # unit: bytes 
+ ------------------------------------- + - --------------- +

Shared memory

Execute the following command to query the shared memory allocation example:

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');

Description:

Version 5.7 does not support innodb_additional_mem_pool_size.

The following parameters are memory specifications for the results of the allocation of shared memory 1000MB instance (The following is an example test configuration):

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
    The partial cache Innodb engine is the most important buffer area is an important means to compensate for the physical file data through the memory, on the cloud will MySQL database instance size of 50% - An 80% as the size of the portion (upper graph 1000MB * 0.5 = 500MB). Wherein the main page contains data, index pages, page Use the undo, insert buffer, adaptive hash index, and lock data dictionary information and other information. During operation of SQL to read and write, not primarily on physical data file operations, but first of buffer_pool operation, and then write back the data file by checkpoint mechanisms. The advantage of this space is that you can improve the performance of the database, SQL accelerate the speed, the disadvantage is slow recovery.

  • innodb_log_buffer_size
    The main part of the redo log information stored in the cloud database MySQL will set the size of 64MB. InnoDB redo log will first be written here, and according to a certain frequency to refresh back to redo log files. The space does not need too much, because under normal circumstances this part of the cache will be refreshed at a faster frequency to redo log (Master Thread refreshes per second, will refresh the transaction commits, it will also refresh the space of less than 1/2).

  • innodb_additional_mem_pool_size
    The main part of the data structure to store some InnoDB, uniformly set to 8MB cloud database MySQL. When the application memory is usually in buffer_pool also you need to apply for space to store configuration information of the object in additional memory. The size of the main table and related to the number, the greater the number of tables needed more space.

  • key_buffer_size
    This is an important part of the cache area MyISAM table, all instances of unified 16M. The portion of the main storage key MyISAM tables. Unlike MyISAM tables InnoDB tables, which are cached in the cache index of key_buffer, the data is stored in the cache memory of the operating system. MySQL cloud database system is MyISAM engine, and therefore need to be given the part of a certain amount of space.

  • query_cache_size
    This part is doing the query result caching to reduce SQL and execute SQL parsing overhead, closed part of the cache in the cloud database MySQL. Mainly for reading and writing little scenario, because it is cached in accordance with the hash value of the SQL statement, when the table data changes after the failure.

Private memory

Execute the following command, query session private memory allocation example:

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');

Query results are as follows (hereinafter, the configuration of Test Example):

    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
      are stored in the cache for sequential scanning, when the thread data is scanned sequentially scans the first buffer to avoid more physical space read.

    • read_rnd_buffer_size
      were stored cache random scan, random scan when the thread data is first scans the buffer space to avoid more physical read.

    • sort_buffer_size
      you need to perform SQL is assigned sort_buffer order by group by and for storing intermediate results sorted. In the sorting process, if the memory is greater than sort_buffer_size, temporary table is generated in the disk to complete the operation.

    • join_buffer_size
      MySQL supports only join algorithm nest loop, the processing logic is driven and non-driven row table lookup table joins, then you can be a non-driving table into join_buffer, you do not need to have access buffer_pool concurrent protection mechanisms.

    • binlog_cache_size
      binlog log is used to cache the region of the thread, before a transaction can not commit its first store in binlog_cache log in, wait until after the transaction will commit its binlog brush back binlog file on disk to persist.

    • tmp_table_size
      different from each session level above buffer, this parameter can be changed on the console. This parameter is the size of user memory temporary table if the temporary table exceeds the size of the thread to create a temporary table it will be converted to a set of MyISAM temporary tables on disk.

Guess you like

Origin www.cnblogs.com/chenjw-note/p/10942990.html