争议 | MySQL 5.7 vs 8.0,哪个性能更牛一些?

背景

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

图片

前提

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

环境

机器

<pre data-tool="mdnice编辑器" style="margin: 10px 0px; padding: 0px; max-width: 100%; box-sizing: border-box !important; word-wrap: break-word !important; color: rgb(51, 51, 51); font-size: 17px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: 0.544px; orphans: 2; text-align: justify; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); overflow-wrap: break-word !important;">

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

</pre>

myql5.7.22

<pre data-tool="mdnice编辑器" style="margin: 10px 0px; padding: 0px; max-width: 100%; box-sizing: border-box !important; word-wrap: break-word !important; color: rgb(51, 51, 51); font-size: 17px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: 0.544px; orphans: 2; text-align: justify; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); overflow-wrap: break-word !important;">

5.7.22-log
innodb_buffer_pool_size 128M
innodb_log_buffer_size 64M
innodb_log_file_size 48M
binlog_format ROW
log_bin ON
transaction_isolation REPEATABLE-READ

</pre>

mysql8.0.15

<pre data-tool="mdnice编辑器" style="margin: 10px 0px; padding: 0px; max-width: 100%; box-sizing: border-box !important; word-wrap: break-word !important; color: rgb(51, 51, 51); font-size: 17px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: 0.544px; orphans: 2; text-align: justify; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); overflow-wrap: break-word !important;">

8.0.15
innodb_buffer_pool_size 128M
innodb_log_buffer_size 64M
innodb_log_file_size 48M
binlog_format ROW
log_bin ON
transaction_isolation REPEATABLE-READ

</pre>

sysbench

<pre data-tool="mdnice编辑器" style="margin: 10px 0px; padding: 0px; max-width: 100%; box-sizing: border-box !important; word-wrap: break-word !important; color: rgb(51, 51, 51); font-size: 17px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: 0.544px; orphans: 2; text-align: justify; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); overflow-wrap: break-word !important;">

sysbench -V
sysbench 1.1.0 (using bundled LuaJIT 2.1.0-beta3)

</pre>

图片

测试

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

**双1模式下 **

<pre data-tool="mdnice编辑器" style="margin: 10px 0px; padding: 0px; max-width: 100%; box-sizing: border-box !important; word-wrap: break-word !important; color: rgb(51, 51, 51); font-size: 17px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: 0.544px; orphans: 2; text-align: justify; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); overflow-wrap: break-word !important;">

SHOW GLOBAL VARIABLES WHERE Variable_name IN('sync_binlog','innodb_flush_log_at_trx_commit');
+--------------------------------+-------+
| Variable_name | Value |
+--------------------------------+-------+
| innodb_flush_log_at_trx_commit | 1 |
| sync_binlog | 1 |
+--------------------------------+-------+

</pre>

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 模式下 **

<pre data-tool="mdnice编辑器" style="margin: 10px 0px; padding: 0px; max-width: 100%; box-sizing: border-box !important; word-wrap: break-word !important; color: rgb(51, 51, 51); font-size: 17px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: 0.544px; orphans: 2; text-align: justify; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); overflow-wrap: break-word !important;">

SHOW GLOBAL VARIABLES WHERE Variable_name IN('sync_binlog','innodb_flush_log_at_trx_commit');
+--------------------------------+-------+
| Variable_name | Value |
+--------------------------------+-------+
| innodb_flush_log_at_trx_commit | 2 |
| sync_binlog | 0 |
+--------------------------------+-------+

</pre>

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 禁用预编译语句,不然并发测试线程多时会报下面的错误

<pre data-tool="mdnice编辑器" style="margin: 10px 0px; padding: 0px; max-width: 100%; box-sizing: border-box !important; word-wrap: break-word !important; color: rgb(51, 51, 51); font-size: 17px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: 0.544px; orphans: 2; text-align: justify; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); overflow-wrap: break-word !important;">

FATAL: mysql_stmt_prepare() failed
FATAL: MySQL error: 1461 "Can't create more than max_prepared_stmt_count statements (current value: 16382)"
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 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
FATAL: mysql_stmt_prepare() failed

</pre>

使用脚本

<pre data-tool="mdnice编辑器" style="margin: 10px 0px; padding: 0px; max-width: 100%; box-sizing: border-box !important; word-wrap: break-word !important; color: rgb(51, 51, 51); font-size: 17px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: 0.544px; orphans: 2; text-align: justify; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); overflow-wrap: break-word !important;">

cat sysbench_test_mysql5.7_8.0_tps_qps.sh

!/bin/bash

用于sysbench 测试在读写模式、只读模式、只写模式下 mysql5.7和mysql8.0 的tps,qps

nohup bash $0 >/tmp/sysbench_test 2>& 1 &

user=admin
passwd=admin
ports="8015 57222"
host=127.0.0.1
sysbench_test_mode="oltp_read_write oltp_read_only oltp_write_only"
sysbench_test_info_path=/tmp/sysbench-test

function red_echo () {

    local what="$*"
    echo -e "$(date +%F-%T) \e[1;31m ${what} \e[0m"

}

function check_las_comm(){
if [ 1 -ne 0 ];then red_echo2
exit 1
fi
}

function restart_mysqld(){
service mysqld${1} restart
sleep 2
}

function purge_binlog(){
port=1 mysql -uuser -ppasswd -Pport -h$host<<EOF
purge binary logs before now();
EOF
}

function clean_os_cache(){
echo 3 > /proc/sys/vm/drop_caches
}

function sysbench_with_diff_thread(){

thread_num=1 port=2
order=3 test_mode=4
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

}

function main(){
for test_mode in $sysbench_test_mode;do

for port in ports;do for thread_num in {5,10,20,30,40,80,120,200};do restart_mysqld "port"
check_las_comm "?" "restart mysqld{port} failed "
clean_os_cache
purge_binlog "$port"

  red_echo "sysbench $thread_num  threads cleanup mysqld${port}"
  sysbench_with_diff_thread "$thread_num" "$port" "cleanup" "$test_mode">/dev/null

  red_echo "sysbench $thread_num  threads prepare mysqld${port}"
  sysbench_with_diff_thread "$thread_num" "$port" "prepare" "$test_mode">/dev/null

  mkdir -p $sysbench_test_info_path
  red_echo "sysbench $thread_num  threads run mysqld${port} $test_mode"
  sysbench_with_diff_thread "$thread_num" "$port" "run" "$test_mode" > $sysbench_test_info_path/${test_mode}_${thread_num}_$port

  # service mysqld{port} stop
done

done
done

}

main

</pre>

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 221,273评论 6 515
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 94,349评论 3 398
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 167,709评论 0 360
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 59,520评论 1 296
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 68,515评论 6 397
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 52,158评论 1 308
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,755评论 3 421
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 39,660评论 0 276
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 46,203评论 1 319
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 38,287评论 3 340
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 40,427评论 1 352
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 36,122评论 5 349
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 41,801评论 3 333
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 32,272评论 0 23
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 33,393评论 1 272
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 48,808评论 3 376
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 45,440评论 2 359

推荐阅读更多精彩内容