MariaDB 基准测试

作者: 灼灼2015 | 来源:发表于2016-08-18 10:39 被阅读448次

之前测试了应用使用MySQL5.7.12(连接、增删改查)等功能都已OK,在准备对MySQL5.7.12做基准测试的过程中,发现MySQL5.7.12的性能还没有MySQL5.1.73的性能好,非常崩溃,一打压CPU使用率就88%以上,然后TPS也不高。

猜测原因:连接的处理方式为One-Connection-Per-Thread,即对于每一个数据库连接,Mysql-Server都会创建一个独立的线程服务,请求结束后,销毁线程。再来一个连接请求,则再创建一个连接,结束后再进行销毁。忙于切换消耗掉CPU。

改用MariaDB,理由一:MySQL最强分支,理由二:有thread_pool功能

  1. 准备环境
    一:操作系统 CentOS 7
    二:32G内存
    三:1颗6核的CPU Intel(R) Xeon(R) CPU E5-2603 v3 @ 1.60GHz cpu MHz: 1200.062
    四:MariaDB配置:
innodb_buffer_pool_size=5G
innodb_log_file_size=1280M
innodb_log_buffer_size=16M
innodb_flush_log_at_trx_commit=2
innodb_file_per_table=1
max_connections=5000

五: MySQL 5.1.73 配置:

innodb_buffer_pool_size = 4G  #超过4G时 mysql无法启动
innodb_log_file_size = 1024M
innodb_log_buffer_size = 16M
innodb_flush_log_at_trx_commit=2
innodb_file_per_table=1
max_connections =5000

六:测试工具 sysbench 版本 0.5
分别发起1、4、8、16、32、64、128、256、512、1024、2048、4096连接对10张表(每表数据记录1000万)做只读、插入、读写混合操作,每隔5秒显示一次测试结果,测试请求次数:100万次

https://github.com/akopytov/sysbench 下载源码
./autogen.sh
./configure 
#如遇到:“drv_mysql.c:37:19: 致命错误:mysql.h:没有那个文件或目录” 请改用下面的参数配置
./configure --with-mysql-libs=/opt/mysql/lib --with-mysql-includes=/opt/mysql/include
make
make install
sysbench --version
sysbench 0.5
#如遇到sysbench: error while loading shared libraries: libmysqlclient.so.20: cannot open shared object file: No such file or directory
则在/etc/profile中加入export LD_LIBRARY_PATH=/opt/mysql/lib
  1. 测试结果


    sysbench OLTP read only.jpg
    sysbench OLTP read-write.jpg

结论:mariadb 的thread_pool 提升数据库的读写。
1)在数据库连接小的情况下,两者性能相差不大。
2)当数据库连接高于64后,mariadb性能明显高于mysql5.1,资源使用率高( CPU使用率 80%,IO:每秒7-9M/s)。
mysql5.1的连接数为512、1024、2048,响应时间分别为:3150ms、5874ms、31074ms。
mysql5.1连接数为4096时,数据库会报错,并发事务太多,日志来不及写,可提高innodb_log_file_size配置时启动报错。
mariadb 在连接数为512、1024、2048、4096,响应时间分别为:941ms、1592ms、2935ms、7678ms。

当前为1颗6核CPU,32G内,磁盘读写速度10.226Mb/sec,mariadb最高只读每秒2500TPS,读写每秒1250TPS,而mysql5.6官网企业版 只读14000TPS/s,读写1000TPS/s,CPU为64,磁盘读写速度未知。

附上测试脚本:

#!/bin/bash
# 初始化基础变量
test_dir=/opt/test/lixr/mysqltest/
test_file=/opt/test/lixr/tools/sysbench-0.5/sysbench/tests/db/oltp.lua
socket=$1
port=$2
mysqlname=$3
test=$4
common=" --mysql-db=sbtest --mysql-host=localhost --mysql-user=root --mysql-password=123456 --oltp-tables-count=10 --oltp-table-size=10000000 --report-interval=5 --oltp-dist-type=uniform --rand-init=on --oltp-test-mode=nontrx "

if [[ $test == "readonly" ]]; then
   echo "test readonly"
   testtype=" --oltp-nontrx-mode=select --oltp-read-only=on"
else
   echo "test read-write"
   testtype=" --oltp-nontrx-mode=complex --oltp-read-only=off"
