Categories
linux shell

两个压测工具

前些天做的一个项目,需要mock一些场景,如系统过载,CPU飙高、IO hang,数据库连接数过多等,之前没有相关经验,于是google之,找到了一些不错的工具如sysbench,特mark之。同时也BS一下自己,如sysbench这类经典工具以前竟然没听说过。。 sysbench是通用压测工具,支持对系统负载压测。我是先查到stress后才看到sysbench的,就都记录下吧~~
工具链接:
1. Stress:http://people.seas.harvard.edu/~apw/stress/
2.Sysbench:https://github.com/akopytov/sysbench
3. mysql benchmark tools:https://dev.mysql.com/downloads/benchmarks.html
以下是我需要的几个场景
1. 系统负载压测
使用工具stress
1.1 产生cpu高
#stress –cpu 8   // spawn N workers spinning on sqrt()
1.2 产生io高
#stress –hdd 4
1.3 内存增高
#stress –vm 2 –vm-bytes 256M
或者合并执行:
#stress –cpu 8 –hdd 4 –vm 2 –vm-bytes 256M
=============================================================
2. 数据库压测
2.1 准备数据(创建5个表,每个表插入100万条数据)
#sysbench –mysql-table-engine=innodb –oltp-tables-count=5 –oltp-table-size=1000000  –max-requests=15 –max-time=300 –num-threads=16  –report-interval=10  –mysql-host=your-mysql-db-host –mysql-user=your-username  –mysql-password=your-db-password–mysql-db=your-dbname –test=/root/benchmarkTools/sysbench-1.0/sysbench/tests/db/parallel_prepare.lua prepare
2.2 进行压测 (60秒后结束)
#sysbench –mysql-host=your-mysql-db-host –mysql-user=your-username  –mysql-password=your-db-password–mysql-db=your-dbname –oltp-tables-count=5 –oltp-table-size=6000000 –num-threads=50 –max-requests=100000000 –report-interval=1 –max-time=60 –test=/root/benchmarkTools/sysbench-1.0/sysbench/tests/db/oltp.lua run
2.3 INSERT测试
#sysbench –mysql-host=your-mysql-db-host –mysql-user=your-username  –mysql-password=your-db-password–mysql-db=your-dbname –oltp-tables-count=5  –oltp-table-size=6000000 –num-threads=50 –max-requests=100000000 –report-interval=1 –max-time=20 –test=/root/benchmarkTools/sysbench-1.0/sysbench/tests/db/insert.lua run
2.4 清理
#sysbench  –mysql-host=your-mysql-db-host –mysql-user=your-username  –mysql-password=your-db-password–mysql-db=your-dbname –oltp-tables-count=5 –oltp-table-size=6000000 –num-threads=50–test=/root/benchmarkTools/sysbench-1.0/sysbench/tests/db/oltp.lua cleanup