mysql 批量update_mysql如何进行压力测试?

一、介绍

  • SysBench 是一款开源的、跨平台的、模块化的、多线程的性能测试工具, 可以执行 CPU/内存/线程/IO/数据库 等方面的性能测试

二、安装 sysbench

  • yum -y install sysbench
  • 安装完sysbench后,/usr/share/sysbench下对数据库压力测试的lua文件
  • lua脚本说明
7ff42be8a05cf8545365492b22776d3f.png
1、 bulk_insert.lua 批量写入操作2、 oltp_common.lua oltp公用代码3、 oltp_delete.lua 写入和删除并行操作4、 oltp_insert.lua 纯写入操作5、 oltp_point_select.lua 只读操作,条件为唯一索引列6、 oltp_read_only.lua 只读操作,包含聚合,去重等操作7、 oltp_read_write.lua 读写混合操作,最常用的脚本8、 oltp_update_index.lua 更新操作,通过主键进行更新9、 oltp_update_non_index.lua 更新操作,不通过索引列10、 oltp_write_only.lua 纯写操作,常用脚本,包括insert update delete11、 select_random_points.lua 随机集合只读操作,常用脚本,聚集索引列的selete in操作12、 select_random_ranges.lua 随机范围只读操作,常用脚本,聚集索引列的selete between操作
  • 参数说明
-–db-driver:用到的数据库类型-–mysql-host:数据库的IP-–mysql-port:数据库的端口-–mysql-socket:socket的路径-–mysql-user:数据库用户名-–mysql-password:用户密码-–mysql-db:数据库名字,默认为sysbench,需要提前创建创好-–tables:生成表的个数-–table-size:每个表的行数-–report-interval:每隔多久在屏幕打印一次信息-–time:压测时间-–threads:启动多少个线程,即模拟多少个用户
  • 帮助命令 sysbench /usr/share/sysbench/oltpreadwrite.lua help
oltp_read_write.lua options: --auto_inc[=on|off] Use AUTO_INCREMENT column as Primary Key (for MySQL), or its alternatives in other DBMS. When disabled, use client-generated IDs [on] --create_secondary[=on|off] Create a secondary index in addition to the PRIMARY KEY [on] --delete_inserts=N Number of DELETE/INSERT combinations per transaction [1] --distinct_ranges=N Number of SELECT DISTINCT queries per transaction [1] --index_updates=N Number of UPDATE index queries per transaction [1] --mysql_storage_engine=STRING Storage engine, if MySQL is used [innodb] --non_index_updates=N Number of UPDATE non-index queries per transaction [1] --order_ranges=N Number of SELECT ORDER BY queries per transaction [1] --pgsql_variant=STRING Use this PostgreSQL variant when running with the PostgreSQL driver. The only currently supported variant is 'redshift'. When enabled, create_secondary is automatically disabled, and delete_inserts is set to 0 --point_selects=N Number of point SELECT queries per transaction [10] --range_selects[=on|off] Enable/disable all range SELECT queries [on] --range_size=N Range size for range SELECT queries [100] --secondary[=on|off] Use a secondary index in place of the PRIMARY KEY [off] --simple_ranges=N Number of simple range SELECT queries per transaction [1] --skip_trx[=on|off] Don't start explicit transactions and execute all queries in the AUTOCOMMIT mode [off] --sum_ranges=N Number of SELECT SUM() queries per transaction [1] --table_size=N Number of rows per table [10000] --tables=N Number of tables [1]

数据库压力测试通常三个阶段,准备数据、压测数据、清理数据

  • 第一阶段数据准备
mysql -uroot -p123 -e "create database sbtest;" -- 创建测试数据库sysbench /usr/share/sysbench/oltp_read_write.lua --mysql-host=localhost --mysql-port=3306 --mysql-user=root --mysql-password='test' --mysql-socket=/data/mysql/mysql.sock --mysql-db=sbtest --db-driver=mysql --tables=10 --table-size=50000 --threads=4 prepare
9a7b6c3842cc4956c1b9947957d71ddc.png

登录数据库检查生成表和数据情况

d266a0005fb1226259ebe7d94a16240d.png
  • 第二阶段数据运行测试
情况1:查询sysbench /usr/share/sysbench/oltp_read_write.lua --mysql-host=localhost --mysql-port=3306 --mysql-user=root --mysql-password='test' --mysql-socket=/data/mysql/mysql.sock --mysql-db=sbtest --db-driver=mysql --tables=10 --table-size=50000 --report-interval=10 --threads=128 --time=600 ru
ea2e06a84dcbb573445e78e6860087e8.png

备注:重要指标

QPS(Query per second) 每秒查询量:21021.78

TPS(Transaction per second)每秒事务量 1052.19

情况2: 在每个查询的事物里面添加 INSERT/UPDATE/DELDETE 操作sysbench /usr/share/sysbench/oltp_read_write.lua --mysql-host=localhost --mysql-port=3306 --mysql-user=root --mysql-password='test' --mysql-socket=/data/mysql/mysql.sock --mysql-db=sbtest --db-driver=mysql --tables=10 --table-size=50000 --delete_inserts=10 --index_updates=10 --non_index_updates=10 --report-interval=10 --threads=4 --time=60 run
856af6aebe32183cfebcfbdd995e5e80.png
  • 第三阶段删除测试数据
sysbench /usr/share/sysbench/oltp_read_write.lua --mysql-host=localhost --mysql-port=3306 --mysql-user=root --mysql-password='test' --mysql-socket=/data/mysql/mysql.sock --mysql-db=sbtest --db-driver=mysql --tables=10 --table-size=50000 --delete_inserts=10 --index_updates=10 --non_index_updates=10 --report-interval=10 --threads=4 --time=60 cleanup
9d1ee4bf018c7dfb708be260f4dae2f4.png
  • 注一个错误处理(修改自己安装mysql对应socket文件)
71efe1903e875b44225fa78af1ae81eb.png
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值