简单了解MySQL参数压测的全过程

发布时间:2020-05-11 14:26:03 作者:三月
来源:亿速云 阅读:208

下文主要给大家带来MySQL参数压测的全过程,希望这些内容能够带给大家实际用处,这也是我编辑MySQL参数压测的全过程这篇文章的主要目的。好了,废话不多说,大家直接看下文吧。

1.测试背景

首先分别了解一下这两个参数的官方解释:

sync_binlog

Controls how often the MySQL server synchronizes the binary log to disk.
控制MySQL server 同步binlog到磁盘的频率

sync_binlog=0: Disables synchronization of the binary log to disk by the MySQL server. Instead, the MySQL server relies on the operating system to flush the binary log to disk from time to time as it does for any other file. This setting provides the best performance, but in the event of a power failure or operating system crash, it is possible that the server has committed transactions that have not been synchronized to the binary log.
关闭MySQL server binlog同步到磁盘,由OS不时的刷新到磁盘,这是MySQL最好的性能,但是当断电或者系统崩溃,MySQL server已经提交的事物可能还没有同步到binlog,导致事物丢失。

sync_binlog=1: Enables synchronization of the binary log to disk before transactions are committed. This is the safest setting but can have a negative impact on performance due to the increased number of disk writes. In the event of a power failure or operating system crash, transactions that are missing from the binary log are only in a prepared state. This permits the automatic recovery routine to roll back the transactions, which guarantees that no transaction is lost from the binary log.
在事物提交之前同步binlog到磁盘,这是最安全的,但是由于增加了磁盘的写操作,会有一些消极的性能影响。当断电或者系统崩溃,从binlog中丢失的事物仅仅处于准备状态。这个允许自动恢复程序去rollback事物,保证binlog没有事物丢失。

sync_binlog=N, where N is a value other than 0 or 1: The binary log is synchronized to disk after N binary log commit groups have been collected. In the event of a power failure or operating system crash, it is possible that the server has committed transactions that have not been flushed to the binary log. This setting can have a negative impact on performance due to the increased number of disk writes. A higher value improves performance, but with an increased risk of data loss.
在N个binlog提交组被收集到之后,binglog同步到磁盘。当断电或者系统崩溃,已经提交的事物可能还没有刷新到binlog。这样的配置增加了磁盘的写操作,会有一些消极的性能影响。N值越高,数据库性能越好,但是数据越可能丢失。

For the greatest possible durability and consistency in a replication setup that uses InnoDB with transactions, use these settings:
为了使使用InnoDB的复制设置具有最大的持久性和一致性,请使用以下设置:

sync_binlog=1.
innodb_flush_log_at_trx_commit=1.

Caution
Many operating systems and some disk hardware fool the flush-to-disk operation. They may tell mysqld that the flush has taken place, even though it has not. In this case, the durability of transactions is not guaranteed even with the recommended settings, and in the worst case, a power outage can corrupt InnoDB data. Using a battery-backed disk cache in the SCSI disk controller or in the disk itself speeds up file flushes, and makes the operation safer. You can also try to disable the caching of disk writes in hardware caches.
许多操作系统和一些磁盘硬件欺骗了刷新磁盘的操作。它们可能会告诉sqmyld flush已经发生了,尽管没有发生。在这种情况下,即使使用推荐的设置,事务的持久性也不能得到保证,在最坏的情况下,断电可能损坏InnoDB数据。在SCSI磁盘控制器或磁盘本身中使用电池支持的磁盘缓存可以加速文件刷新,并使操作更加安全。您还可以尝试禁用硬件缓存中的磁盘写缓存。

简单了解MySQL参数压测的全过程

innodb_flush_log_at_trx_commit

Controls the balance between strict ACID compliance for commit operations and higher performance that is possible when commit-related I/O operations are rearranged and done in batches. You can achieve better performance by changing the default value but then you can lose up to a second of transactions in a crash.
控制提交操作严格遵守ACID和提高性能之间的平衡,这在批量重新安排和执行与提交相关的I/O操作时是可能的,通过更改默认值,您可以获得更好的性能,但是在崩溃时,你可能会损失多达一秒钟的事务

The default value of 1 is required for full ACID compliance. With this value, the contents of the InnoDB log buffer are written out to the log file at each transaction commit and the log file is flushed to disk.
默认值1是必须的对ACID性.InnoDB日志缓冲区的内容在每个事务提交时被写到日志文件,日志文件被刷新到磁盘。

