sysbench在mysql中的使用

sysbench安装

[root@gip ~]# yum install epel-release -y

[root@gip ~]# yum install sysbench -y

查看sysbench的版本:

[root@gip ~]# sysbench --version
sysbench 1.1.0-df89d34

基于sysbench构造测试表和测试数据

sysbench --db-driver=mysql --time=5 --threads=10 --report-interval=1 --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=greatdb --mysql-password=greatdb --mysql-db=test_db --tables=2 --table_size=10 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=greatdb --mysql-password=greatdb:数据库的用户和密码等信息
--mysql-db=test_db --tables=2 --table_size=10:这一串的意思,就是说在test_db这个库里,构造2个测试表,每个测试表里构造10条测试数据,测试表的名字会是类似于sbtest1,sbtest2这个样子的
oltp_read_write:这个就是说,执行oltp数据库的读写测试
--db-ps-mode=disable:这个就是禁止ps模式 最后有一个prepare,意思是参照这个命令的设置去构造出来我们需要的数据库里的数据,他会自动创建20个测试表,每个表里创建100万条测试数据。

下面是命令执行后,输出的信息:

sysbench 1.1.0-df89d34 (using bundled LuaJIT 2.1.0-beta3)

Initializing worker threads...

Creating table 'sbtest1'...

Creating table 'sbtest2'...

Inserting 10 records into 'sbtest2'

Inserting 10 records into 'sbtest1'

Creating a secondary index on 'sbtest2'...

Creating a secondary index on 'sbtest1'...

查看创建的表信息:

mysql> show tables;

+-------------------+

| Tables_in_test_db |

+-------------------+

| sbtest1 |

| sbtest2 |

+-------------------+

2 rows in set (0.01 sec)

mysql> select count(*) from sbtest1;

+----------+

| count(*) |

+----------+

| 10 |

+----------+

1 row in set (0.01 sec)

数据库读写性能测试

做性能测试前,需要先创建数据

[root@localhost bin]# sysbench --db-driver=mysql --time=50 --threads=10 --report-interval=1 --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=greatdb --mysql-password=greatdb --mysql-db=test_db --tables=10 --table_size=1000 oltp_read_write --db-ps-mode=disable prepare

数据库读写性能测试,将执行指令最后的prepare 修改成run

[root@localhost bin]# sysbench --db-driver=mysql --time=50 --threads=10 --report-interval=1 --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=greatdb --mysql-password=greatdb --mysql-db=test_db --tables=10 --table_size=1000 oltp_read_write --db-ps-mode=disable run

执行run命令后数据显示:

[ 10s ] thds: 10 tps: 800.11 qps: 16012.28 (r/w/o: 11207.60/3204.46/1600.23) lat (ms,95%): 15.27 err/s: 0.00 reconn/s: 0.00
[ 40s ] thds: 10 tps: 697.26 qps: 13957.21 (r/w/o: 9771.64/2791.04/1394.52) lat (ms,95%): 13.46 err/s: 0.00 reconn/s: 0.00

对表中的数据进行说明,以第一条数据做解释描述:

​ thds: 10,这个意思就是有10个线程在压测

​ tps: 800.11,这个意思就是每秒执行了800.11个事务

​ qps: 16012.28,这个意思就是每秒可以执行2996.03个请求

​ (r/w/o: 11544.02/3298.07/1642.90),这个意思就是说,在每秒16012.28个请求中,有11544.02个请求是读请求,3298.07个请求是写请求,1642.90个请求是其他的请求,就是对QPS进行了拆解

​ lat (ms, 95%): 10.27,这个意思就是说,95%的请求的延迟都在 10.27毫秒以下

​ err/s: 0.00 reconn/s: 0.00,这两个的意思就是说,每秒有0个请求是失败的,发生了0次网络重连

下面是执行完成后控制台输出的数据:

SQL statistics:
queries performed:
read: 482034 // 这就是说在50s的压测期间执行了482034 次的读请求
write: 137724 // 这就是说在50s的压测期间执行了137724 次的写请求
other: 68862 // 这就是说在50s的压测期间执行了68862 次其他请求
total: 688620 // 这就是说在300s的压测期间执行了688620 次总的请求
transactions: 34431 (684.29 per sec.) //共执行了34431 次事务 平均1秒执行684.29 次事务
queries: 688620 (13685.79 per sec.) //共执行688620次查询 平均每秒13685.79次
ignored errors: 0 (0.00 per sec.)
reconnects: 0 (0.00 per sec.)

Throughput:
events/s (eps): 684.2895
time elapsed: 50.3164s
total number of events: 34431

Latency (ms):
min: 4.15 //请求中延迟最小的是4.15ms
avg: 14.61 //请求中延迟平均的是14.61ms
max: 499.87 //请求中延迟最大的是499.87ms
95th percentile: 13.46 //95%的请求中延迟在13.46ms以内
sum: 502991.87

Threads fairness:
events (avg/stddev): 3443.1000/21.30
execution time (avg/stddev): 50.2992/0.00

数据库读性能测试

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=10000 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=10000 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=10000 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=10000 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=10000 oltp_write_only --db-ps-mode=disable run

清除数据,将run改成cleanup,

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=10000 oltp_read_write --db-ps-mode=disable cleanup

[root@gip ~]# sysbench --db-driver=mysql --time=50 --threads=10 --report-interval=1 --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=greatdb --mysql-password=greatdb --mysql-db=test_db --tables=10 --table_size=1000 oltp_read_write --db-ps-mode=disable cleanup
sysbench 1.1.0-df89d34 (using bundled LuaJIT 2.1.0-beta3)

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'...
相关推荐
大拇指的约定2 分钟前
数据库(MySQL):使用命令从零开始在Navicat创建一个数据库及其数据表(三),单表查询
数据库·mysql·oracle
银氨溶液38 分钟前
MySql数据引擎InnoDB引起的锁问题
数据库·mysql·面试·求职
unix2linux3 小时前
Parade Series - SHA256
linux·python·mysql·shell
hefaxiang4 小时前
【MYSQL】mysql约束---自增长约束(auto_increment)
数据库·mysql
计算机学姐5 小时前
基于微信小程序的调查问卷管理系统
java·vue.js·spring boot·mysql·微信小程序·小程序·mybatis
momo小菜pa15 小时前
【MySQL 06】表的增删查改
数据库·mysql
程序员大金18 小时前
基于SpringBoot+Vue+MySQL的装修公司管理系统
vue.js·spring boot·mysql
gorgor在码农18 小时前
Mysql 索引底层数据结构和算法
数据结构·数据库·mysql
-seventy-18 小时前
SQL语句 (MySQL)
sql·mysql
一般路过糸.18 小时前
MySQL数据库——索引
数据库·mysql