#下载sysbench工具
[root@localhost bin]# curl -s https://packagecloud.io/install/repositories/akopytov/sysbench/script.rpm.sh | sudo bash
#安装sysbench工具
[root@localhost bin]# sudo yum -y install sysbench
#查看安装后的版本号
[root@localhost bin]# sysbench --version
[root@localhost bin]# sysbench --db-driver=mysql --time=300 --threads=10 --report-interval=1 --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=test --mysql-password=123456 --mysql-db=test_db --tables=20 --table_size=1000000 oltp_read_write --db-ps-mode=disable prepare
命令行中的参数说明:
--db-driver=mysql:代表数据库驱动
--time=300:这个就是说连续访问300秒
--threads=10:这个就是说用10个线程模拟并发访问
--report-interval=1:这个就是说每隔1秒输出一下压测情况
--mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=test --mysql-password=123456:数据库的用户和密码等信息
--mysql-db=test_db --tables=20 --table_size=1000000:这一串的意思,就是说在test_db这个库里,构造20个测试表,每个测试表里构造100万条测试数据,测试表的名字会是类似于sbtest1,sbtest2这个样子的
oltp_read_write:这个就是说,执行oltp数据库的读写测试
--db-ps-mode=disable:这个就是禁止ps模式
最后有一个prepare,意思是参照这个命令的设置去构造出来我们需要的数据库里的数据,他会自动创建20个测试表,每个表里创建100万条测试数据,所以这个工具是非常的方便的。
下面是执行过程中的输出信息:
[root@localhost bin]# sysbench --db-driver=mysql --time=300 --threads=10 --report-interval=1 --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=test --mysql-password=123456 --mysql-db=test_db --tables=20 --table_size=1000000 oltp_read_write --db-ps-mode=disable prepare
sysbench 1.0.20 (using bundled LuaJIT 2.1.0-beta2)
Initializing worker threads...
Creating table 'sbtest1'...
Creating table 'sbtest2'...
Creating table 'sbtest5'...
Creating table 'sbtest3'...
Creating table 'sbtest6'...
Creating table 'sbtest4'...
Creating table 'sbtest9'...
Creating table 'sbtest8'...
Creating table 'sbtest7'...
Creating table 'sbtest10'...
Inserting 1000000 records into 'sbtest6'
Inserting 1000000 records into 'sbtest3'
Inserting 1000000 records into 'sbtest5'
Inserting 1000000 records into 'sbtest7'
Inserting 1000000 records into 'sbtest8'
Inserting 1000000 records into 'sbtest9'
Inserting 1000000 records into 'sbtest10'
Inserting 1000000 records into 'sbtest2'
Inserting 1000000 records into 'sbtest1'
Inserting 1000000 records into 'sbtest4'
Creating a secondary index on 'sbtest5'...
Creating a secondary index on 'sbtest3'...
Creating a secondary index on 'sbtest10'...
Creating a secondary index on 'sbtest4'...
Creating a secondary index on 'sbtest8'...
Creating a secondary index on 'sbtest9'...
Creating a secondary index on 'sbtest1'...
Creating a secondary index on 'sbtest6'...
Creating a secondary index on 'sbtest2'...
Creating a secondary index on 'sbtest7'...
Creating table 'sbtest15'...
Inserting 1000000 records into 'sbtest15'
Creating table 'sbtest13'...
Inserting 1000000 records into 'sbtest13'
Creating table 'sbtest20'...
Creating table 'sbtest18'...
Creating table 'sbtest11'...
Creating table 'sbtest14'...
Inserting 1000000 records into 'sbtest20'
Inserting 1000000 records into 'sbtest18'
Inserting 1000000 records into 'sbtest11'
Inserting 1000000 records into 'sbtest14'
Creating table 'sbtest19'...
Inserting 1000000 records into 'sbtest19'
Creating table 'sbtest12'...
Creating table 'sbtest16'...
Inserting 1000000 records into 'sbtest12'
Inserting 1000000 records into 'sbtest16'
Creating table 'sbtest17'...
Inserting 1000000 records into 'sbtest17'
Creating a secondary index on 'sbtest15'...
Creating a secondary index on 'sbtest14'...
Creating a secondary index on 'sbtest19'...
Creating a secondary index on 'sbtest20'...
Creating a secondary index on 'sbtest17'...
Creating a secondary index on 'sbtest13'...
Creating a secondary index on 'sbtest11'...
Creating a secondary index on 'sbtest18'...
Creating a secondary index on 'sbtest16'...
Creating a secondary index on 'sbtest12'...
数据库读写性能测试,将执行指令最后的prepare修改成run:
[root@localhost bin]# sysbench --db-driver=mysql --time=300 --threads=10 --report-interval=1 --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=test --mysql-password=123456 --mysql-db=test_db --tables=20 --table_size=1000000 oltp_read_write --db-ps-mode=disable run
下面是截取的执行100秒,200秒,300秒的数据。
[ 100s ] thds: 10 tps: 151.70 qps: 2996.03 (r/w/o: 2091.83/600.80/303.40) lat (ms,95%): 97.55 err/s: 0.00 reconn/s: 0.00
[ 200s ] thds: 10 tps: 131.15 qps: 2644.08 (r/w/o: 1853.16/528.62/262.31) lat (ms,95%): 112.67 err/s: 0.00 reconn/s: 0.00
[ 300s ] thds: 10 tps: 151.05 qps: 3021.04 (r/w/o: 2118.73/600.21/302.10) lat (ms,95%): 95.81 err/s: 0.00 reconn/s: 0.00
对表中的数据进行说明,以第一条数据做解释描述:
thds: 10,这个意思就是有10个线程在压测
tps: 151.70,这个意思就是每秒执行了151.70个事务
qps: 2996.03,这个意思就是每秒可以执行2996.03个请求
(r/w/o: 2091.83/600.80/303.40),这个意思就是说,在每秒2996.03个请求中,有2091.83个请求是读请求,600.80个请求是写请求,303.40个请求是其他的请求,就是对QPS进行了拆解
lat (ms, 95%): 97.55,这个意思就是说,95%的请求的延迟都在 97.55毫秒以下
err/s: 0.00 reconn/s: 0.00,这两个的意思就是说,每秒有0个请求是失败的,发生了0次网络重连
下面是执行完成后控制台输出的数据:
SQL statistics:
queries performed:
read: 584150 // 这就是说在300s的压测期间执行了584150次的读请求
write: 166900 // 这就是说在300s的压测期间执行了166900次的写请求
other: 83450 // 这就是说在300s的压测期间执行了83450次其他请求
total: 834500 // 这就是说在300s的压测期间执行了834500次总的请求
transactions: 41725 (139.06 per sec.) //共执行了41725次事务 平均1秒执行139.06次事务
queries: 834500 (2781.11 per sec.)//共执行834500次查询 平均每秒2781.11次
ignored errors: 0 (0.00 per sec.)
reconnects: 0 (0.00 per sec.)
General statistics:
total time: 300.0585s
total number of events: 41725
Latency (ms):
min: 8.56 //请求中延迟最小的是8.56ms
avg: 71.90 //请求中延迟平均的是71.90ms
max: 729.21 //请求中延迟最大的是729.21ms
95th percentile: 112.67 //95%的请求中延迟在112.67ms以内124
sum: 3000139.42
Threads fairness:
events (avg/stddev): 4172.5000/7.20
execution time (avg/stddev): 300.0139/0.02
sysbench --db-driver=mysql --time=300 --threads=10 --report-interval=1 --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=test --mysql-password=123456 --mysql-db=test_db --tables=20 --table_size=1000000 oltp_read_only --db-ps-mode=disable run
sysbench --db-driver=mysql --time=300 --threads=10 --report-interval=1 --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=test --mysql-password=123456 --mysql-db=test_db --tables=20 --table_size=1000000 oltp_delete --db-ps-mode=disable run
sysbench --db-driver=mysql --time=300 --threads=10 --report-interval=1 --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=test --mysql-password=123456 --mysql-db=test_db --tables=20 --table_size=1000000 oltp_update_index --db-ps-mode=disable run
sysbench --db-driver=mysql --time=300 --threads=10 --report-interval=1 --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=test --mysql-password=123456 --mysql-db=test_db --tables=20 --table_size=1000000 oltp_update_non_index --db-ps-mode=disable run
sysbench --db-driver=mysql --time=300 --threads=10 --report-interval=1 --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=test --mysql-password=123456 --mysql-db=test_db --tables=20 --table_size=1000000 oltp_insert --db-ps-mode=disable run
sysbench --db-driver=mysql --time=300 --threads=10 --report-interval=1 --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=test --mysql-password=123456 --mysql-db=test_db --tables=20 --table_size=1000000 oltp_write_only --db-ps-mode=disable run
sysbench --db-driver=mysql --time=300 --threads=10 --report-interval=1 --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=test --mysql-password=123456 --mysql-db=test_db --tables=20 --table_size=1000000 oltp_read_write --db-ps-mode=disable cleanup
[root@localhost bin]# sysbench --db-driver=mysql --time=300 --threads=10 --report-interval=1 --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=test --mysql-password=123456 --mysql-db=test_db --tables=20 --table_size=1000000 oltp_read_write --db-ps-mode=disable cleanup
sysbench 1.0.20 (using bundled LuaJIT 2.1.0-beta2)
Dropping table 'sbtest1'...
Dropping table 'sbtest2'...
Dropping table 'sbtest3'...
Dropping table 'sbtest4'...
Dropping table 'sbtest5'...
Dropping table 'sbtest6'...
Dropping table 'sbtest7'...
Dropping table 'sbtest8'...
Dropping table 'sbtest9'...
Dropping table 'sbtest10'...
Dropping table 'sbtest11'...
Dropping table 'sbtest12'...
Dropping table 'sbtest13'...
Dropping table 'sbtest14'...
Dropping table 'sbtest15'...
Dropping table 'sbtest16'...
Dropping table 'sbtest17'...
Dropping table 'sbtest18'...
Dropping table 'sbtest19'...
Dropping table 'sbtest20'...