With a value of 0, the contents of the InnoDB log buffer are written to the log file approximately once per second and the log file is flushed to disk. No writes from the log buffer to the log file are performed at transaction commit. Once-per-second flushing is not guaranteed to happen every second due to process scheduling issues. Because the flush to disk operation only occurs approximately once per second, you can lose up to a second of transactions with any mysqld process crash.
值为0时,InnoDB日志缓冲区的内容大约每秒写入一次日志文件,日志文件被刷新到磁盘。事务提交时不执行从日志缓冲区写入日志文件的操作。由于进程调度问题,不能保证每秒一次刷新。由于对磁盘的刷新操作大约每秒钟只发生一次,因此您可以在任何mysqld进程中损失最多一秒钟的事务

With a value of 2, the contents of the InnoDB log buffer are written to the log file after each transaction commit and the log file is flushed to disk approximately once per second. Once-per-second flushing is not 100% guaranteed to happen every second, due to process scheduling issues. Because the flush to disk operation only occurs approximately once per second, you can lose up to a second of transactions in an operating system crash or a power outage.
当值为2时,InnoDB日志缓冲区的内容在每次事务提交后被写入日志文件,日志文件大约每秒被刷新一次。由于进程调度问题,每秒一次的刷新不能100%保证每秒发生。由于磁盘刷新操作大约每秒发生一次,所以在操作系统崩溃或断电时,最多可能损失1秒的事务。

InnoDB log flushing frequency is controlled by innodb_flush_log_at_timeout, which allows you to set log flushing frequency to N seconds (where N is 1 ... 2700, with a default value of 1). However, any mysqld process crash can erase up to N seconds of transactions.
DDL changes and other internal InnoDB activities flush the InnoDB log independent of the innodb_flush_log_at_trx_commit setting.
InnoDB crash recovery works regardless of the innodb_flush_log_at_trx_commit setting. Transactions are either applied entirely or erased entirely.
For durability and consistency in a replication setup that uses InnoDB with transactions:
If binary logging is enabled, set sync_binlog=1.
Always set innodb_flush_log_at_trx_commit=1.

Caution
Many operating systems and some disk hardware fool the flush-to-disk operation. They may tell mysqld that the flush has taken place, even though it has not. In this case, the durability of transactions is not guaranteed even with the recommended settings, and in the worst case, a power outage can corrupt InnoDB data. Using a battery-backed disk cache in the SCSI disk controller or in the disk itself speeds up file flushes, and makes the operation safer. You can also try to disable the caching of disk writes in hardware caches.


2.测试配置

这里TPCC和MySQL分别在两台机器上面,是为了排除TPCC运行过程中对MySQL服务资源的占用的影响

IP:172.16.101.54

CPU:2core

Memory:8G

软件:tpcc-mysql-master


IP:172.16.101.55

CPU:2core

Memory:6G

软件:MySQL5.7.21 


MySQL其他部分参数配置:

key_buffer_size = 8M
sort_buffer_size = 2M
read_buffer_size = 2M
read_rnd_buffer_size = 4M
query_cache_size= 0M
query_cache_type= off
max_allowed_packet = 64M
myisam_sort_buffer_size=128M
tmp_table_size=32M
table_open_cache = 2000
thread_cache_size = 8
wait_timeout = 300
interactive_timeout = 300
max_connections = 8000
max_user_connections=0
innodb_thread_concurrency = 4 
transaction_isolation = READ-COMMITTED
gtid-mode = on
enforce-gtid-consistency = true
log_slave_updates = on
innodb_buffer_pool_size = 5120M
innodb_log_buffer_size = 16M
innodb_lock_wait_timeout = 100

3.测试过程

测试主要分两种情况,通过tpcc测得MySQL server的tps和qps,每一种情况测试三遍,取平均值,并做成表格和折线图。


innodb_flush_log_at_trx_commit = 1 && sync_binlog = 1

or

innodb_flush_log_at_trx_commit = 0 && sync_binlog = 0


4.测试结果

首先说明一下,因为手头上只有这样低配置的云服务器,所以测试结果不是那么的可靠,所以仅仅参考测试思想和过程即可,不要太在意测试结果,哈哈。


(1)TpmC

即每分钟的事物数

线程数48163264128256512102415362048
i=1&s=1864.4331411.3672020.6672465.8672666.5332666.6332614.3332431.2672011.2331507.7331266.1
i=0&s=02761.3833160.052835.8172510.6832366.0172303.252367.5172251.8171834.5831439.6841166.3

简单了解MySQL参数压测的全过程


从图中我们可以看到:


(2)双1情况下的 slow queries,open tables,Queries per second avg等指标的情况


简单了解MySQL参数压测的全过程


从图中我们可以看到:

对于以上关于MySQL参数压测的全过程,大家是不是觉得非常有帮助。如果需要了解更多内容,请继续关注我们的行业资讯,相信你会喜欢上这些内容的。

推荐阅读:
  1. 简单了解tengine
  2. 简单了解MySQL的基础语句

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

mysql 参数压测

上一篇:iOS UI基本控件UIButton介绍

下一篇:基于域名、端口和IP搭建nginx虚拟主机

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》