Centos-7.7 安装 sysbench 压测服务器以及 MySQL

tech2022-09-18  97

作者:李红(老李),中国开源协会(oscna.org)数据库分会成员,热衷于数据库集群架构相关方向,上海某企业MySQL数据库负责人。

本文来源:Linux备忘录(iirwt.com)出品,转载请注明来源,谢谢。


 

备注:数据库自行安装,安装之后数据库的路径 一定要加入变量

一、项目地址

https://launchpad.net/sysbench

二、安装需要的依赖包以及做好相关的软连接 以及让配置生效

[root@unicom ~]# yum -y install make-* automake-* libtool-* pkgconfig-* libaio-devel-* gcc-* gcc-c++-* [root@unicom ~]# ln -s /storage/mysql/app/mysql/lib/libmysqlclient.so.20 /usr/local/lib/libmysqlclient.so.20 [root@unicom ~]# vim /etc/ld.so.conf /usr/local/lib #文件最后添加一行信息 [root@unicom ~]# ldconfig -v #让 /etc/ld.so.conf 的文件生效

三、下载软件以及解压安装

[root@unicom ~]# mkdir -p /storage/soft [root@unicom ~]# cd /storage/soft/ [root@unicom soft]# wget https://codeload.github.com/akopytov/sysbench/tar.gz/1.0.19 [root@unicom soft]# tar -zxvf 1.0.19 [root@unicom soft]# cd sysbench-1.0.19/ [root@unicom sysbench-1.0.19]# ./autogen.sh [root@unicom sysbench-1.0.19]# ./configure --prefix=/storage/mysql/app/sysbench --with-mysql=/storage/mysql/app/mysql --with-mysql-includes=/storage/mysql/app/mysql/include [root@unicom sysbench-1.0.19]# make && make install

四、配置环境变量

[root@unicom sysbench-1.0.19]# vim ~/.bash_profile PATH=$PATH:/storage/mysql/app/mysql/bin:/storage/mysql/app/sysbench/bin:$HOME/bin [root@unicom sysbench-1.0.19]# source ~/.bash_profile

五、查看安装的版本

[root@unicom sysbench-1.0.19]# sysbench --version sysbench 1.0.19

六、查看 sysbench 帮助 --help

