MySQL压测--参数压测

本文涉及的产品
云数据库 RDS MySQL,集群系列 2核4GB
推荐场景:
搭建个人博客
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
云数据库 RDS PostgreSQL,集群系列 2核4GB
简介: 我们知道,MySQL为了保证数据的尽量不丢失,一般会把参数sync_binlog 和innodb_flush_log_at_trx_commit都设置为1,即双1原则,但是,凡是都有两面性,高安全和高性能往往是让人很难取舍的,需要根据你的实际业务需求进行抉择;1.

我们知道,MySQL为了保证数据的尽量不丢失,一般会把参数sync_binlog 和innodb_flush_log_at_trx_commit都设置为1,即双1原则,但是,凡是都有两面性,高安全和高性能往往是让人很难取舍的,需要根据你的实际业务需求进行抉择;


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磁盘控制器或磁盘本身中使用电池支持的磁盘缓存可以加速文件刷新,并使操作更加安全。您还可以尝试禁用硬件缓存中的磁盘写缓存。



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

即每分钟的事物数

线程数 4 8 16 32 64 128 256 512 1024 1536 2048
i=1&s=1 864.433 1411.367 2020.667 2465.867 2666.533 2666.633 2614.333 2431.267 2011.233 1507.733 1266.1
i=0&s=0 2761.383 3160.05 2835.817 2510.683 2366.017 2303.25 2367.517 2251.817 1834.583 1439.684 1166.3

blob.png


从图中我们可以看到:

  • 并发0-32的时候,双0的MySQL TpmC远远大于双1;

  • 并发>32后,两者之间的TpmC数量差不多


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


blob.png


从图中我们可以看到:

  • 随着并发越来越大,slow queries也越来越多;

  • 当并发达到512左右,open tables也达到参数table_open_cache = 2000的设定值;

  • 随着并发越来越大,QPS越来越小,刚开始并不明显,一度处于平衡,知道并发太大,QPS性能下降;


参考链接:

《MySQL压测--TPCC安装,测试》 http://blog.51cto.com/darrenmemos/2130202

《MySQL压测--注意事项和FAQ》 http://blog.51cto.com/darrenmemos/2132084



相关实践学习
如何在云端创建MySQL数据库
开始实验后,系统会自动创建一台自建MySQL的 源数据库 ECS 实例和一台 目标数据库 RDS。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助     相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
目录
相关文章
|
1月前
|
存储 SQL 关系型数据库
【MySQL调优】如何进行MySQL调优?从参数、数据建模、索引、SQL语句等方向,三万字详细解读MySQL的性能优化方案(2024版)
MySQL调优主要分为三个步骤:监控报警、排查慢SQL、MySQL调优。 排查慢SQL:开启慢查询日志 、找出最慢的几条SQL、分析查询计划 。 MySQL调优: 基础优化:缓存优化、硬件优化、参数优化、定期清理垃圾、使用合适的存储引擎、读写分离、分库分表; 表设计优化:数据类型优化、冷热数据分表等。 索引优化:考虑索引失效的11个场景、遵循索引设计原则、连接查询优化、排序优化、深分页查询优化、覆盖索引、索引下推、用普通索引等。 SQL优化。
397 15
【MySQL调优】如何进行MySQL调优?从参数、数据建模、索引、SQL语句等方向,三万字详细解读MySQL的性能优化方案(2024版)
|
18天前
|
SQL 关系型数据库 MySQL
数据库:MYSQL参数max_allowed_packet 介绍
数据库:MYSQL参数max_allowed_packet 介绍
20 2
|
5月前
|
存储 监控 关系型数据库
MySQL 参数innodb_read_io_threads
`innodb_read_io_threads` 是 MySQL 数据库中 InnoDB 存储引擎的一个配置参数,它用于指定后台线程池中用于处理读取 I/O 请求的线程数量。InnoDB 存储引擎负责管理数据库的物理存储和检索,是 MySQL 最常用的存储引擎之一。 ### 参数说明 - **名称**: `innodb_read_io_threads` - **默认值**: 4 - **范围**: 1 到 64 - **动态修改**: 不能动态修改(需要重启服务器) - **适用版本**: MySQL 5.6 及以上版本 ### 作用 `innodb_read_io_threads`
520 1
|
5月前
|
关系型数据库 MySQL 测试技术
MySQL性能测试(完整版)
MySQL性能测试(完整版)
421 1
|
5月前
|
缓存 关系型数据库 MySQL
MySQL查询优化:提速查询效率的13大秘籍(合理使用索引合并、优化配置参数、使用分区优化性能、避免不必要的排序和group by操作)(下)
MySQL查询优化:提速查询效率的13大秘籍(合理使用索引合并、优化配置参数、使用分区优化性能、避免不必要的排序和group by操作)(下)
241 0
|
3月前
|
分布式计算 关系型数据库 MySQL
MySQL超时参数优化与DataX高效数据同步实践
通过合理设置MySQL的超时参数,可以有效地提升数据库的稳定性和性能。而DataX作为一种高效的数据同步工具,可以帮助企业轻松实现不同数据源之间的数据迁移。无论是优化MySQL参数还是使用DataX进行数据同步,都需要根据具体的应用场景来进行细致的配置和测试,以达到最佳效果。
|
3月前
|
存储 缓存 关系型数据库
Mysql/etc/my.cnf参数详解
以上只是 `/etc/my.cnf`中的部分参数,实际上,`/etc/my.cnf`中的参数非常多,可以根据具体的应用需求进行调整。
71 0
|
4月前
|
关系型数据库 MySQL 测试技术
《阿里云产品四月刊》—瑶池数据库微课堂|RDS MySQL 经济版 vs 自建 MySQL 性能压测与性价比分析
阿里云瑶池数据库云原生化和一体化产品能力升级,多款产品更新迭代
|
5月前
|
SQL 关系型数据库 MySQL
实时计算 Flink版产品使用合集之使用 MySQL CDC 进行数据同步时,设置 server_id 参数如何解决
实时计算Flink版作为一种强大的流处理和批处理统一的计算框架,广泛应用于各种需要实时数据处理和分析的场景。实时计算Flink版通常结合SQL接口、DataStream API、以及与上下游数据源和存储系统的丰富连接器,提供了一套全面的解决方案,以应对各种实时计算需求。其低延迟、高吞吐、容错性强的特点,使其成为众多企业和组织实时数据处理首选的技术平台。以下是实时计算Flink版的一些典型使用合集。
|
4月前
|
存储 Oracle 关系型数据库
【MySQL技术内幕】3.1-参数文件
【MySQL技术内幕】3.1-参数文件
34 0