1.安装压测工具

curl -s https://packagecloud.io/install/repositories/akopytov/sysbench/script.rpm.sh | sudo bash
sudo yum -y install sysbench

2.创建测试数据库

CREATE DATABASE test_db;
CREATE USER 'test_user'@'127.0.0.1' IDENTIFIED BY 'test_user';
GRANT ALL ON test_db.* TO 'test_user'@'127.0.0.1';
flush privileges;

3.创建测试数据

sysbench --db-driver=mysql --time=30 --threads=50 --report-interval=1 --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=test_user --mysql-password=test_user --mysql-db=test_db --tables=5 --table_size=1000000 oltp_read_write --db-ps-mode=disable prepare

参数解释:
–db-driver=mysql:基于mysql的驱动去连接mysql数据库,如果是oracle,或者sqlserver,那自然就是其他的数据库的驱动了
–time=30:这个就是说连续访问30秒
–threads=50:这个就是说用50个线程模拟并发访问
–report-interval=1:这个就是说每隔1秒输出一下压测情况
–mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=test_user --mysql-password=test_user:这个是说连接到哪台机器的哪个端口上的MySQL库,他的用户名和密码是什么
–mysql-db=test_db --tables=5 --table_size=500000:这个是说在test_db这个库里,构造5个测试表,每个测试表里构造50万条测试数据
oltp_read_write:这个就是说,执行oltp数据库的读写测试
–db-ps-mode=disable:这个是禁止ps模式
prepare:意思是参照这个命令的设置去构造出来我们需要的数据库里的数据,他会自动创建5个测试表,每个表里创建50万条测试数据。
 

4. 开始测试

sysbench --db-driver=mysql --time=30 --threads=50 --report-interval=1 --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=test_user --mysql-password=test_user --mysql-db=test_db --tables=5 --table_size=500000 oltp_read_write --db-ps-mode=disable run

oltp_write_only:测试写入性能
oltp_read_write : 测试读写性能
oltp_read_only:测试只读性能
oltp_delete:测试删除性能
oltp_update_index: 测试更新索引字段性能
oltp_update_non_index: 测试更新非索引字段性能
oltp_insert: 测试插入性能
 

5.结果

read: 273602 的意思是在30s的压测期间执行了27万多次的读请求
write: 78172 的意思在压测期间执行了差不多8万次的写请求
other: 39086 的意思是在压测期间执行了差不多4万次的其他请求
total: 390860 的意思是一共执行了39万多次的请求
transactions: 19543 ( 650.89 per sec. ) 的意思是一共执行了差不多2万万个事务,每秒执行650.89多个事务
queries: 390860 (13017.74 per sec. ) 的意思是一共执行了39万多次的请求,每秒执行1万3千多请求
ignored errors: 0 (0.00 per sec.)
reconnects: 0 (0.00 per sec.)
// 下面就是说,一共执行了30s的压测,执行了差不多两万的事务
General staticstics:
total time: 30.0240s
total number of events: 19543
Latency (ms):
min: 3.80 意思是请求中延迟最小的是3.80ms
avg: 76.77 意思是所有请求平均延迟是76.77ms
max: 710.73 意思是延迟最大的请求是710.73ms
95th percentile: 262.64 意思是95%的请求延迟都在262.64 ms以内
 

6.清理测试数据

sysbench --db-driver=mysql --time=300 --threads=50 --report-interval=1 --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=test_user --mysql-password=test_user --mysql-db=test_db --tables=5 --table_size=500000 oltp_read_write --db-ps-mode=disable cleanup

 

标签: none

添加新评论