fi 
if [ ! -d "$test_dir" ]; then  
  mkdir "$test_dir"  
fi  
cd $test_dir

for th in 1 4 8 16 32 64 128 256 512 1024 2048 4096;do
     loadavg="$(uptime)"
     ts="$(date +"TS %s.%N %F %T")"
     echo "$ts $loadavg" >> ${th}-$mysqlname-$test
     sysbench --test=${test_file} --num-threads=${th} --mysql-socket=$socket --mysql-port=$port $common  $testtype --max-requests=1000000  run >> ${th}-$mysqlname-$test
     echo "$ts $loadavg" >> ${th}-$mysqlname-$test
done

测试脚本:
sh -n test.sh #检查是否有语法错误
sh -x test.sh #检查是否有运行时错误
单个脚本:

#只读
sysbench --test=/opt/test/lixr/tools/sysbench-0.5/sysbench/tests/db/oltp.lua --num-threads=1 --mysql-db=sbtest --mysql-socket=/tmp/mysql5.sock --mysql-host=localhost --mysql-port=3308 --mysql-user=root --mysql-password=123456 --oltp-tables-count=10 --oltp-table-size=10000000 --report-interval=5 --oltp-dist-type=uniform --rand-init=on --oltp-test-mode=nontrx --oltp-nontrx-mode=select --oltp-read-only=on --max-requests=100000  run >> 1-600-mysql51-select &
sysbench --test=/opt/test/lixr/tools/sysbench-0.5/sysbench/tests/db/oltp.lua --num-threads=4 --mysql-db=sbtest --mysql-socket=/tmp/mysql5.sock --mysql-host=localhost --mysql-port=3308 --mysql-user=root --mysql-password=123456 --oltp-tables-count=10 --oltp-table-size=10000000 --report-interval=5 --oltp-dist-type=uniform --rand-init=on --oltp-test-mode=nontrx --oltp-nontrx-mode=select --oltp-read-only=on --max-requests=100000  run >> 4-600-mysql51-select &
sysbench --test=/opt/test/lixr/tools/sysbench-0.5/sysbench/tests/db/oltp.lua --num-threads=8 --mysql-db=sbtest --mysql-socket=/tmp/mysql5.sock --mysql-host=localhost --mysql-port=3308 --mysql-user=root --mysql-password=123456 --oltp-tables-count=10 --oltp-table-size=10000000 --report-interval=5 --oltp-dist-type=uniform --rand-init=on --oltp-test-mode=nontrx --oltp-nontrx-mode=select --oltp-read-only=on --max-requests=100000  run >> 8-600-mysql51-select &
sysbench --test=/opt/test/lixr/tools/sysbench-0.5/sysbench/tests/db/oltp.lua --num-threads=16 --mysql-db=sbtest --mysql-socket=/tmp/mysql5.sock --mysql-host=localhost --mysql-port=3308 --mysql-user=root --mysql-password=123456 --oltp-tables-count=10 --oltp-table-size=10000000 --report-interval=5 --oltp-dist-type=uniform --rand-init=on --oltp-test-mode=nontrx --oltp-nontrx-mode=select --oltp-read-only=on --max-requests=100000  run >> 16-600-mysql51-select &
sysbench --test=/opt/test/lixr/tools/sysbench-0.5/sysbench/tests/db/oltp.lua --num-threads=32 --mysql-db=sbtest --mysql-socket=/tmp/mysql5.sock --mysql-host=localhost --mysql-port=3308 --mysql-user=root --mysql-password=123456 --oltp-tables-count=10 --oltp-table-size=10000000 --report-interval=5 --oltp-dist-type=uniform --rand-init=on --oltp-test-mode=nontrx --oltp-nontrx-mode=select --oltp-read-only=on --max-requests=100000  run >> 32-600-mysql51-select &
sysbench --test=/opt/test/lixr/tools/sysbench-0.5/sysbench/tests/db/oltp.lua --num-threads=64 --mysql-db=sbtest --mysql-socket=/tmp/mysql5.sock --mysql-host=localhost --mysql-port=3308 --mysql-user=root --mysql-password=123456 --oltp-tables-count=10 --oltp-table-size=10000000 --report-interval=5 --oltp-dist-type=uniform --rand-init=on --oltp-test-mode=nontrx --oltp-nontrx-mode=select --oltp-read-only=on --max-requests=100000  run >> 64-600-mysql51-select &
sysbench --test=/opt/test/lixr/tools/sysbench-0.5/sysbench/tests/db/oltp.lua --num-threads=128 --mysql-db=sbtest --mysql-socket=/tmp/mysql5.sock --mysql-host=localhost --mysql-port=3308 --mysql-user=root --mysql-password=123456 --oltp-tables-count=10 --oltp-table-size=10000000 --report-interval=5 --oltp-dist-type=uniform --rand-init=on --oltp-test-mode=nontrx --oltp-nontrx-mode=select --oltp-read-only=on --max-requests=100000  run >> 128-600-mysql51-select &
sysbench --test=/opt/test/lixr/tools/sysbench-0.5/sysbench/tests/db/oltp.lua --num-threads=256 --mysql-db=sbtest --mysql-socket=/tmp/mysql5.sock --mysql-host=localhost --mysql-port=3308 --mysql-user=root --mysql-password=123456 --oltp-tables-count=10 --oltp-table-size=10000000 --report-interval=5 --oltp-dist-type=uniform --rand-init=on --oltp-test-mode=nontrx --oltp-nontrx-mode=select --oltp-read-only=on --max-requests=100000  run >> 256-600-mysql51-select &
sysbench --test=/opt/test/lixr/tools/sysbench-0.5/sysbench/tests/db/oltp.lua --num-threads=512 --mysql-db=sbtest --mysql-socket=/tmp/mysql5.sock --mysql-host=localhost --mysql-port=3308 --mysql-user=root --mysql-password=123456 --oltp-tables-count=10 --oltp-table-size=10000000 --report-interval=5 --oltp-dist-type=uniform --rand-init=on --oltp-test-mode=nontrx --oltp-nontrx-mode=select --oltp-read-only=on --max-requests=100000  run >> 512-600-mysql51-select &
sysbench --test=/opt/test/lixr/tools/sysbench-0.5/sysbench/tests/db/oltp.lua --num-threads=1024 --mysql-db=sbtest --mysql-socket=/tmp/mysql5.sock --mysql-host=localhost --mysql-port=3308 --mysql-user=root --mysql-password=123456 --oltp-tables-count=10 --oltp-table-size=10000000 --report-interval=5 --oltp-dist-type=uniform --rand-init=on --oltp-test-mode=nontrx --oltp-nontrx-mode=select --oltp-read-only=on --max-requests=100000  run >> 1024-600-mysql51-select &
sysbench --test=/opt/test/lixr/tools/sysbench-0.5/sysbench/tests/db/oltp.lua --num-threads=2048 --mysql-db=sbtest --mysql-socket=/tmp/mysql5.sock --mysql-host=localhost --mysql-port=3308 --mysql-user=root --mysql-password=123456 --oltp-tables-count=10 --oltp-table-size=10000000 --report-interval=5 --oltp-dist-type=uniform --rand-init=on --oltp-test-mode=nontrx --oltp-nontrx-mode=select --oltp-read-only=on --max-requests=100000  run >> 2048-600-mysql51-select &
sysbench --test=/opt/test/lixr/tools/sysbench-0.5/sysbench/tests/db/oltp.lua --num-threads=4096 --mysql-db=sbtest --mysql-socket=/tmp/mysql5.sock --mysql-host=localhost --mysql-port=3308 --mysql-user=root --mysql-password=123456 --oltp-tables-count=10 --oltp-table-size=10000000 --report-interval=5 --oltp-dist-type=uniform --rand-init=on --oltp-test-mode=nontrx --oltp-nontrx-mode=select --oltp-read-only=on --max-requests=100000  run >> 4096-600-mysql51-select &
#读写
sysbench --test=/opt/test/lixr/tools/sysbench-0.5/sysbench/tests/db/oltp.lua --num-threads=1 --mysql-db=sbtest --mysql-socket=/tmp/mysql5.sock --mysql-host=localhost --mysql-port=3308 --mysql-user=root --mysql-password=123456 --oltp-tables-count=10 --oltp-table-size=10000000 --report-interval=5 --oltp-dist-type=uniform --rand-init=on --oltp-test-mode=nontrx --oltp-nontrx-mode=complex --oltp-read-only=off --max-requests=100000  run >> 1-600-mysql51-complex &
sysbench --test=/opt/test/lixr/tools/sysbench-0.5/sysbench/tests/db/oltp.lua --num-threads=4 --mysql-db=sbtest --mysql-socket=/tmp/mysql5.sock --mysql-host=localhost --mysql-port=3308 --mysql-user=root --mysql-password=123456 --oltp-tables-count=10 --oltp-table-size=10000000 --report-interval=5 --oltp-dist-type=uniform --rand-init=on --oltp-test-mode=nontrx --oltp-nontrx-mode=complex --oltp-read-only=off --max-requests=100000  run >> 4-600-mysql51-complex &
sysbench --test=/opt/test/lixr/tools/sysbench-0.5/sysbench/tests/db/oltp.lua --num-threads=8 --mysql-db=sbtest --mysql-socket=/tmp/mysql5.sock --mysql-host=localhost --mysql-port=3308 --mysql-user=root --mysql-password=123456 --oltp-tables-count=10 --oltp-table-size=10000000 --report-interval=5 --oltp-dist-type=uniform --rand-init=on --oltp-test-mode=nontrx --oltp-nontrx-mode=complex --oltp-read-only=off --max-requests=100000  run >> 8-600-mysql51-complex &
sysbench --test=/opt/test/lixr/tools/sysbench-0.5/sysbench/tests/db/oltp.lua --num-threads=16 --mysql-db=sbtest --mysql-socket=/tmp/mysql5.sock --mysql-host=localhost --mysql-port=3308 --mysql-user=root --mysql-password=123456 --oltp-tables-count=10 --oltp-table-size=10000000 --report-interval=5 --oltp-dist-type=uniform --rand-init=on --oltp-test-mode=nontrx --oltp-nontrx-mode=complex --oltp-read-only=off --max-requests=100000  run >> 16-600-mysql51-complex &
sysbench --test=/opt/test/lixr/tools/sysbench-0.5/sysbench/tests/db/oltp.lua --num-threads=32 --mysql-db=sbtest --mysql-socket=/tmp/mysql5.sock --mysql-host=localhost --mysql-port=3308 --mysql-user=root --mysql-password=123456 --oltp-tables-count=10 --oltp-table-size=10000000 --report-interval=5 --oltp-dist-type=uniform --rand-init=on --oltp-test-mode=nontrx --oltp-nontrx-mode=complex --oltp-read-only=off --max-requests=100000  run >> 32-600-mysql51-complex &
sysbench --test=/opt/test/lixr/tools/sysbench-0.5/sysbench/tests/db/oltp.lua --num-threads=64 --mysql-db=sbtest --mysql-socket=/tmp/mysql5.sock --mysql-host=localhost --mysql-port=3308 --mysql-user=root --mysql-password=123456 --oltp-tables-count=10 --oltp-table-size=10000000 --report-interval=5 --oltp-dist-type=uniform --rand-init=on --oltp-test-mode=nontrx --oltp-nontrx-mode=complex --oltp-read-only=off --max-requests=100000  run >> 64-600-mysql51-complex &
sysbench --test=/opt/test/lixr/tools/sysbench-0.5/sysbench/tests/db/oltp.lua --num-threads=128 --mysql-db=sbtest --mysql-socket=/tmp/mysql5.sock --mysql-host=localhost --mysql-port=3308 --mysql-user=root --mysql-password=123456 --oltp-tables-count=10 --oltp-table-size=10000000 --report-interval=5 --oltp-dist-type=uniform --rand-init=on --oltp-test-mode=nontrx --oltp-nontrx-mode=complex --oltp-read-only=off --max-requests=100000  run >> 128-600-mysql51-complex &
sysbench --test=/opt/test/lixr/tools/sysbench-0.5/sysbench/tests/db/oltp.lua --num-threads=256 --mysql-db=sbtest --mysql-socket=/tmp/mysql5.sock --mysql-host=localhost --mysql-port=3308 --mysql-user=root --mysql-password=123456 --oltp-tables-count=10 --oltp-table-size=10000000 --report-interval=5 --oltp-dist-type=uniform --rand-init=on --oltp-test-mode=nontrx --oltp-nontrx-mode=complex --oltp-read-only=off --max-requests=100000  run >> 256-600-mysql51-complex &
sysbench --test=/opt/test/lixr/tools/sysbench-0.5/sysbench/tests/db/oltp.lua --num-threads=512 --mysql-db=sbtest --mysql-socket=/tmp/mysql5.sock --mysql-host=localhost --mysql-port=3308 --mysql-user=root --mysql-password=123456 --oltp-tables-count=10 --oltp-table-size=10000000 --report-interval=5 --oltp-dist-type=uniform --rand-init=on --oltp-test-mode=nontrx --oltp-nontrx-mode=complex --oltp-read-only=off --max-requests=100000  run >> 512-600-mysql51-complex &
sysbench --test=/opt/test/lixr/tools/sysbench-0.5/sysbench/tests/db/oltp.lua --num-threads=1024 --mysql-db=sbtest --mysql-socket=/tmp/mysql5.sock --mysql-host=localhost --mysql-port=3308 --mysql-user=root --mysql-password=123456 --oltp-tables-count=10 --oltp-table-size=10000000 --report-interval=5 --oltp-dist-type=uniform --rand-init=on --oltp-test-mode=nontrx --oltp-nontrx-mode=complex --oltp-read-only=off --max-requests=100000  run >> 1024-600-mysql51-complex &
sysbench --test=/opt/test/lixr/tools/sysbench-0.5/sysbench/tests/db/oltp.lua --num-threads=2048 --mysql-db=sbtest --mysql-socket=/tmp/mysql5.sock --mysql-host=localhost --mysql-port=3308 --mysql-user=root --mysql-password=123456 --oltp-tables-count=10 --oltp-table-size=10000000 --report-interval=5 --oltp-dist-type=uniform --rand-init=on --oltp-test-mode=nontrx --oltp-nontrx-mode=complex --oltp-read-only=off --max-requests=100000  run >> 2048-600-mysql51-complex &
sysbench --test=/opt/test/lixr/tools/sysbench-0.5/sysbench/tests/db/oltp.lua --num-threads=4096 --mysql-db=sbtest --mysql-socket=/tmp/mysql5.sock --mysql-host=localhost --mysql-port=3308 --mysql-user=root --mysql-password=123456 --oltp-tables-count=10 --oltp-table-size=10000000 --report-interval=5 --oltp-dist-type=uniform --rand-init=on --oltp-test-mode=nontrx --oltp-nontrx-mode=complex --oltp-read-only=off --max-requests=100000  run >> 4096-600-mysql51-complex &