[root@unicom sysbench-1.0.19]# sysbench --help Usage: sysbench [options]... [testname] [command] Commands implemented by most tests: prepare run cleanup help General options: --threads=N number of threads to use [1] 创建测试线程的数量,默认为 1 --events=N limit for total number of events [0] 事件最大数量,0为不限制 --time=N limit for total execution time in seconds [10] 最大执行时间,单位 S --forced-shutdown=STRING number of seconds to wait after the --time limit before forcing shutdown, or 'off' to disable [off] --thread-stack-size=SIZE size of stack per thread [64K] --rate=N average transactions rate. 0 for unlimited rate [0] --report-interval=N periodically report intermediate statistics with a specified interval in seconds. 0 disables intermediate reports [0] --report-checkpoints=[LIST,...] dump full statistics and reset all counters at specified points in time. The argument is a list of comma-separated values representing the amount of time in seconds elapsed from start of test when report checkpoint(s) must be performed. Report checkpoints are off by default. [] --debug[=on|off] print more debugging info [off] --validate[=on|off] perform validation checks where possible [off] --help[=on|off] print help and exit [off] --version[=on|off] print version and exit [off] --config-file=FILENAME File containing command line options --tx-rate=N deprecated alias for --rate [0] --max-requests=N deprecated alias for --events [0] --max-time=N deprecated alias for --time [0] --num-threads=N deprecated alias for --threads [1] Pseudo-Random Numbers Generator options: --rand-type=STRING random numbers distribution {uniform,gaussian,special,pareto} [special] --rand-spec-iter=N number of iterations used for numbers generation [12] --rand-spec-pct=N percentage of values to be treated as 'special' (for special distribution) [1] --rand-spec-res=N percentage of 'special' values to use (for special distribution) [75] --rand-seed=N seed for random number generator. When 0, the current time is used as a RNG seed. [0] --rand-pareto-h=N parameter h for pareto distribution [0.2] Log options: --verbosity=N verbosity level {5 - debug, 0 - only critical messages} [3] --percentile=N percentile to calculate in latency statistics (1-100). Use the special value of 0 to disable percentile calculations [95] --histogram[=on|off] print latency histogram in report [off] General database options: --db-driver=STRING specifies database driver to use ('help' to get list of available drivers) [mysql] --db-ps-mode=STRING prepared statements usage mode {auto, disable} [auto] --db-debug[=on|off] print database-specific debug information [off] Compiled-in database drivers: mysql - MySQL driver mysql options: --mysql-host=[LIST,...] MySQL server host [localhost] --mysql-port=[LIST,...] MySQL server port [3306] --mysql-socket=[LIST,...] MySQL socket --mysql-user=STRING MySQL user [sbtest] --mysql-password=STRING MySQL password [] --mysql-db=STRING MySQL database name [sbtest] --mysql-ssl[=on|off] use SSL connections, if available in the client library [off] --mysql-ssl-cipher=STRING use specific cipher for SSL connections [] --mysql-compression[=on|off] use compression, if available in the client library [off] --mysql-debug[=on|off] trace all client library calls [off] --mysql-ignore-errors=[LIST,...] list of errors to ignore, or "all" [1213,1020,1205] --mysql-dry-run[=on|off] Dry run, pretend that all MySQL client API calls are successful without executing them [off] Compiled-in tests: fileio - File I/O test cpu - CPU performance test memory - Memory functions speed test threads - Threads subsystem performance test mutex - Mutex performance test See 'sysbench &lt;testname&gt; help' for a list of options for each test. [root@unicom01 ~]#</pre> sysbench 脚本名以及脚本路径 <pre>[root@unicom sysbench-1.0.19]# cd /storage/mysql/app/sysbench/share/sysbench/tests/include/oltp_legacy/ [root@unicom01 oltp_legacy]# ls -lsa total 56 0 drwxr-xr-x 2 root root 284 Jan 8 15:38 . 4 drwxr-xr-x 3 root root 4096 Jan 8 15:38 .. 4 -rw-r--r-- 1 root root 1195 Jan 8 15:38 bulk_insert.lua 8 -rw-r--r-- 1 root root 4696 Jan 8 15:38 common.lua 4 -rw-r--r-- 1 root root 366 Jan 8 15:38 delete.lua 4 -rw-r--r-- 1 root root 1171 Jan 8 15:38 insert.lua 4 -rw-r--r-- 1 root root 3004 Jan 8 15:38 oltp.lua 4 -rw-r--r-- 1 root root 368 Jan 8 15:38 oltp_simple.lua 4 -rw-r--r-- 1 root root 527 Jan 8 15:38 parallel_prepare.lua 4 -rw-r--r-- 1 root root 369 Jan 8 15:38 select.lua 4 -rw-r--r-- 1 root root 1448 Jan 8 15:38 select_random_points.lua 4 -rw-r--r-- 1 root root 1556 Jan 8 15:38 select_random_ranges.lua 4 -rw-r--r-- 1 root root 369 Jan 8 15:38 update_index.lua 4 -rw-r--r-- 1 root root 578 Jan 8 15:38 update_non_index.lua [root@unicom01 oltp_legacy]#

七、sysbench 使用注意事项

(1)尽量不要在 MySQL 服务器运行的机器上进行测试,一方面可能无法体现网络(哪怕是局域网)的影响, 另一方面,sysbench 的运行(尤其是设置的并发数较高时)会影响 MySQL 服务器的表现。

(2)可以逐步增加客户端的并发连接数(–thread 参数),观察在连接数不同情况下,MySQL 服务器的表现; 如分别设置为 10,20,50,100 等。

(3)一般执行模式选择 complex 即可,如果需要特别测试服务器只读性能,或不使用事务时的性能, 可以选择 simple 模式或 nontrx 模式。

complex:测试最全面,会测试增删改查,会使用事务。simple:只测试简单的查询nontrx:不仅测试查询,还测试插入更新等,但不使用事务。 (4)如果连续进行多次测试,注意确保之前测试的数据已经被清理干净。

(5)测试表的数量不宜太少,至少要求 20 个表以上;每个表的数据量不宜太少,通常至少要求 1 千万以上, 也要根据 DB 服务器的配置适当调整;每次进行基准压测的时长不宜过短,通常要求持续 15 分钟以上; 每轮测试完毕后,中间至少暂停 5 分钟,或者确认系统负载完全恢复空跑状态为止

八、使用 sysbench 的一些建议

1、在开始测试之前,应该首先明确:应采用针对整个系统的基准测试,还是针对 MySQL 的基准测试,还是二者都需要。

2、如果需要针对 MySQL 的基准测试,那么还需要明确精度方面的要求:是否需要使用生产环境的真实数据,还是使用工具生成也可以; 前者实施起来更加繁琐。如果要使用真实数据,尽量使用全部数据,而不是部分数据。

3、基准测试要进行多次才有意义。

4、测试时需要注意主从同步的状态。

5、测试必须模拟多线程的情况,单线程情况不但无法模拟真实的效率,也无法模拟阻塞甚至死锁情况。

