4

sysbench压测工具的使用

 1 year ago
source link: https://blog.51cto.com/u_13874232/5582905
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

sysbench压测工具的使用

精选 原创

进击的CJR 2022-08-16 16:25:40 博主文章分类:MySQL ©著作权

文章标签 mysql lua 响应时间 文章分类 MySQL 数据库 yyds干货盘点 阅读数229

sysbench 安装

curl -s https://packagecloud.io/install/repositories/akopytov/sysbench/script.rpm.sh | sudo bash
sudo yum -y install sysbench
sysbench压测工具的使用_响应时间
1. bulk_insert.lua 批量写入操作
2. oltp_delete.lua 写入和删除并行操作
3. oltp_insert.lua 纯写入操作
4. oltp_point_select.lua 只读操作,条件为唯一索引列
5. oltp_read_only.lua 只读操作,包含聚合,去重等操作
6. oltp_read_write.lua 读写混合操作,最常用的脚本
7. oltp_update_index.lua 更新操作,通过主键进行更新
8. oltp_update_non_index.lua 更新操作,不通过索引列
9. oltp_write_only.lua 纯写操作,常用脚本,包括insert update delete
10. select_random_points.lua 随机集合只读操作,常用脚本,聚集索引列的selete in操作
11. select_random_ranges.lua 随机范围只读操作,常用脚本,聚集索引列的selete between操作
Sysbench中常用的参数如下:
Sysbench中常用的参数如下:
--mysql-table-engine=innodb 表示选择测试表的存储引擎
--oltp_tables_count=10 表示会生成 10 个测试表
--oltp-table-size=100000 表示每个测试表填充数据量为 100000
--rand-init=on 表示每个测试表都是用随机数据来填充的
如果在本机,也可以使用 –mysql-socket 指定 socket 文件来连接。加载测试数据时长视数据量而定,若过程比较久需要稍加耐心等待。

--oltp-read-only=off 表示不要进行只读测试,也就是会采用读写混合模式测试
--report-interval=10 表示每10秒输出一次测试进度报告
--rand-type=uniform 表示随机类型为固定模式,其他几个可选随机模式:uniform(固定),gaussian(高斯),special(特定的),pareto(帕累托)
--max-time=120 表示最大执行时长为 120秒
--max-requests=0 表示总请求数为 0,因为上面已经定义了总执行时长,所以总请求数可以设定为 0;也可以只设定总请求数,不设定最大执行时长
--percentile=99 表示设定采样比例,默认是 95%,即丢弃1%的长请求,在剩余的99%里取最大值
--num-threads=12: 并发线程数,可以理解为模拟的客户端并发连接数

--mysql-db=sbtest:测试使用的目标数据库,这个库名要事先创建
--oltp-tables-count=10:产生表的数量
--oltp-table-size=500000:每个表产生的记录行数
--oltp-dist-type=uniform:指定随机取样类型,可选值有 uniform(均匀分布), Gaussian(高斯分布), special(空间分布)。默认是special
--oltp-read-only=off:表示不止产生只读SQL,也就是使用oltp.lua时会采用读写混合模式。默认 off,如果设置为on,则不会产生update,delete,insert的sql。
--oltp-test-mode=nontrx:执行模式,这里是非事务式的。可选值有simple,complex,nontrx。默认是complex
simple:简单查询,SELECT c FROM sbtest WHERE id=N
complex (advanced transactional):事务模式在开始和结束事务之前加上begin和commit, 一个事务里可以有多个语句,如点查询、范围查询、排序查询、更新、删除、插入等,并且为了不破坏测试表的数据,该模式下一条记录删除后会
在同一个事务里添加一条相同的记录。
nontrx (non-transactional):与simple相似,但是可以进行update/insert等操作,所以如果做连续的对比压测,你可能需要重新cleanup,prepare。
--oltp-skip-trx=[on|off]:省略begin/commit语句。默认是off
--oltp_secondary=on:将ID设置为非主键防止主键冲突。
--oltp_range_size=5: 连续取值5个,必定走到5个分片。
--mysql_table_options='dbpartition by hash(id) tbpartition by hash(id) tbpartitions 2':PolarDB-X 1.0支持拆分表,在建表的时候需要指定拆分方式。

压测准备数据

sysbench /usr/share/sysbench/oltp_read_only.lua --mysql-host=10.0.16.10 --mysql-port=3307 --mysql-user=cjr --mysql-password=cjr
--mysql-db=sysbench --db-driver=mysql --tables=100 --table-size=100000 --time=1800 --max-requests=1000000 prepare
sysbench /usr/share/sysbench/oltp_read_only.lua --mysql-host=10.0.16.10 --mysql-port=3307 --mysql-user=cjr --mysql-password=cjr --mysql-db=sysbench --db-driver=mysql --tables=100 --table-size=100000 --report-interval=1 --threads=2 --rand-type=uniform --time=1800 --max-requests=1000000
SQL statistics:
queries performed:
read: 1791048 读总数
write: 0 写总数
other: 255864 其他操作总数
total: 2046912 总操作数
transactions: 127932 (71.06 per sec.) 事务总数
queries: 2046912 (1137.00 per sec.)读写总数
ignored errors: 0 (0.00 per sec.) 忽略错误次数
reconnects: 0 (0.00 per sec.) 重连次数

General statistics:
total time: 1800.2764s 总耗时
total number of events: 127932 共发生多少事务

Latency (ms):
min: 2.78 最小响应时间
avg: 28.14 平均响应时间
max: 469.89 最大响应时间
95th percentile: 66.84 95%响应时间小于
sum: 3599701.37 总响应时间

Threads fairness:
events (avg/stddev): 63966.0000/4.00
execution time (avg/stddev): 1799.8507/0.18
  • 收藏
  • 评论
  • 分享
  • 举报

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK