下载sysbench
git clone https://github.com/akopytov/sysbench
fio下载 https://git.kernel.dk/cgit/fio/tag/?h=fio-3.20
复制
安装sysbench
1、sysbench的一些安装依赖: yum install -y autoconf automake make libtool* libaio-devel gcc pkgconfig vim-common gcc相关包 mpfr-3.1.1-4.el7.x86_64.rpm libmpc-1.0.1-3.el7.x86_64.rpm kernel-headers-3.10.0-123.el7.x86_64.rpm glibc-headers-2.17-55.el7.x86_64.rpm glibc-devel-2.17-55.el7.x86_64.rpm cpp-4.8.2-16.el7.x86_64.rpm gcc-4.8.2-16.el7.x86_64.rpm rpm -Uvh *.rpm --nodeps --force 2、执行autogen.sh用它来生成configure这个文件 # 可能还需要安装perl相关包 cd /app/sysbench ./autogen.sh 3、执行configure && make && make install 来完成sysbench的安装 ./configure --prefix=/app/sysbench/ --with-mysql --with-mysql-includes=/app/mysql/include --with-mysql-libs=/app/mysql/lib make && make install ## 报错 # sysbench --help sysbench: error while loading shared libraries: libmysqlclient.so.20: cannot open shared object file: No such file or directory ##解决办法: # cp /app/mysql/lib/libmysqlclient.so.20 /usr/lib64/ ## 安装程序前手动设置动态链接库位置 将/usr/local/mysql/lib路径增加到/etc/ld.so.conf文件中去,执行ldconfig -v让系统重新加载动态链接库 在/etc/profile中添加共享库的路径,export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/data/mysql/base/lib/,source /etc/profile生效;如果只需要临时生效,则在命令行执行export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/data/mysql/base/lib/即可
复制
sysbench 使用
测试范围
- cpu性能测试【找范围内最大素数{时间越短越好}】
- 线程调度【线程并发执行,循环响应信号量花费的时间{越少越好}】
- 互斥锁【并发线程同时申请互斥锁循环一定次数花费的时间{越少越好}】
- 内存【以不同块大小传输一定数量的数据吞吐量大小{越大越好}】
- IO【不同场景下IOPS{越大越好}】
测试数据准备
磁盘吞吐量测试
sysbench --test=fileio --file-num=16 --file-total-size=5G prepare
复制
准备oltp测试数据
sysbench --mysql_host=127.0.0.1 --mysql-port=3307 --mysql-user=root --mysql-password=xxxx --mysql-db=sbtest /usr/local/sysbench/share/sysbench/oltp_read_write.lua --table_size=1000000 --tables=10 --threads=64 --time=600 --histogram=on --db-ps-mode=disable --auto_inc=off --report-interval=3 --percentile=95 --skip_trx=on --mysql-ignore-errors=6002,6004,4012,2013,4016,1062 --create_secondary=off prepare
复制
开始测试
1、cpu性能测试 执行命令 sysbench --test=cpu --cpu-max-prime=20000 run 进行CPU测试 cpu测试主要是进行素数的加法运算 2、线程测试 sysbench --test=threads --num-threads=500 --thread-yields=100 --thread-locks=4 run 如下图 (发送500次/个测试线程请求,每次/个线程请求产生/生成100个数量,每个线程的锁数量为4) 3、磁盘IO性能测试 测试IO:--num-threads 开启的线程 --file-total-size 总的文件大小 (1)prepare阶段,生成需要的测试文件,完成后会在当前目录下生成很多小文件。 sysbench --test=fileio --num-threads=16 --file-total-size=2G --file-test-mode=rndrw prepare sysbench fileio --threads=16 --file-total-size=2G --file-test-mode=rndrw prepare (2)run阶段 sysbench --test=fileio --num-threads=20 --file-total-size=2G --file-test-mode=rndrw run (3)清理测试时生成的文件 sysbench --test=fileio --num-threads=20 --file-total-size=2G --file-test-mode=rndrw cleanup 上述参数指定了最大创建16个线程,创建的文件总大小为2G,文件读写模式为随机读。 4、内存测试 sysbench --test=memory --memory-block-size=8k --memory-total-size=4G run 上述参数指定了本次测试整个过程是在内存中传输 4G 的数据量,每个 block 大小为 8K 5、测试mutex sysbench –test=mutex –num-threads=100 –mutex-num=1000 –mutex-locks=100000 –mutex-loops=10000 run 6、测试OLTP mysql> create database sbtest charset utf8mb4; #建表,造数据 sysbench --mysql_host=127.0.0.1 --mysql-port=3307 --mysql-user=root --mysql-password=xxxx --mysql-db=sbtest /app/sysbench/share/sysbench/oltp_read_write.lua --table_size=1000000 --tables=10 --threads=64 --time=600 --histogram=on --db-ps-mode=disable --auto_inc=off --report-interval=3 --percentile=95 --skip_trx=on --mysql-ignore-errors=6002,6004,4012,2013,4016,1062 --create_secondary=off prepare # 运行压测程序 sysbench --mysql_host=127.0.0.1 --mysql-port=3307 --mysql-user=root --mysql-password=xxxx --mysql-db=sbtest /app/sysbench/share/sysbench/oltp_read_write.lua --table_size=1000000 --tables=10 --threads=64 --time=600 --histogram=on --db-ps-mode=disable --auto_inc=off --report-interval=3 --percentile=95 --skip_trx=on --mysql-ignore-errors=6002,6004,4012,2013,4016,1062 --create_secondary=off run # 执行清理工作 sysbench --mysql_host=127.0.0.1 --mysql-port=3307 --mysql-user=root --mysql-password=xxxx --mysql-db=sbtest /app/sysbench/share/sysbench/oltp_read_write.lua --table_size=1000000 --tables=10 --threads=64 --time=600 --histogram=on --db-ps-mode=disable --auto_inc=off --report-interval=3 --percentile=95 --skip_trx=on --mysql-ignore-errors=6002,6004,4012,2013,4016,1062 --create_secondary=off cleanup
复制
Uproxy读写分离测试所需用到命令
## 非事物自动读写 使用sysbench压力脚本制造读写请求,修改请求数max-requests=20 sysbench --test=/mysql/sysbench-0.5/sysbench/tests/db/oltp_no_trx_select.lua --num-threads=4 --oltp-table-size=10000000 --mysql-user=dadi --mysql-host=10.1.12.145 --mysql-port=13306 --mysql-password=dadi --mysql-db=dadi --max-requests=20 run ## 事物(读写) sysbench --test=/mysql/sysbench-0.5/sysbench/tests/db/oltp.lua --num-threads=4 --oltp-table-size=10000000 --mysql-user=dadi --mysql-host=10.1.12.145 --mysql-port=13306 --mysql-password=dadi --mysql-db=dadi --max-requests=20 run
复制
注意
- 当sysbench压测到指定参数 --max-time=30 所指定的时间后,sysbench无法中断测试(该场景常见在Mycat中);
56s] threads: 4, tps: 0.00, reads: 0.00, writes: 0.00, response time: 0.00ms (95%), errors: 4588.85, reconnects: 0.00 [ 58s] threads: 4, tps: 0.00, reads: 0.00, writes: 0.00, response time: 0.00ms (95%), errors: 4197.04, reconnects: 0.00 [ 60s] threads: 4, tps: 0.00, reads: 0.00, writes: 0.00, response time: 0.00ms (95%), errors: 4278.51, reconnects: 0.00 [ 62s] threads: 4, tps: 0.00, reads: 0.00, writes: 0.00, response time: 0.00ms (95%), errors: 4477.30, reconnects: 0.00 [ 64s] threads: 4, tps: 0.00, reads: 0.00, writes: 0.00, response time: 0.00ms (95%), errors: 4301.12, reconnects: 0.00 [ 66s] threads: 4, tps: 0.00, reads: 0.00, writes: 0.00, response time: 0.00ms (95%), errors: 4595.94, reconnects: 0.00 [ 68s] threads: 4, tps: 0.00, reads: 0.00, writes: 0.00, response time: 0.00ms (95%), errors: 4306.31, reconnects: 0.00
复制
- 解决办法:
添加参数 --forced-shutdown=3
--forced-shutdown=STRING amount of time to wait after --max-time before forcing shutdown [off]
- 测试过程中遇到死锁等错误
Ignoring error 1003 Transaction error, need to rollback. errno:1213 Deadlock found when trying to get lock; try restarting transaction
复制
- 解决办法
添加参数 --mysql-ignore-errors=1203,1213,1003 绕过
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。
评论
您好,您的文章已入选墨力原创作者计划合格奖,10墨值奖励已经到账请查收!
❤️我们还会实时派发您的流量收益。
2年前