6、测试环境 主机、CPU、内存、RAID、硬盘、文件系统、系统版本、内存、MySQL、sysbench

7、压测基准值 多少张表,每张表多少数据量,测试脚本,测试多少时间,最大请求数多少,并发线程数,生成多大数量

九、进行 Sysench OLTP 测试-混合读写

(1)准备数据 mysql -uroot -proot create database sbtest; exit; [针对线程 --oltp-test-mode=complex(全量测试) oltp-tables-count=10(10张表) --oltp-table-size=100000(每张表数据大小 10W 行) --threads=10(线程数10个 相当于并发10个) --time=120(默认秒 120秒=2分钟) --report-interval=10(默认为秒 每 10 秒生成一个报告) prepare(开始准备)] cd /storage/mysql/app/sysbench/ sysbench ./share/sysbench/tests/include/oltp_legacy/oltp.lua \ --mysql-host=192.168.33.51 \ --mysql-port=3306 --mysql-user=root --mysql-password=root \ --oltp-test-mode=complex \ --oltp-tables-count=20 --oltp-table-size=100000 --threads=20 --time=120 \ --report-interval=10 prepare

(2)执行测试

mkdir -p /storage/mysql/app/sysbench/report #新建一个存放报告的文件目录路径 [针对线程 --oltp-test-mode=complex(全量测试) oltp-tables-count=10(10张表) --oltp-table-size=100000(每张表数据大小 10W 行) --threads=10(线程数10个 相当于并发10个) --time=120(默认秒 120秒=2分钟) --report-interval=10(默认为秒 每 10 秒生成一个报告) prepare(开始准备)] cd /storage/mysql/app/sysbench sysbench ./share/sysbench/tests/include/oltp_legacy/oltp.lua \ --mysql-host=192.168.33.51 \ --mysql-port=3306 --mysql-user=root --mysql-password=root \ --oltp-test-mode=complex \ --oltp-tables-count=10 --oltp-table-size=100000 --threads=10 --time=120 \ --report-interval=10 \ run &gt;&gt; /mysql/app/sysbench/report/mysysbench-18080401.log

(3)执行测试多执行几次才能看到效果

[针对线程 --oltp-test-mode=complex(全量测试) oltp-tables-count=20(20张表) --oltp-table-size=100000(每张表数据大小 10W 行) --threads=20(线程数20个 相当于并发20个) --time=120(默认秒 120秒=2分钟) --report-interval=10(默认为秒 每 10 秒生成一个报告) run(开始)] cd /storage/mysql/app/sysbench sysbench ./share/sysbench/tests/include/oltp_legacy/oltp.lua \ --mysql-host=192.168.33.51 \ --mysql-port=3306 --mysql-user=root --mysql-password=root \ --oltp-test-mode=complex \ --oltp-tables-count=20 --oltp-table-size=100000 --threads=20 --time=120 \ --report-interval=10 \ run &gt;&gt; /mysql/app/sysbench/report/mysysbench-18080402.log

(4)清除数据信息

cd /storage/mysql/app/sysbench sysbench ./share/sysbench/tests/include/oltp_legacy/oltp.lua \ --mysql-host=192.168.33.51 \ --mysql-port=3306 --mysql-user=root --mysql-password=root \ oltp_tables_count=10 cleanup

(5)查看测试结果校验报告