相关文章

  • MariaDB 基准测试

    之前测试了应用使用MySQL5.7.12(连接、增删改查)等功能都已OK,在准备对MySQL5.7.12做基准测试...

  • mysql 基准测试

    mysql 基准测试 基准测试策略 基准测试指标 基准测试工具 基准测试样例

  • MySQL基准测试工具

    一、基准测试 基准测试(benchmark)是针对系统设计的一种压力测试。 基准测试是简化了的压力测试。 1.1 ...

  • 数据库基准测试工具-sysbench

    基准测试 定义 数据库的基准测试是对数据库的性能指标进行定量的、可复现的、可对比的测试。 基准测试与压力测试 基准...

  • go 基准测试

    基准测试主要用于评估代码的性能,Go 语言测试框架可以让我们很容易地进行基准测试,同样需要遵循四点规则: 基准测试...

  • 什么是MySQL的基准测试

    1.MySQL基准测试 什么是基准测试: 基准测试是一种测量和评估软件性能指标的活动用于建立某个时刻的性能基准,以...

  • 高性能MySQL第二章 读书笔记

    第2章 MySQL基准测试 基准测试可以在系统的实际负载之外创造一些虚构场景进行测试。 基准测试的一个主要问题在于...

  • Go语言之基准测试

    在Go语言中,提供了测试函数性能(CPU和Memory)的测试方法,基准测试。 基准测试主要用来测试CPU和内存的...

  • JMH微基准测试快速入门

    前言JMH是一个微基准测试框架,什么是微基准测试? Micro benchmark is a benchmark ...

  • 性能测试案例与经验分享

    性能基准测试 性能基准测试,通常被称为 Performance Benchmark Test,是每次对外发布产品版...

网友评论

    本文标题:MariaDB 基准测试

    本文链接:https://www.haomeiwen.com/subject/viadsttx.html