暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

DBA必备压测工具之--sysbench

DBA札记 2021-07-22
745

   

1.github地址:https://github.com/akopytov/sysbench

2.在线安装

依赖安装:

    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

     sysbench安装(centos系统)

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

      3.用法

         sysbench [options]... [testname] [command]

        参数解释:

         testname是一个内置测试(例如文件、内存、cpu等)的可选名称,或者一个捆绑的Lua脚本的名称(例如oltp_read_only),或者一个自定义Lua脚本的路径。如果在命令行上没有指定测试名(因此也没有命令,因为在这种情况下,它将被解析为testname),或者测试名是一个短横线(“-”),那么sysbench期望Lua脚本在其标准输入上执行。

         command是一个可选参数,将由sysbench传递给内置的测试或脚本,由testname指定。命令定义了测试必须执行的动作。

        可用命令的列表取决于特定的测试。有些测试还实现了它们自己的自定义命令。有4个选项:

                 prepare                 ---准备数据

                 run                          ---测试

                 cleanup                 ---清理数据 

                  help                        ---帮助

                常见可选项列表如下:

        Option

        Description

        Default value

        --threads
        The total number of worker threads to create1
        --events
        Limit for total number of requests. 0 (the default) means no limit0
        --time
        Limit for total execution time in seconds. 0 means no limit10
        --warmup-time
        Execute events for this many seconds with statistics disabled before the actual benchmark run with statistics enabled. This is useful when you want to exclude the initial period of a benchmark run from statistics. In many benchmarks, the initial period is not representative because CPU/database/page and other caches need some time to warm up0
        --rate
        Average transactions rate. The number specifies how many events (transactions) per seconds should be executed by all threads on average. 0 (default) means unlimited rate, i.e. events are executed as fast as possible0
        --thread-init-timeout
        Wait time in seconds for worker threads to initialize30
        --thread-stack-size
        Size of stack for each thread32K
        --report-interval
        Periodically report intermediate statistics with a specified interval in seconds. Note that statistics produced by this option is per-interval rather than cumulative. 0 disables intermediate reports0
        --debug
        Print more debug infooff
        --validate
        Perform validation of test results where possibleoff
        --help
        Print help on general syntax or on a specified test, and exitoff
        --verbosity
        Verbosity level (0 - only critical messages, 5 - debug)4
        --percentile
        sysbench measures execution times for all processed requests to display statistical information like minimal, average and maximum execution time. For most benchmarks it is also useful to know a request execution time value matching some percentile (e.g. 95% percentile means we should drop 5% of the most long requests and choose the maximal value from the remaining ones). This option allows to specify a percentile rank of query execution times to count95
        --luajit-cmd
        perform a LuaJIT control command. This option is equivalent to luajit -j
        . See LuaJIT documentation for more information

        请注意,所有大小选项的数值(如该表中的——thread-stack-size)都可以通过添加相应的后缀来指定

        (K表示kilobytes, M表示megabytes, G表示gigabytes, T表示terabytes)。

        随机数的选项:

        Sysbench提供了许多算法来生成根据给定概率分布分布的随机数。下表列出了可用于控制这些算法的选项。

        Option

        Description

        Default value

        --rand-type
        random numbers distribution {uniform, gaussian, special, pareto, zipfian} to use by default. Benchmark scripts may choose to use either the default distribution, or specify it explictly, i.e. override the default.special
        --rand-seed
        seed for random number generator. When 0, the current time is used as an RNG seed.0
        --rand-spec-iter
        number of iterations for the special distribution12
        --rand-spec-pct
        percentage of the entire range where 'special' values will fall in the special distribution1
        --rand-spec-res
        percentage of 'special' values to use for the special distribution75
        --rand-pareto-h
        shape parameter for the Pareto distribution0.2
        --rand-zipfian-exp
        shape parameter (theta) for the Zipfian distribution0.8


        4. 实际测试案例

          sysbench --mysql-host=localhost --mysql-port=3306 --mysql-user=root --mysql-password=password --mysql-db=dbtest oltp_insert prepare


            sysbench --mysql-host=localhost --mysql-port=3306 --mysql-user=root 
            --mysql-password=password --time=12000 --mysql-db=dbtest oltp_insert run > test1.txt &


            ps:1.本文为sysbench 1.0.20版本,参数与老版本有区别;

                    2.其他操作系统的安装可参考文章开头地址。


            历史文章:

            MySQL参数的"双1"设置

            Docker基本介绍和常用操作命令--docker上篇

            MySQL DBA必备工具Percona Toolkit--上篇

            文章转载自DBA札记,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

            评论