[root@unicom01 ~]# cd /storage/mysql/app/sysbench/report [root@unicom01 report]# ls -lsa total 8 0 drwxr-xr-x 2 root root 68 Jan 8 15:52 . 0 drwxr-xr-x 5 root root 44 Jan 8 15:46 .. 4 -rw-r--r-- 1 root root 2725 Jan 8 15:49 mysysbench-18080401.log 4 -rw-r--r-- 1 root root 2000 Jan 8 15:53 mysysbench-18080402.log [root@unicom01 report]# [root@unicom01 report]# more mysysbench-18080401.log sysbench 1.0.19 (using bundled LuaJIT 2.1.0-beta2) Running the test with following options: Number of threads: 10 Report intermediate results every 10 second(s) Initializing random number generator from current time Initializing worker threads... Threads started! --每 10 秒钟报告一次测试结果,TPS,QPS,95%以上的响应时长统计,每秒多少错误统计 [ 10s ] thds: 10 tps: 158.87 qps: 3191.79 (r/w/o: 2235.67/637.48/318.64) lat (ms,95%): 78.60 err/s: 0.00 reconn/s: 0.00 [ 20s ] thds: 10 tps: 167.70 qps: 3351.32 (r/w/o: 2346.74/669.18/335.39) lat (ms,95%): 70.55 err/s: 0.00 reconn/s: 0.00 [ 30s ] thds: 10 tps: 166.61 qps: 3333.69 (r/w/o: 2333.53/666.84/333.32) lat (ms,95%): 71.83 err/s: 0.00 reconn/s: 0.00 [ 40s ] thds: 10 tps: 162.60 qps: 3251.71 (r/w/o: 2276.33/650.28/325.09) lat (ms,95%): 77.19 err/s: 0.00 reconn/s: 0.00 [ 50s ] thds: 10 tps: 166.00 qps: 3321.84 (r/w/o: 2324.83/664.91/332.10) lat (ms,95%): 73.13 err/s: 0.00 reconn/s: 0.00 [ 60s ] thds: 10 tps: 168.10 qps: 3359.81 (r/w/o: 2351.84/671.78/336.19) lat (ms,95%): 70.55 err/s: 0.00 reconn/s: 0.00 [ 70s ] thds: 10 tps: 157.59 qps: 3150.10 (r/w/o: 2205.33/629.58/315.19) lat (ms,95%): 77.19 err/s: 0.00 reconn/s: 0.00 [ 80s ] thds: 10 tps: 166.21 qps: 3326.41 (r/w/o: 2328.24/665.74/332.42) lat (ms,95%): 71.83 err/s: 0.00 reconn/s: 0.00 [ 90s ] thds: 10 tps: 168.40 qps: 3365.31 (r/w/o: 2355.40/673.30/336.60) lat (ms,95%): 70.55 err/s: 0.00 reconn/s: 0.00 [ 100s ] thds: 10 tps: 166.10 qps: 3324.53 (r/w/o: 2327.32/664.81/332.40) lat (ms,95%): 71.83 err/s: 0.00 reconn/s: 0.00 [ 110s ] thds: 10 tps: 166.10 qps: 3322.55 (r/w/o: 2325.66/664.69/332.19) lat (ms,95%): 73.13 err/s: 0.00 reconn/s: 0.00 [ 120s ] thds: 10 tps: 165.00 qps: 3298.45 (r/w/o: 2309.23/659.21/330.00) lat (ms,95%): 74.46 err/s: 0.00 reconn/s: 0.00 SQL statistics: queries performed: read: 277242 --读总数 write: 79212 --写总数 other: 39606 --其他操作,如(commit,alter,delete) total: 396060 --全部总数 transactions: 19803 (164.93 per sec.) --TPS,总事务数(TPS,每秒事务数) queries: 396060 (3298.53 per sec.) --读写事务数(QPS,每秒事务数) ignored errors: 0 (0.00 per sec.) --忽略的错误数 reconnects: 0 (0.00 per sec.) --重新连接数 General statistics: --统计结果 total time: 120.0702s --总耗时 total number of events: 19803 --共发生了多少事务数 Latency (ms): --响应时长统计 min: 13.76 --最小耗时 avg: 60.61 --平均耗时 max: 377.66 --最长耗时 95th percentile: 73.13 --95%请求最大响应时间 sum: 1200356.69 --总耗时 Threads fairness: --与线程相关的指标 events (avg/stddev): 1980.3000/9.90 --事件(平均值/偏差) execution time (avg/stddev): 120.0357/0.02 --执行时间(平均值/偏差) [root@unicom01 report]#

十、安装分析工具(1) 备注:这个工具一定要有 图形界面 才能看到操作,命令界面很难实现需求

https://jaist.dl.sourceforge.net/project/gnuplot/gnuplot/ cd /storage/soft/ tar -zxvf gnuplot-5.2.8.tar.gz cd gnuplot-5.2.8 ./configure make &amp;&amp; make install

在 VMware-Workstation 上去操作,然后开启图形界面

