MySQL 5.7 vs 8.0,哪个性能更牛?

数据库 MySQL
测试mysql5.7和mysql8.0 分别在读写、只读、只写模式下不同并发时的性能(tps,qps)。

 背景

测试mysql5.7和mysql8.0 分别在读写、只读、只写模式下不同并发时的性能(tps,qps)

前提

  • 测试使用版本为mysql5.7.22和mysql8.0.15
  •  sysbench测试前先重启mysql服务,并清空os的cache(避免多次测试时命中缓存)
  •  每次进行测试都是新生成测试数据后再进行mysql5.7和mysql8.0的测试
  •  每次测试时保证mysql5.7和mysql8.0的配置参数一致

环境

机器 

  1. cat /etc/redhat-release | xargs echo '版本 ' && dmidecode -s system-product-name | xargs echo '是否虚拟化 ' && cat /proc/cpuinfo |grep "processor"|wc -l | xargs echo 'cpu核数 '  
  2. 版本 CentOS Linux release 7.5.1804 (Core)    
  3. 是否虚拟化 KVM    
  4. cpu核数 4 

 myql5.7.22 

  1. 5.7.22-log  
  2. innodb_buffer_pool_size 128M  
  3. innodb_log_buffer_size  64M  
  4. innodb_log_file_size    48M  
  5. binlog_format   ROW  
  6. log_bin ON  
  7. transaction_isolation   REPEATABLE-READ 

mysql8.0.15 

  1. 8.0.15 
  2. innodb_buffer_pool_size 128M  
  3. innodb_log_buffer_size  64M  
  4. innodb_log_file_size    48M  
  5. binlog_format   ROW  
  6. log_bin ON  
  7. transaction_isolation   REPEATABLE-READ 

sysbench 

  1. sysbench -V  
  2. sysbench 1.1.0 (using bundled LuaJIT 2.1.0-beta3)

测试

  •  在不同的持久化策略下(binlog, redo log持久化)mysql5.7和mysql8.0 在读写模式、只读模式、只写模式(oltp_read_write,oltp_read_only,oltp_write_only)下的性能表现
  •  sysbench 测试时间为60s,测试的表数量为20
  •  测试分别在双1模式(安全性)和0 2模式(高性能)下进行

双1模式下 

  1. SHOW GLOBAL  VARIABLES WHERE Variable_name IN('sync_binlog','innodb_flush_log_at_trx_commit');  
  2. +--------------------------------+-------+  
  3. | Variable_name                  | Value |  
  4. +--------------------------------+-------+  
  5. | innodb_flush_log_at_trx_commit | 1     |  
  6. | sync_binlog                    | 1   |  
  7. +--------------------------------+-------+ 

mysql5.7和mysql8.0 在读写模式下的表现 

  •  双1 配置,读写模式下,mysql5.7.22 和mysql8.0.15 tps 、qps 性能差不多,mysql8.0.15 在120 线程并发时,性能出现了下降抖动:

mysql5.7和mysql8.0 在只读模式下的表现   

  • 双1 配置,只读模式下,mysql5.7.22 的tps、qps比mysql8.0.15 好1/3 左右;并发线程数增加后,tps、qps并没有随着增加,反而出现了下降的趋势。

mysql5.7和mysql8.0 在只写模式下的表现

  •  双1 配置,只写模式下,随着并发数的上升,mysql5.7.22 的性能比mysql8.0.15 好1/4左右。

0 2 模式下 

  1. SHOW GLOBAL  VARIABLES WHERE Variable_name IN('sync_binlog','innodb_flush_log_at_trx_commit');  
  2. +--------------------------------+-------+  
  3. | Variable_name                  | Value |  
  4. +--------------------------------+-------+  
  5. | innodb_flush_log_at_trx_commit | 2     |  
  6. | sync_binlog                    | 0   |  
  7. +--------------------------------+-------+ 

mysql5.7和mysql8.0 在读写模式下的表现   

  • 0 2配置,读写模式下,并发数低时,mysql5.7.22性能好于mysql8.0.15; 并发数比较高时,mysql8.0.15 性能好于mysql5.7.22;在80 线程的并发以上时,性能开始下降。

mysql5.7和mysql8.0 在只读模式下的表现

  •  0 2配置,只读模式下,mysql5.7.22性能比mysql8.0.15 好1/3左右;随着并发数的上升,性能也没有上升,反而有下降的趋势.

mysql5.7和mysql8.0 在只写模式下的表现

  •  0 2 配置,只写模式下,mysql5.7.22的tps 抖动比较大;mysql5.7.22 的qps比mysql8.0.15好1/3左右

结论

  •  整体来看,mysql5.7.22在读写模式、只读模式、只写模式下的表现是优于mysql8.0.15的
  •  随着并行数的增加,性能表现不会也跟着增加,还会出现下降
  •  本次测试结果是在配置很低的情况下进行的,不代表绝对

注意

