Optimization parameters that the mysql storage engine needs to know

background

老版本与旧版本交替之际,需要了解之间参数的不同

In short
摘录于https://developer.aliyun.com/article/472132
link

MyISAM

MyISAM存储引擎优化

涉及参数如下:

Key_buffery_size

Concurrent_insert = 2 | WAAYS

Bulk_insert_buffer_size=8M

Myisam_recover_options=FORCE

Myisam_recover_threads=1

Myisam_sort_buffer_size=1G

key_buffery_size

It is mainly used to store the index information of the myisam table, and there is also a special IO scheduling algorithm. If it is uncertain, its buffer will be flushed out
. The default engine in mysql 5.6 version is adjusted to innodb, and the default engine for temporary tables is the same, so the myisam engine Basically adjust the key_buffer_size, but it can’t be banned, because most of the mysql library currently contains myisam and
only a few tables are innodb, so many of them are myisam engines that cannot be banned.
But for the 5.6 version, the key_buffer_size is 8M can

bulk_inser_buffer_size = 8M (default)

In the high version, the default is 8M, and the low version is still 4M; so if it is small, it can be changed to a larger value. Generally speaking, the value of SQL is:
insert into tb (c1,c2,c3) values(),()…;
If The configuration is 1M, then insert executes 4M data, in this case an error will be reported, and there is no need to adjust by default, but if you are doing data collection and other scenarios, you need to increase it

For the myisam table may be broken, the following parameters can be opened in this:

Myisam_recover_options=FORCE
Myisam_recover_threads=1
Myisam_sort_buffer_size=1G
This will automatically repair, and it is a repair for myisam table

但是有缺点,如果使用Myisam_recover_options=FORCE ,很可能会丢失数据,
因为myisam表已经不能保证数据一致性,所以丢数据也避免不了,所以,如果业务数据非常重要,
对于安全性要求很高,那么尽量不要用myisam

因为5.5之后官方不会对myisam做任何升级和维护;5.6之后默认引擎为innodb。临时表也改为innodb

innodb

innodb_buffer_pool_size

Mainly store hot data, store according to page, page is the smallest unit, or even store by segment
Suggested value: If it is a dedicated database server, it is recommended to allocate it to 50%-75% of physical memory

innodb_buffer_pool_instances

Mainly to facilitate the global lock of the buffer pool.
Generally, it is set to 8. In 5.5 version, it is divided to 4. After 5.6 version, it is divided to 8. It cannot be changed to other values, because this is the result of pressure measurement, 8 Is possible to get the best performance

innodb_log_file_size

It is recommended to set the percentage of the data page. For example, if the page is 15% and the buffer pool is 100G, the result of multiplying the two sides is 15G. In fact, the recommended value is equal to the data page configuration. It may not be configured so large, so Set file_size to 1g

So if we want to use multiple log files, the following parameters will be involved:
innodb_log_file_in_gourp

Several log files can be set, as for how to calculate:

Innodb's redo log file size, the total size is innodb_log_file_size *
Innodb_log_file_in_group the total size should not be less than 600M,
generally 3 log files are recommended

innodb_file_per_table

Whether to set up an independent table space
It was closed before 5.6, and opened by default after 5.6. It is recommended to be open

innodb_file_format #It is recommended to be designated as Barracuda

innodb_flush_log_at_trx_commit

If you
are importing data , it may not be completed in 2 or 3 days, then it may be the result of setting this parameter to 1, that is, it can be 2 when importing data. In other cases, it is recommended to
refresh to disk for each transaction. , High security, but the lowest performance, which often leads to the slowest
data transfer (high data security)
0 flushes transactions to disk
every second 2 flushes transactions and synchronizes to disk about once per second, but actually only writes to In the buffer of the operating system, if the operating system is powered off, it will cause errors and loss;
#Because the data is a process of human participation, set it to 2 to maximize the speed and complete it. If there is an error, you can do it again manually

