zoukankan      html  css  js  c++  java
  • 使用sysbench 进行msyql oltp压力测试

    安装参考:
    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 |
    +-------------------------------------------+
    1 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=30000 --mysql-table-engine=innodb --oltp-tables-count=20 --mysql-user=username --mysql-password=mysql_password --mysql-port=3306 --mysql-host=127.0.0.1 --max-requests=0 --time=30 --report-interval=1 --threads=10 --oltp-point-selects=1 --oltp-simple-ranges=0 --oltp_sum_ranges=0 --oltp_order_ranges=0 --oltp_distinct_ranges=0 --oltp-read-only=on prepare
    
    第二:运行工作 ,按照秒每秒输出实时的参数
    sysbench /usr/local/share/sysbench/tests/include/oltp_legacy/oltp.lua --oltp-table-size=30000 --mysql-table-engine=innodb --oltp-tables-count=20 --mysql-user=username --mysql-password=mysql_password --mysql-port=3306 --mysql-host=127.0.0.1 --max-requests=0 --time=30 --report-interval=1 --threads=10 --oltp-point-selects=1 --oltp-simple-ranges=0 --oltp_sum_ranges=0 --oltp_order_ranges=0 --oltp_distinct_ranges=0 --oltp-read-only=on run
    
    第三:清理工作:逐个drop掉sbtest的测试表
    
    sysbench /usr/local/share/sysbench/tests/include/oltp_legacy/oltp.lua --oltp-table-size=30000 --mysql-table-engine=innodb --oltp-tables-count=20 --mysql-user=username --mysql-password=mysql_password --mysql-port=3306 --mysql-host=127.0.0.1 --max-requests=0 --time=30 --report-interval=1 --threads=10 --oltp-point-selects=1 --oltp-simple-ranges=0 --oltp_sum_ranges=0 --oltp_order_ranges=0 --oltp_distinct_ranges=0 --oltp-read-only=on cleanup

  • 相关阅读:
    SpringMVC开发环境搭建
    SpringMVCRestful
    SpringMVC源码执行流程
    SpringMVC域对象数据输出
    SpringMVC请求参数
    Object类常用方法
    五大浏览器
    jinja2的学习之路
    嚣张过后之解决问题篇(无果)
    嚣张狂妄的经历之二(应聘infosys的teamleader)
  • 原文地址:https://www.cnblogs.com/netsa/p/7454339.html
Copyright © 2011-2022 走看看