startx gnuplot #进入 gnuplot 终端 gnuplot&gt; plot '/storage/mysql/app/sysbench/report/mysysbench-18080401.log' using 9 with lines title 'QPS'; #using 9 表示使用第 9 列数据作图 #with lines 定义图中的趋势使用线来表示 #title 'QPS' 定义线的名称 #使用,(逗号)分割,进行多列数据的绘制 mkdir -p /storage/mysql/app/sysbench/monitor touch /storage/mysql/app/sysbench/monitor/run vim /storage/mysql/app/sysbench/sysbench_monitor.sh #!/bin/bash #开始前获取全局配置参数 #每五秒获取一次 cpu load,MySQL 全局信息,InnoDB 引擎相关信息,线程信息 INTERVAL=5 PREFIX=$INTERVAL-sec-status RUNFILE=/storage/mysql/app/sysbench/monitor/run mysql -uroot -proot -e 'show global variables' &gt;&gt; mysql-variables #通过检测/storage/mysql/app/sysbench/run 文件是否存在作为是否进行获取信息的依据,可以在压 测结束时删除此文件停止收集 while test -e $RUNFILE; do file=$(date +%F_%H) sleep=$(date +%s.%N |awk "{print $INTERVAL -(\$1 % $INTERVAL)}") sleep $sleep ts="$(date +"TS %s.%N %F %T")" loadavg="$(uptime)" #通过 uptime 命令获取cpu load echo "$ts $loadavg"&gt;&gt; $PREFIX-${file}-status mysql -uroot -proot -e "show global status" &gt;&gt; $PREFIX-${file}-status &amp; #获取 MySQL 全局信息 echo "$ts $loadavg"&gt;&gt; $PREFIX-${file}-innodbstatus mysql -uroot -proot -e "show engine innodb status\G" &gt;&gt; $PREFIX-${file}-innodbstatus &amp; #获取引擎信息 echo "$ts $loadavg"&gt;&gt; $PREFIX-${file}-processlist mysql -uroot -proot -e "show full processlist\G" &gt;&gt; $PREFIX-${file}-processlist &amp; #获取线程信息 echo $ts done echo Exiting because $RUNFILE not exist chmod -R 777 /storage/mysql/app/sysbench/* cd /storage/mysql/app/sysbench/monitor nohup /storage/mysql/app/sysbench/sysbench_monitor.sh &amp;

备注:如果要停止运行 sysbench_monitor.sh 脚本如下操作

cd /storage/mysql/app/sysbench/monitor rm -rf run

备注:如果要继续运行 sysbench_monitor.sh 脚本如下操作

cd /storage/mysql/app/sysbench/monitor touch run chmod 777 * vim /storage/mysql/app/sysbench/sysbench_anaylyze.sh #!/bin/bash awk ' BEGIN{ printf "#ts date time load QPS"; fmt = " %.2f"; } /^TS/ { # The timestamp lines begin with TS. ts = substr($2, 1, index($2,".") - 1); load = NF - 2; diff = ts -prev_ts; prev_ts = ts; printf "\n%s %s %s %s",ts,$3,$4,substr($load, 1,length($load)-1); } /Queries/ { printf fmt, ($2-Queries)/diff; Queries=$2 } ' "$@"

运行方式:

cd /storage/mysql/app/sysbench/ ./sysbench_anaylyze.sh /mysql/app/sysbench/monitor/5-sec-status-2020-01-09_10-status &gt;&gt; /mysql/app/sysbench/monitor/sysbench_status_out.log cd /storage/mysql/app/sysbench/monitor/ more sysbench_status_out.log (将分析后的结果记入 sysbench_status_out.log 中) https://jaist.dl.sourceforge.net/project/gnuplot/gnuplot</pre> 同样使用 gnupot 进行绘图分析: <pre>gunplot&gt; plot '/storage/mysql/app/sysbench/monitor/sysbench_status_out.log' using 5 with lines title 'QPS', 4 with lines title 'load'; gunplot&gt; plot '/storage/mysql/app/sysbench/monitor/sysbench_status_out.log' using 4 with lines title 'cpuload'; #using 5 表示使用第 5 列数据作图 #with lines 定义图中的趋势使用线来表示 #title 'QPS' 定义线的名称 #使用,(逗号)分割,进行多列数据的绘制

十一、安装分析工具(2) nmon 分析工具

[root@unicom01 ~]# cat /etc/redhat-release CentOS Linux release 7.7.1908 (Core) [root@unicom01 ~]# mkdir -p /storage/soft/nmon [root@unicom01 ~]# cd /storage/soft/nmon/ [root@unicom01 nmon]# ls -lsa total 392 0 drwxr-xr-x 2 root root 33 Jan 9 10:58 . 0 drwxr-xr-x 5 root root 324 Jan 9 10:58 .. 392 -rw-r--r-- 1 root root 397618 Jan 9 10:57 nmon_x86_64_centos7 [root@unicom01 nmon]# chmod 777 * [root@unicom01 nmon]# which man /usr/bin/man [root@unicom01 nmon]# cp nmon_x86_64_centos7 /usr/bin/nmon [root@unicom01 nmon]# which nmon /usr/bin/nmon [root@unicom01 nmon]# [怎么调用 nmon] [root@unicom01 nmon]# nmon #直接调用

十二、sysbench 其他类型测试 (只读)