innodb_flush_log_at_timeout (introduced in 5.6)

This parameter is used to control the log refresh every N seconds (between 1-2700 seconds). It is an enhancement to group commit. The default is 1 second, refreshed every 1 second and processed by crop commit. Actually, it can be done in 1-2700 seconds. If the system has high performance requirements, you can change this value Set a larger setting, and the throughput rate will be higher, because group commit will work better. If the real-time synchronization requirements are high, then set a lower value. The default value can
be a relative relationship. If Tuning the assembly to get a good performance, but there may be a delay from the library.
If you adjust to 3 seconds, then make a commit in these 3 seconds, then it hangs in the second second, then the data will be changed during the 2 seconds Lost

innodb_flush_method

Using the method of actually writing the specified data to the disk, you can directly use O_DIRECT.
O_DIRECT works on XFS or EXT4. The performance is very good. The
biggest problem is that O_DIRECT is used to reduce the system's VFS level cache. The saved memory can provide buffer Pool to use
If you use fsync to do it, it will take up the vfs level cache, it will take up a lot of memory, if the buffer pool is large, it is easy to cause oom,
so the use of O_DIRECT to do is to save memory and provide a larger buffer pool space

innodb_flush_neighbors

The default is 0. After using this parameter, it will refresh the dirty pages close to the extent. For
example, at the time of writing, the dirty pages will be checked. This time will merge the dirty pages into sequential writes, which means that the adjacent extents will also be merged. For example, the first extent and the second extent are next to each other, then after moving here, it is found that there is also the second one, so by the way, brush the second one too

If it is a sas sata disk, it is recommended to use 1; but for ssd, there is no addressing delay, so there is no need to refresh dirty pages, because it was originally hot data but changed to cold data after refreshing. The data will be loaded again (ssd keeps the default 0)

IO related optimization

innodb_io_capacity #important

This parameter is the maximum number of innodb io.
In general, 10W iops is normal, and optimization was carried out later: hdd 150 * number of disks, ssd 2000-10 thousand. For
example, 6 disks are made of RAID10, then the calculation is 150*3. What
needs to be considered is For a RAID with 6 disks, you need to consider how much fast disk IO capacity; then consider whether you can improve IO capacity if you do RAID 1 first. If you can’t improve it, then it is nothing more than 0 to improve IO capacity, so RAID10 with 6 disks can only get 3 Block disk IO capability

以下是对capactiy的补充参数

比如这里配置的是3块盘的450个,但是峰值会更高,可能会达到1000个或更多,那么可以对以下参数指定最大值

innodb_io_capacity_max              #设置io_capacity 最大值 

读写相关:

Innodb_write_io_threads

Innodb_read_io_threads

建议配置值:

保持与CPU的数量一样就可以了,比如是16核心的cpu 那么配置为16即可

如果是8核就配成8 以此类推

配置太高的话会到导致系统很卡 ,所以保持一致即可

Innodb_write_io_threshold

Only allow one prefech multiple pages to bp (0-64)
Innodb_random_read_ahead
Is the function of Prefech to bp turned on?
Considering some sequential IO and data loading issues. For
example, now read io threshold,
such as reading a user's information in a user system , Then this page will be loaded into the dp,
so you may need to say whether to load the adjacent page. There is a problem. If it is a user system, then you don’t need to load the adjacent page in a page and turn it off directly , Then this parameter is definitely 0 because no additional data is needed,
but if it is a friend relationship, if the data is read to this user, then the program needs to read and load the neighboring users. Then you can set this parameter to be larger. Read more, such as 3.
This parameter needs to be combined according to the business system. If you can’t help me, just leave it alone.

This article explains that the main technical content comes from the sharing of Internet technology giants, as well as some self-processing (only for the role of annotations). If related questions, please leave a message after the confirmation, the implementation of infringement will be deleted

Guess you like

Origin blog.csdn.net/baidu_34007305/article/details/110409482