MySQL InnoDB storage engine performance tuning

CPU

  • From the perspective of the design architecture of the InnoDB storage engine, its main background operations are completed in a separate master thread, so it does not support multi-core applications well. Of course, the open source community has tried to change this in a number of ways.
  • If your CPU is multi-core, you can increase the number of IO threads by modifying the parameters innodb_read_io_threadsand to make full use of the multi-core performance of the CPU.innodb_write_io_threads

Memory

  • The size of the buffer pool (InnoDB Buffer Pool) of the InnoDB storage engine directly affects the performance of the database.
  • How to judge whether the memory of the current database has reached the bottleneck? You can judge the hit ratio of the buffer pool by checking the current server status and comparing the ratio of physical disk reads and memory reads. Generally, the buffer pool hit rate of the InnoDB storage engine should not be lower than 99%.
  • We need to calculate the buffer pool hit ratio using the formula below.
    Innodb _ buffer _ pool _ read _ requests Innodb _ buffer _ pool _ read _ requests + Innodb _ buffer _ pool _ read _ ahead + Innodb _ buffer _ pool _ reads = buffer pool hit rate \frac{ Innodb\_buffer\_pool\_read\_re quests } { Innodb\_buffer\_pool\_read\_requests + Innodb\_buffer\_pool\_read\_ahead + Innodb\_buffer\_pool\_reads} = buffer pool hit rateInnodb_buffer_pool_read_requests+Innodb_buffer_pool_read_ahead+Innodb_buffer_pool_readsInnodb_buffer_pool_read_requests=buffer pool hit ratio
  • Use show global status like 'innodb%read%';the command such as to see the statistics, as shown in the figure below.
    insert image description here

Innodb_buffer_pool_reads : Indicates the number of pages read from the physical disk.
Innodb_buffer_pool_read_ahead : The number of times to read ahead.
Innodb_buffer_pool_read_ahead_evicted : Read-ahead pages, but the number of pages that are replaced from the buffer pool without being read, is generally used to judge the efficiency of read-ahead.
Innodb_buffer_pool_read_requests : The number of times pages were read from the buffer pool.
Innodb_data_read: The total number of bytes read.
Innodb_data_reads: The number of read requests initiated, each read may need to read multiple pages.

  • As can be seen from the above figure, the buffer pool hit rate = 16507 / (16507 + 0 + 868) ≈ 95%, you can try to increase the size of the buffer pool. Main tweaks innodb_buffer_pool_instancesand innodb_buffer_pool_sizeparameters.

innodb_buffer_pool_size: The size of the buffer pool. The default memory size is 128M. In theory, the larger the setting, the better the InnoDB table performance. However, if the setting is too large, it may cause the system to exchange SWAP pages. The MySQL recommended configuration size is 80% of the physical memory of the server.
innodb_buffer_pool_instances: The buffer pool is divided into multiple instances. For systems with multi-gigabyte buffer pools, dividing the buffer pool into separate instances can reduce contention when different threads read and write cache pages, thereby improving system concurrency. This parameter item is only meaningful when innodb_buffer_pool_size is set to 1GB or larger.

  • The formula for calculating the average number of bytes read per read is as follows.

    Innodb_data_read Innodb_data_reads = average number of bytes per read \frac{ Innodb\_data\_read } { Innodb\_data\_reads } = average number of bytes per readInnodb_data_readsInnodb_data_read=The average number of bytes read per

RAID

  • The basic idea of ​​RAID (Redundant Array of Independent Disks, redundant array of independent disks) is to combine multiple relatively cheap hard disks to form a disk array, so that the performance can reach or even exceed that of an expensive hard disk with huge capacity. Since multiple hard disks are combined into one logical sector, RAID looks like a single hard disk or logical storage unit, so the operating system treats it as one hard disk.

operating system

  • Most of the server memory exceeds 4GB, in order to better use the memory capacity greater than 4GB, you must use a 64-bit operating system. And use 64-bit MySQL to give full play to the addressing capability of the 64-bit operating system.

benchmark tool

  • Benchmarking tools can be used to compare the performance of an operating system or database before and after tuning. Commonly used tools are sysbenchand mysql-tpcc.

reference

  • "MySQL Technology Insider InnoDB Storage Engine"

Guess you like

Origin blog.csdn.net/baidu_19473529/article/details/129766315