mysql -uroot -proot drop database sbtest; create database sbtest; exit; [准备数据信息] [针对线程 --oltp-read-only=on(只读模式) --oltp-skip-trx=on(省略开始和提交语句) --oltp-test-mode=nontrx(不产生事务) --oltp-nontrx-mode=select(只查询) oltp-tables-count=10(10张表) --oltp-table-size=100000(每张表数据大小 10W 行) --threads=10(线程数10个 相当于并发10个) --time=120(默认秒 120秒=2分钟) --report-interval=10(默认为秒 每 10 秒生成一个报告) prepare(开始准备)] sysbench /storage/mysql/app/sysbench/share/sysbench/tests/include/oltp_legacy/oltp.lua \ --mysql-host=192.168.33.51 \ --mysql-port=3306 --mysql-user=root --mysql-password=root \ --mysql-db=sbtest --oltp-tables-count=10 \ --oltp-table-size=100000 --threads=10 --time=120 --report-interval=10 \ --rand-init=on --max-requests=0 \ --oltp-test-mode=nontrx --oltp-nontrx-mode=select --oltp-read-only=on \ --oltp-skip-trx=on prepare [针对线程 --oltp-read-only=on(只读模式) --oltp-skip-trx=on(省略开始和提交语句) --oltp-test-mode=nontrx(不产生事务) --oltp-nontrx-mode=select(只查询) oltp-tables-count=10(10张表) --oltp-table-size=100000(每张表数据大小 10W 行) --threads=10(线程数10个 相当于并发10个) --time=120(默认秒 120秒=2分钟) --report-interval=10(默认为秒 每 10 秒生成一个报告) run(开始)] sysbench /storage/mysql/app/sysbench/share/sysbench/tests/include/oltp_legacy/oltp.lua \ --mysql-host=192.168.33.51 \ --mysql-port=3306 --mysql-user=root --mysql-password=root \ --mysql-db=sbtest --oltp-tables-count=10 \ --oltp-table-size=500000 --threads=10 --time=120 --report-interval=10 \ --rand-init=on --max-requests=0 \ --oltp-test-mode=nontrx --oltp-nontrx-mode=select \ --oltp-read-only=on --oltp-skip-trx=on run &gt; /mysql/app/sysbench/report/mysysbench-18080404.log [清除数据信息] sysbench /storage/mysql/app/sysbench/share/sysbench/tests/include/oltp_legacy/oltp.lua \ --mysql-host=192.168.33.51 --mysql-port=3306 --mysql-user=root \ --mysql-password=root --oltp-tables-count=10 cleanup [查看测试结果校验报告] [root@unicom01 ~]# cd /storage/mysql/app/sysbench/report/ [root@unicom01 report]# ls -lsa /storage/mysql/app/sysbench/report/ total 16 0 drwxrwxrwx 2 root root 130 Jan 9 11:47 . 0 drwxr-xr-x 6 root root 114 Jan 9 10:26 .. 4 -rwxrwxrwx 1 root root 2736 Jan 9 10:17 mysysbench-18080401.log 4 -rw-r--r-- 1 root root 2736 Jan 9 10:26 mysysbench-18080402.log 4 -rw-r--r-- 1 root root 2736 Jan 9 10:29 mysysbench-18080403.log 4 -rw-r--r-- 1 root root 2670 Jan 9 11:49 mysysbench-18080404.log

十三、只写-更新测试(主库写入操作)

mysql -uroot -proot drop database sbtest; create database sbtest; exit; [准备数据信息] [] sysbench /storage/mysql/app/sysbench/share/sysbench/tests/include/oltp_legacy/update_index.lua \ --mysql-host=192.168.33.51 --mysql-port=3306 --mysql-user=root \ --mysql-password=root --mysql-db=sbtest \ --oltp-tables-count=10 --oltp-table-size=10000 --threads=10 --time=20 \ --report-interval=10 \ --rand-init=on --oltp-read-only=off prepare sysbench /storage/mysql/app/sysbench/share/sysbench/tests/include/oltp_legacy/update_index.lua \ --mysql-host=192.168.33.51 --mysql-port=3306 --mysql-user=root \ --mysql-password=root \ --mysql-db=sbtest --oltp-tables-count=10 --oltp-table-size=500000 \ --threads=10 \ --time=20 --report-interval=10 --rand-init=on --oltp-read-only=off run &gt; /mysql/app/sysbench/report/mysysbench-18080405.log sysbench /storage/mysql/app/sysbench/share/sysbench/tests/include/oltp_legacy/update_index.lua \ --mysql-host=192.168.33.51 --mysql-port=3306 --mysql-user=root \ --oltp-tables-count=10 --mysql-password=root cleanup

十四、IO 性能测试-fileio

