首页 技术 正文
技术 2022年11月9日
0 收藏 823 点赞 2,331 浏览 3500 个字
安装参考:
https://github.com/akopytov/sysbench#linux
#参数说明

需要说明的选项:

  • mysql-db=dbtest1a:测试使用的目标数据库,这个库名要事先创建

  • --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

  • --rand-init=on:是否随机初始化数据,如果不随机化那么初始好的数据每行内容除了主键不同外其他完全相同

  • --num-threads=12: 并发线程数,可以理解为模拟的客户端并发连接数

  • --report-interval=10:表示每10s输出一次测试进度报告

  • --max-requests=0:压力测试产生请求的总数,如果以下面的max-time来记,这个值设为0

  • --max-time=120:压力测试的持续时间,这里是2分钟。

注意,针对不同的选项取值就会有不同的子选项。比如oltp-dist-type=special,就有比如oltp-dist-pct=1oltp-dist-res=50两个子选项,代表有50%的查询落在1%的行(即热点数据)上,另外50%均匀的(sample uniformly)落在另外99%的记录行上。

再比如oltp-test-mode=nontrx时, 就可以有oltp-nontrx-mode,可选值有select(默认), update_key, update_nokey, insert, delete,代表非事务式模式下使用的测试sql类型。

以上代表的是一个只读的例子,可以把num-threads依次递增(16,36,72,128,256,512),或者调整my.cnf参数,比较效果。另外需要注意的是,大部分mysql中间件对事务的处理,默认都是把sql发到主库执行,所以只读测试需要加上oltp-skip-trx=on来跳过测试中的显式事务。

ps1: 只读测试也可以使用share/tests/db/select.lua进行,但只是简单的point select。
ps2: 我在用sysbench压的时候,在mysql后端会话里有时看到大量的query cache lock,如果使用的是uniform取样,最好把查询缓存关掉。当然如果是做两组性能对比压测,因为都受这个因素影响,关心也不大。

#建立测试数据库,这个sbtest是固定的,必须建立这个数据库
a)创建数据库:
mysqladmin create sbtest -uroot –p
或者
SQL>create database sbtest
b)增加权限:
grant usage on . to 'sbtest'@'%' identified by password '*2AFD99E79E4AA23DE141540F4179F64FFB3AC521';
其中密码通过如下命令获取:
select password('sbtest');
+-------------------------------------------+
| password('sbtest') |
+-------------------------------------------+
| 2AFD99E79E4AA23DE141540F4179F64FFB3AC521 |
+-------------------------------------------+
row in set (0.00 sec)
c)增加权限:
GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP,ALTER,INDEX ON sbtest.TO 'sbtest'@"%";
grant all privileges on . to 'sbtest'@'%';
flush privileges;
或者简单粗暴:
create user 'sbtest'@'127.0.0.1' identified by 'sbtest';
grant all privileges on . to
flush privileges; 测试三步骤:第一:准备工作 创建表和插入数据
sysbench /usr/local/share/sysbench/tests/include/oltp_legacy/oltp.lua --oltp-table-size= --mysql-table-engine=innodb --oltp-tables-count= --mysql-user=username --mysql-password=mysql_password --mysql-port= --mysql-host=127.0.0.1 --max-requests= --time= --report-interval= --threads= --oltp-point-selects= --oltp-simple-ranges= --oltp_sum_ranges= --oltp_order_ranges= --oltp_distinct_ranges= --oltp-read-only=on prepare第二:运行工作 ,按照秒每秒输出实时的参数
sysbench /usr/local/share/sysbench/tests/include/oltp_legacy/oltp.lua --oltp-table-size= --mysql-table-engine=innodb --oltp-tables-count= --mysql-user=username --mysql-password=mysql_password --mysql-port= --mysql-host=127.0.0.1 --max-requests= --time= --report-interval= --threads= --oltp-point-selects= --oltp-simple-ranges= --oltp_sum_ranges= --oltp_order_ranges= --oltp_distinct_ranges= --oltp-read-only=on run第三:清理工作:逐个drop掉sbtest的测试表sysbench /usr/local/share/sysbench/tests/include/oltp_legacy/oltp.lua --oltp-table-size= --mysql-table-engine=innodb --oltp-tables-count= --mysql-user=username --mysql-password=mysql_password --mysql-port= --mysql-host=127.0.0.1 --max-requests= --time= --report-interval= --threads= --oltp-point-selects= --oltp-simple-ranges= --oltp_sum_ranges= --oltp_order_ranges= --oltp_distinct_ranges= --oltp-read-only=on cleanup
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,492
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,907
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,740
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,494
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,132
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,295