sysbench 需要设置--db-ps-mode=disable 禁用预编译语句,不然并发测试线程多时会报下面的错误 

  1. FATAL: mysql_stmt_prepare() failed  
  2. FATAL: MySQL error: 1461 "Can't create more than max_prepared_stmt_count statements (current value: 16382)"  
  3. FATAL: mysql_stmt_prepare() failed  
  4. FATAL: MySQL error: 1461 "Can't create more than max_prepared_stmt_count statements (current value: 16382)"  
  5. FATAL: thread_init' function failed: /usr/local/share/sysbench/oltp_common.lua:288: SQL API error FATAL: mysql_stmt_prepare() failed FATAL: MySQL error: 1461 "Can't create more than max_prepared_stmt_count statements (current value: 16382)" FATAL:thread_init' function failed: /usr/local/share/sysbench/oltp_common.lua:288: SQL API error 
  6. FATAL: mysql_stmt_prepare() failed 

使用脚本 

  1. cat sysbench_test_mysql5.7_8.0_tps_qps.sh  
  2. #!/bin/bash  
  3. #用于sysbench 测试在读写模式、只读模式、只写模式下 mysql5.7和mysql8.0 的tps,qps  
  4. #nohup bash $0 >/tmp/sysbench_test 2>& 1 &  
  5.  
  6. user=admin  
  7. passwd=admin  
  8. ports="8015 57222"  
  9. host=127.0.0.1  
  10. sysbench_test_mode="oltp_read_write oltp_read_only oltp_write_only"  
  11. sysbench_test_info_path=/tmp/sysbench-test  
  12. function red_echo () {  
  13.         local what="$*"  
  14.         echo -e "$(date +%F-%T) \e[1;31m ${what} \e[0m"  
  15.  
  16. function check_las_comm(){  
  17.     if [ $1 -ne 0 ];then  
  18.         red_echo $2  
  19.         exit 1  
  20.     fi  
  21.  
  22. function  restart_mysqld(){  
  23.   service mysqld${1} restart  
  24.   sleep 2  
  25.  
  26. function  purge_binlog(){  
  27. port=$1  
  28. mysql -u$user -p$passwd -P$port -h$host<<EOF  
  29. purge binary logs before now();  
  30. EOF  
  31.  
  32. function clean_os_cache(){  
  33.   echo 3 > /proc/sys/vm/drop_caches  
  34.  
  35. function  sysbench_with_diff_thread(){  
  36. thread_num=$1  
  37. port=$2  
  38. order=$3  
  39. test_mode=$4  
  40. sysbench /usr/local/share/sysbench/${test_mode}.lua --mysql_storage_engine=innodb  --table-size=100000 --tables=20 --mysql-db=test_1 --mysql-user=$user --mysql-password=$passwd --mysql-port=$port  --mysql-host=$host --threads=$thread_num  --time=60 --report-interval=2 --db-ps-mode=disable --events=0 --db-driver=mysql $order 
  41. function  main(){  
  42. for test_mode in $sysbench_test_mode;do  
  43.   for port in $ports;do  
  44.     for thread_num in {5,10,20,30,40,80,120,200};do  
  45.       restart_mysqld "$port"  
  46.       check_las_comm  "$?" "restart mysqld${port} failed "  
  47.       clean_os_cache  
  48.       purge_binlog "$port"  
  49.       red_echo "sysbench $thread_num  threads cleanup mysqld${port}"  
  50.       sysbench_with_diff_thread "$thread_num" "$port" "cleanup" "$test_mode">/dev/null  
  51.       red_echo "sysbench $thread_num  threads prepare mysqld${port}"  
  52.       sysbench_with_diff_thread "$thread_num" "$port" "prepare" "$test_mode">/dev/null  
  53.       mkdir -p $sysbench_test_info_path  
  54.       red_echo "sysbench $thread_num  threads run mysqld${port} $test_mode"  
  55.       sysbench_with_diff_thread "$thread_num" "$port" "run" "$test_mode" > $sysbench_test_info_path/${test_mode}_${thread_num}_$port  
  56.       # service mysqld{port} stop  
  57.     done  
  58.   done  
  59. done  
  60.  
  61. main 

 【编辑推荐】

 

责任编辑:庞桂玉 来源: 民工哥技术之路
相关推荐

2019-09-24 13:53:19

MySQLMySQL 8.0数据库

2019-03-01 09:36:25

ReactAngular开发

2022-05-23 09:11:18

AngularBlazor前端

2016-01-11 11:56:14

jQueryAngularJS

2024-02-26 07:39:16

2021-05-31 10:16:04

代码Java工具

2009-09-30 10:30:19

FreeBSD 8.0Ubuntu 9.10性能测试

2020-12-31 05:35:53

MySQL 8.0MySQL 5.7JSON

2020-07-31 13:55:57

MySQL数据库DBA

2024-04-18 09:00:00

MySQL数据库

2023-05-12 08:04:11

2021-12-01 10:18:08

MongoDBMySQL数据库

2023-12-11 07:37:08

mongodb经纬度性能

2023-05-03 21:34:34

MySQL状态变量

2023-06-20 12:02:39

WhileFor(;;)

2013-03-25 11:27:13

Windows Blu

2022-01-17 07:50:36

Maven Gradle 工具

2012-05-22 14:26:10

Windows 8显示器

2021-09-14 09:35:34

MySQL查询解析优化器
点赞
收藏

51CTO技术栈公众号