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'...
相关推荐
叁沐5 分钟前
MySQL 06 全局锁和表锁:给表加个字段怎么有这么多阻碍?
mysql
power 雀儿1 小时前
集群聊天服务器---MySQL数据库的建立
服务器·数据库·mysql
Edingbrugh.南空3 小时前
Flink MySQL CDC 环境配置与验证
mysql·adb·flink
BD_Marathon4 小时前
Ubuntu:Mysql服务器
服务器·mysql·ubuntu
程序猿小D5 小时前
[附源码+数据库+毕业论文]基于Spring+MyBatis+MySQL+Maven+jsp实现的电影小说网站管理系统,推荐!
java·数据库·mysql·spring·毕业设计·ssm框架·电影小说网站
羊小猪~~5 小时前
数据库学习笔记(十七)--触发器的使用
数据库·人工智能·后端·sql·深度学习·mysql·考研
叁沐6 小时前
MySQL 05 深入浅出索引(下)
mysql
陈卓4106 小时前
MySQL-主从复制&分库分表
android·mysql·adb
你都会上树?7 小时前
MySQL MVCC 详解
数据库·mysql
长征coder8 小时前
AWS MySQL 读写分离配置指南
mysql·云计算·aws