本文共 3617 字,大约阅读时间需要 12 分钟。
测试MySQL 5.7 和 MySQL 8.0 在不同持久化策略下的性能表现
在这个测试中,我们比较了MySQL 5.7.22 和 MySQL 8.0.15 在不同的持久化策略下(binlog 和 redo log 持久化)、在读写模式、预期模式和只写模式下的性能表现。测试使用了 sysbench 工具,并在双1模式(安全性模式)和 0 2模式(高级模式)下进行。
innodb_buffer_pool_size = 128Minnodb_log_buffer_size = 64Minnodb_log_file_size = 48Mbinlog_format = ROWtransaction_isolation = REPEATABLE-READ整体来看,MySQL 5.7.22 在读写模式、预期模式和只写模式下的性能表现均优于 MySQL 8.0.15。随着并发线程数的增加,性能提升趋势逐渐减弱,甚至出现下降。需要注意的是,本次测试是在配置较低的情况下进行的,结果并不代表绝对情况。
以下是用于测试的脚本:
#!/bin/bash# 该脚本用于 sysbench 测试在读写模式、只读模式、只写模式下 MySQL 5.7 和 MySQL 8.0 的 tps 和 qps# 使用方式:./sysbench_test_mysql.sh#!/bin/bashnohup bash $0 > /tmp/sysbench_test 2>&1 &user=adminpasswd=adminports="8015 57222"host=127.0.0.1sysbench_test_mode="oltp_read_write oltp_read_only oltp_write_only"sysbench_test_info_path=/tmp/sysbench-testfunction red_echo() { local what="$1" echo -e "$(date +%F-%T) $(tput -T -t 31m ${what} $(tput -T -t 0m))"}function check_last_comm() { if [ $1 -ne 0 ]; then red_echo "sysbench $2 threads cleanup mysqld${1}" exit 1 fi}function restart_mysqld() { service mysqld${1} restart sleep 2}function purge_binlog() { port=$1 mysql -u $user -p$passwd -P$port -h$host < purge_binary_logs_before_now()}function clean_os_cache() { echo 3 > /proc/sys/vm/drop_caches}function sysbench_with_diff_thread() { thread_num=$1 port=$2 test_mode=$3 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_last_comm "$port" || true clean_os_cache purge_binlog "$port" red_echo "sysbench $thread_num threads cleanup mysqld${port}" sysbench_with_diff_thread "$thread_num" "$port" "$test_mode" red_echo "sysbench $thread_num threads prepare mysqld${port}" sysbench_with_diff_thread "$thread_num" "$port" "$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" "$test_mode" > $sysbench_test_info_path/${test_mode}_${thread_num}_$port service mysqld${port} stop done done done}main 欢迎加入我的技术交流星球,探讨更多技术话题。
转载地址:http://snqfk.baihongyu.com/