评论
相关阅读
2025年4月中国数据库流行度排行榜:OB高分复登顶,崖山稳驭撼十强
墨天轮编辑部
1129次阅读
2025-04-09 15:33:27
【DBA坦白局】第一期:在小城市和一线城市做DBA,是“躺”还是“卷”?
墨天轮编辑部
1059次阅读
2025-04-10 14:17:22
Oracle RAC ASM 磁盘组满了,无法扩容怎么在线处理?
Lucifer三思而后行
966次阅读
2025-03-17 11:33:53
Oracle Concepts(Oracle 19c):07 SQL
Ryan Bai
946次阅读
2025-04-09 10:57:11
2025年3月国产数据库大事记
墨天轮编辑部
675次阅读
2025-04-03 15:21:16
MySQL8.0统计信息总结
闫建(Rock Yan)
579次阅读
2025-03-17 16:04:03
Oracle数据库常用的78个脚本,速来下载!
陈举超
568次阅读
2025-03-27 12:27:50
2025年3月国产数据库中标情况一览:TDSQL大单622万、GaussDB大单581万……
通讯员
484次阅读
2025-04-10 15:35:48
东方通 TongWeb 中间件入门指南: 轻松掌握从部署到认证
shunwah
473次阅读
2025-03-19 15:09:52
Oracle DBA 高效运维指南:高频实用 SQL 大全
Lucifer三思而后行
451次阅读
2025-03-28 21:52:03