sysbench fileio help fileio options: --file-num=N 创建测试文件的数量。默认是 128 --file-block-size=N 测试时文件块的大小。默认是 16384(16K) --file-total-size=SIZE 测试文件的总大小。默认是 2G --file-test-mode=STRING 文件测试模式{seqwr(顺序写), seqrewr(顺序读写),seqrd(顺序读), rndrd(随机读), rndwr(随机写), rndrw(随机读写)} --file-io-mode=STRING 文件操作模式{sync(同步),async(异步),fastmmap(快速map 映射),slowmmap(慢 map 映射)}。默认是 sync --file-extra-flags=STRING 使用额外的标志来打开文件{sync,dsync,direct} 。默认为空 --file-fsync-freq=N 执行 fsync()的频率。(0 – 不使用 fsync())。默认是 100 --file-fsync-all=[on|off] 每执行完一次写操作就执行一次 fsync。默认是 off --file-fsync-end=[on|off] 在测试结束时才执行 fsync。默认是 on --file-fsync-mode=STRING 使用哪种方法进行同步{fsync, fdatasync}。默认是fsync --file-merged-requests=N 如果可以,合并最多的 IO 请求数(0 – 表示不合并)。默认是 0 --file-rw-ratio=N 测试时的读写比例。默认是 1.5

Sysbench 的文件测试模式:

seqwr 顺序写seqrew r 顺序读写seqrd 顺序读rndrd 随机读rndwr 随机写rndrw 随机读写 1. 准备 IO 测试文件:执行如下命令,生成 16 个文件,用于本次测试。 mkdir /storage/mysql/data/tmp cd /storage/mysql/data/tmp sysbench fileio --file-num=16 --file-total-size=20M prepare 测试多线程下小 IO 的随机只读性能 sysbench fileio --file-num=16 --file-total-size=20M \ --file-test-mode=rndrd --file-extra-flags=direct \ --file-fsync-freq=0 --file-block-size=16384 run File operations IOPS: reads/s: 6778.14 #每秒磁盘的读入次数 writes/s: 0.00 #每秒磁盘的写入次数 fsyncs/s: 0.00 #每秒同步的次数(从内存向磁盘同步的次数) Throughput: read, MiB/s: 105.91 #每秒的吞吐量(单位:M) written, MiB/s: 0.00 #每秒的写(单位:M) General statistics: total time: 10.0001s #总耗时(单位:秒) total number of events: 146727 #总事件 Latency (ms): min: 0.05 #最小响应时间 avg: 0.07 #平均响应时间 max: 12.25 #最大响应时间 95th percentile: 0.09 #95%的响应时间 sum: 9864.11 #总耗时 Threads fairness: events (avg/stddev): 146727.0000/0.00 #事件(平均值/偏差) execution time (avg/stddev): 9.8641/0.00 #执行时间(平均值/偏差) 备注:参数含义 -test=fileio 测试的名称叫做 fileio -file-num 文件的数量是16个 -file-test-mode=rndrd 测试模式是随机读取 -file-extra-flags=direct 使用额外的标志来打开文件{sync,dsync,direct} -file-fsync-freq=0 执行 fsync()的频率 -file-block-size=16384 测试文件块大的大小位 16384(16K) 测试多线程下小 IO 的随机写入性能 sysbench fileio --file-num=16 --file-total-size=20M \ --file-test-mode=rndwr --max-time=120 \ --file-extra-flags=direct --file-fsync-freq=0 --file-block-size=16384 run File operations: reads/s: 0.00 #每秒磁盘的读入次数 writes/s: 13605.12 #每秒磁盘的写入次数 fsyncs/s: 0.13 #每秒同步的次数(从内存向磁盘同步的次数) Throughput: read, MiB/s: 0.00 #每秒的吞吐量(单位:M) written, MiB/s: 212.58 #每秒的写(单位:M) General statistics: total time: 120.0013s #总耗时(单位:秒) total number of events: 1632656 #总事件 Latency (ms): min: 0.05 #最小响应时间 avg: 0.07 #平均响应时间 max: 15.42 #最大响应时间 95th percentile: 0.10 #95%的响应时间 sum: 118561.01 #总耗时 Threads fairness: events (avg/stddev): 1632656.0000/0.00 #事件(平均值/偏差) execution time (avg/stddev): 118.5610/0.00 #执行时间(平均值/偏差) 测试多线程下小 IO 的随机读写性能 sysbench fileio --file-num=16 --file-total-size=20M \ --file-test-mode=rndrw --file-extra-flags=direct \ --file-fsync-freq=0 --file-block-size=16384 run File operations: reads/s: 6823.92 #每秒磁盘的读入次数 writes/s: 4549.21 #每秒磁盘的写入次数 fsyncs/s: 1.60 #每秒同步的次数(从内存向磁盘同步的次数) Throughput: read, MiB/s: 106.62 #每秒的吞吐量(单位:M) written, MiB/s: 71.08 #每秒的写(单位:M) General statistics: total time: 10.0002s #总耗时(单位:秒) total number of events: 113756 #总事件 Latency (ms): min: 0.05 #最小响应时间 avg: 0.09 #平均响应时间 max: 9.45 #最大响应时间 95th percentile: 0.19 #95%的响应时间 sum: 9863.78 #总耗时 Threads fairness: events (avg/stddev): 113756.0000/0.00 #事件(平均值/偏差) execution time (avg/stddev): 9.8638/0.00 #执行时间(平均值/偏差) 清理测试时生成的文件 sysbench fileio --threads=20 --file-total-size=20M --file-test-mode=rndrw cleanup 701.MySQL数据库性能优化与运维诊断

