zoukankan      html  css  js  c++  java
  • sysbench 压测工具

    参考:

    https://yq.aliyun.com/articles/66651

    下载sysbench:

    http://github.com/akopytov/sysbench

    sysbench文档:

    http://github.com/akopytov/sysbench

    安装:

    1)源码安装:

    build requirements:

    1.ubuntu:

    apt -y install make automake libtool pkg-config libaio-dev

    # For MySQL support

    apt -y install libmysqlclient-dev libssl-dev

    # For PostgreSQL support

    apt install libpq-dev

    2.centos:

    yum -y install make automake libtool pkgconfig libaio-devel
    # For MySQL support, replace with mysql-devel on RHEL/CentOS 5
    yum -y install mariadb-devel openssl-devel
    # For PostgreSQL support
    yum -y install postgresql-devel

    build and install:

    ./autogen.sh
    # Add --with-pgsql to build with PostgreSQL support
    ./configure
    make -j
    make install

    2)二进制包安装:

    1.ubuntu:

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

    2.centos:

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

    测试:

    1)测试cpu:sysbench --test=cpu --cpu-max-prime=2000 run

    2) 测试线程:sysbench --test=threads --num-threads=500 --thread-yields=100 --thread-locks=4 run

    3) 测试IO:

    准备

    sysbench --test=fileio --num-threads=16 --file-total-size=2G --file-test-mode=rndrw prepare

    测试                

    sysbench --test=fileio --num-threads=16 --file-total-size=2G --file-test-mode=rndrw run

    清理

    sysbench --test=fileio --num-threads=20 --file-total-size=2G --file-test-mode=rndrw cleanup

    4)测试内存:sysbench --test=memory --memory-block-size=8k --memory-total-size=1G run

    5)测试oltp:

    1.准备阶段,生成需要测试的表(测试生成10个表,每个表5000000条数据)

    sysbench --mysql-host=localhost --mysql-port=3306 --mysql-user=root --mysql-password=yourpassword  --test=tests/db/oltp.lua(根据具体位置填写) --oltp_tables_count=10 --oltp-table-size=5000000 --rand-init=on prepare

    参数详解:

    --test=tests/db/oltp.lua 表示调用 tests/db/oltp.lua 脚本进行 oltp 模式测试
    --oltp_tables_count=10 表示会生成 10 个测试表
    --oltp-table-size=5000000 表示每个测试表填充数据量为 5000000 
    --rand-init=on 表示每个测试表都是用随机数据来填充的
    如果在本机,也可以使用 –mysql-socket 指定 socket 文件来连接。加载测试数据时长视数据量而定,若过程比较久需要稍加耐心等待。
    真实测试场景中,数据表建议不低于10个,单表数据量不低于500万行,当然了,要视服务器硬件配置而定。如果是配备了SSD或者PCIE SSD这种高IOPS设备的话,则建议单表数据量最少不低于1亿行。

    2.oltp测试:

    此次测试启动了256个线程,10个测试表,每个表中灌入500W条数据,测试时间1个小时

    ./sysbench --mysql-host=localhost --mysql-port=3306 --mysql-user=root --mysql-password=yourpassword --test=tests/db/oltp.lua --oltp_tables_count=10 --oltp-table-size=5000000 --num-threads=256 --oltp-read-only=off --report-interval=10 --rand-type=uniform --max-time=3600  --max-requests=1000000 --percentile=99 run >> ./log/sysbench_oltpX_256_20160403.log

    几个选项稍微解释下
    --num-threads=8 表示发起 8个并发连接
    --oltp-read-only=off 表示不要进行只读测试,也就是会采用读写混合模式测试
    --report-interval=10 表示每10秒输出一次测试进度报告
    --rand-type=uniform 表示随机类型为固定模式,其他几个可选随机模式:uniform(固定),gaussian(高斯),special(特定的),pareto(帕累托)
    --max-time=3600 表示最大执行时长为 3600秒

    --oltp-test-mode 执行模式,这里是非事务式的。可选值有simple,complex,nontrx。默认是complex

    --max-requests=0 表示总请求数为 0,因为上面已经定义了总执行时长,所以总请求数可以设定为 0;也可以只设定总请求数,不设定最大执行时长

    --percentile=99 表示设定采样比例,默认是 95%,即丢弃1%的长请求,在剩余的99%里取最大值
    即:模拟 对10个表并发OLTP测试,每个表1000万行记录,持续压测时间为 1小时。 

    测试结果:

    sysbench 0.5:  multi-threaded system evaluation benchmark
     
    Running the test with following options:
    Number of threads: 256
    Report intermediate results every 10 second(s)
    Random number generator seed is 0 and will be ignored
     
    -- 线程启动
    Threads started!
     
    -- 每10秒钟报告一次测试结果,tps、每秒读、每秒写、99%以上的响应时长统计
    [  10s] threads: 256, tps: 524.19, reads/s: 7697.05, writes/s: 2143.56, response time: 1879.46ms (99%)
    [  20s] threads: 256, tps: 96.50, reads/s: 1351.01, writes/s: 373.30, response time: 9853.49ms (99%)
    [  30s] threads: 256, tps: 235.50, reads/s: 3297.01, writes/s: 946.90, response time: 2150.47ms (99%)
    [  40s] threads: 256, tps: 115.50, reads/s: 1617.00, writes/s: 491.40, response time: 4562.75ms (99%)
    [  50s] threads: 256, tps: 262.10, reads/s: 3669.41, writes/s: 1016.10, response time: 2049.90ms (99%)
    [  60s] threads: 256, tps: 121.50, reads/s: 1701.00, writes/s: 499.10, response time: 3666.03ms (99%)
    [  70s] threads: 256, tps: 201.40, reads/s: 2735.10, writes/s: 769.50, response time: 3867.82ms (99%)
    [  80s] threads: 256, tps: 204.70, reads/s: 2950.29, writes/s: 838.10, response time: 2724.99ms (99%)
    [  90s] threads: 256, tps: 118.40, reads/s: 1657.61, writes/s: 490.00, response time: 3835.53ms (99%)
     
     
    OLTP test statistics:
        queries performed:
            read:                            8823206    -- 读总数
            write:                           2520916    -- 写总数
            other:                           1260458    -- 其他操作总数(SELECT、INSERT、UPDATE、DELETE之外的操作,例如COMMIT等)
            total:                           12604580    -- 全部总数
        transactions:                        630229 (174.94 per sec.)    -- 总事务数(每秒事务数)
        deadlocks:                           0      (0.00 per sec.)        -- 发生死锁总数
        read/write requests:                 11344122 (3148.86 per sec.)    -- 读写总数(每秒读写次数)
        other operations:                    1260458 (349.87 per sec.)    -- 其他操作总数(每秒其他操作次数)
     
     
    General statistics:        -- 一些统计结果        
        total time:                          3602.6152s    -- 总耗时
        total number of events:              630229        -- 共发生多少事务数
        total time taken by event execution: 921887.7227s    -- 所有事务耗时相加(不考虑并行因素)
        response time:                    -- 响应时间
             min:                                  6.52ms    -- 最小耗时
             avg:                               1462.78ms    -- 平均耗时
             max:                               9918.51ms    -- 最长耗时
             approx.  99 percentile:            3265.01ms    -- 超过99%平均耗时
     
     
    Threads fairness:                -- 线程的稳定性
        events (avg/stddev):           2461.8320/34.60      -- 事件(平均值/偏差)
        execution time (avg/stddev):   3601.1239/0.63    -- 执行时间(平均值/偏差)

    每轮测试完成后,都重启mysqld实例,并且用下面的方法删除系统cache,释放swap(如果用到了swap的话),甚至可以重启整个OS。

    # sync  -- 将脏数据刷新到磁盘
    # sync  -- 将脏数据刷新到磁盘
    # echo 3 > /proc/sys/vm/drop_caches  -- 清除OS Cache
    # swapoff -a && swapon -a     -- 清除OS swap缓存

    4、再次启动测试流程

    清理测试数据

    ./sysbench --mysql-host=localhost --mysql-port=3306 --mysql-user=root --mysql-password=yourpassword --test=tests/db/oltp.lua --oltp_tables_count=10 --oltp-table-size=5000000 --num-threads=256 --oltp-read-only=off --report-interval=10 --rand-type=uniform --max-time=3600  --max-requests=1000000 --percentile=99 cleanup

  • 相关阅读:
    Map 嵌套存储Map
    LinkedList;以及迭代器Iterator
    计算某字符串中大写字母、小写字母以及数字的个数
    String字符串转多种类型及多种方法的应用
    String类的构造方法
    String类(附件)
    (五)Kubernetes集群安装
    (四)Kubernetes 网络通讯方式
    (三)Kubernetes-Pod概念
    (二)Kubernetes组件说明
  • 原文地址:https://www.cnblogs.com/yangxiaochu/p/9485824.html
Copyright © 2011-2022 走看看