Mysql之基准测试

基准测试不是压力测试,是每带有业务逻辑的测试。就是直击通过各种语句,压测服务器。

sysbench下载地址

https://dev.mysql.com/downloads/benchmarks.html




安装步骤

cd sysbench-1.0/

./autogen.sh 

./configure --prefix=/usr/local/sysbench/ --with-mysql --with-mysql-includes=/usr/local/mysql/include --with-mysql-libs=/usr/local/mysql/lib   #sysbench依赖mysql安装目录下的两个文件夹下的文件

make

make install

安装过程问题

如果报错为

/usr/local/sysbench/bin/sysbench: error while loading shared libraries: libmysqlclient.so.20: cannot open shared object file: No such file or directory

那么就执行

ln -s /usr/local/mysql/lib/libmysqlclient.so.20 /usr/lib64




OLTP测试

sysbench测试脚本目录:

/usr/local/sysbench/share/sysbench/tests/include/oltp_legacy

下面只测试各种混合场景(生产用的)

真实测试场景中,数据表建议不低于10个,单表数据量不低于500万行,当然了,要视服务器硬件配置而定。如果是配备了SSD或者PCIE SSD这种高IOPS设备的话,则建议单表数据量最少不低于1亿行

生产表语句:

/usr/local/sysbench/bin/sysbench /usr/local/sysbench/share/sysbench/tests/include/oltp_legacy/oltp.lua --mysql-host=localhost --mysql-port=33061 --mysql-table-engine=innodb  --oltp_tables_count=8 --table-size=100000 --db-driver=mysql --mysql-db=test --mysql-user=root --mysql-password=123456 --mysql-socket=/data/mysql/datanode1/node1.sock prepare

/usr/local/sysbench/share/sysbench/tests/include/oltp_legacy/oltp.lua  使用了这个脚本,可读写混合的

--oltp_tables_count=8   在test数据库,创建8个表

--mysql-table-engine=innodb  指定表的存储引擎类别

--table-size=100000   每张表数据量为10万

--mysql-db=test    在test这个数据库进行测试

--mysql-socket=/data/mysql/datanode1/node1.soc 指定socket

prepare 用于生产测试数据

混合场景压测:

/usr/local/sysbench/bin/sysbench /usr/local/sysbench/share/sysbench/tests/include/oltp_legacy/oltp.lua --mysql-host=localhost --mysql-port=33061 --mysql-table-engine=innodb --table-size=100000 --db-driver=mysql --mysql-db=test --mysql-user=root --mysql-password=123456 --oltp_tables_count=8 --max-requests=0 --threads=32 --oltp-read-olny=off --report-interval=10 --percentile=99 --max-time=360 --mysql-socket=/data/mysql/datanode1/node1.sock run

--max-requests=0   设置最大请求,0为不限制,想多少请求都可以,在限定的时间内

--threads=32  开启32个并发线程

--oltp-read-olny=off  读写混合

--report-interval=10 每10s打印一次报告输出

--percentile=99   去签名99%的数据进行分析

--max-time=360 这个命令执行360s

测试结果如下:

SQL statistics:

    queries performed:

        read:                            961506   #360s内一共的读请求

        write:                          274713   #360s内一共的写请求

        other:                          137357   #360s内除了读和写请求外其他的请求

        total:                          1373576    #360s内全部请求总和

    transactions:                        68678  (190.71 per sec.)   # 68678是总共事务数    190.71是平均每秒执行事务数

    queries:                            1373576 (3814.25 per sec.)   #1373576 总共查询数   3814.25 平均每秒查询数

    ignored errors:                      1      (0.00 per sec.)

    reconnects:                          0      (0.00 per sec.)

General statistics:

    total time:                          360.1108s  #总时间

    total number of events:              68678   #总共事务数

Latency (ms):

        min:                                  25.24  #最小的请求响应时间,毫秒

        avg:                                  167.75  #平均请求响应时间,毫秒

        max:                                5602.91  #最大请求响应时间,毫秒

        99th percentile:                      235.74   #签名99%的请求时间,最大为235.74毫秒

        sum:                            11520784.38   #全部等待请求响应的时间

Threads fairness:

    events (avg/stddev):          2146.1875/35.04  #平均每秒执行事件为2146.1875  标准为每秒35.04

    execution time (avg/stddev):  360.0245/0.02  #平均每个事件响应时间为 360.0245毫秒,标准为每个事件响应时间为0.02毫秒

你可能感兴趣的:(Mysql之基准测试)