十五、CPU 性能测试-cpu

--cpu-max-prime=N 最大质数发生器数量。默认是 10000 sysbench cpu --cpu-max-prime=2000 run 内存性能测试-memory sysbench memory help memory options: --memory-block-size=SIZE 测试时内存块大小。默认是 1K --memory-total-size=SIZE 传输数据的总大小。默认是 100G --memory-scope=STRING 内存访问范围{global,local}。默认是 global --memory-hugetlb=[on|off] 从 HugeTLB 池内存分配。默认是 off --memory-oper=STRING 内存操作类型。{read, write, none} 默认是 write --memory-access-mode=STRING 存储器存取方式{seq,rnd} 默认是 seq sysbench memory --memory-block-size=8k --memory-total-size=1G run 线程性能测试-threads threads options: --thread-yields=N 每个请求产生多少个线程。默认是 1000 --thread-locks=N 每个线程的锁的数量。默认是 8 sysbench threads --num-threads=100 --thread-yields=100 --thread-locks=4 run oltp 性能测试-oltp oltp options: --oltp-test-mode=STRING 执 行 模 式 {simple,complex(advanced transactional),nontrx(non-transactional),sp}。默认是 complex --oltp-reconnect-mode=STRING 重新连接模式{session(不使用重新连接。每个线程断 开只在测试结束),transaction(在每次事务结束后重新连接),query(在每个 SQL 语句执行完 重新连接),random(对于每个事务随机选择以上重新连接模式)}。默认是 session --oltp-sp-name=STRING 存储过程的名称。默认为空 --oltp-read-only=[on|off] 只读模式。Update,delete,insert 语句不可执行。默认是 off --oltp-skip-trx=[on|off] 省略 begin/commit 语句。默认是 off --oltp-range-size=N 查询范围。默认是 100 --oltp-point-selects=N number of point selects [10] --oltp-simple-ranges=N number of simple ranges [1] --oltp-sum-ranges=N number of sum ranges [1] --oltp-order-ranges=N number of ordered ranges [1] --oltp-distinct-ranges=N number of distinct ranges [1] --oltp-index-updates=N number of index update [1] --oltp-non-index-updates=N number of non-index updates [1] --oltp-nontrx-mode=STRING 查询类型对于非事务执行模式{select, update_key,update_nokey, insert, delete} [select] --oltp-auto-inc=[on|off] AUTO_INCREMENT 是否开启。默认是 on --oltp-connect-delay=N 在多少微秒后连接数据库。默认是 10000 --oltp-user-delay-min=N 每个请求最短等待时间。单位是 ms。默认是 0 --oltp-user-delay-max=N 每个请求最长等待时间。单位是 ms。默认是 0 --oltp-table-name=STRING 测试时使用到的表名。默认是 sbtest --oltp-table-size=N 测试表的记录数。默认是 10000 --oltp-dist-type=STRING 分布的随机数{uniform(均匀分布),Gaussian(高斯分布),special(空间分布)}。默认是 special --oltp-dist-iter=N 产生数的迭代次数。默认是 12 --oltp-dist-pct=N 值的百分比被视为'special' (for special distribution)。默认是 1 --oltp-dist-res=N ‘special’的百分比值。默认是 75 Sysbench 自定义脚本进行测试 自定义 lua 脚本的结构 unicomoltp.lua pathtest = string.match(test, "(.*/)") or "" -- dofile 是 lua 中的函数,加载并运行脚本,我们需要使用 common.lua 中的 set_vars()函数 dofile(pathtest .. "common.lua") function thread_init(thread_id) set_vars() -- 其他一些参数的处理 end -- event(thread_id) 可以把 sql 逻辑写到这里, --num-threads 多少个,就会同 时调用多少个,然后进行压测就 ok function event(thread_id)
最新回复(0)