上一篇已经有sysbench的安装教程了,补充一下 在使用sysbench之前需要安装libtool,automake autoconf,mysql。


接下来详细介绍 用sysbench oltp基准测试 线下TiDB


1、测试准备: 10张表 每个表填充10W条数据 最大请求时间120s


#-test=tests/db/oltp.lua 表示调用 tests/db/oltp.lua 脚本进行 oltp 模式测试
#--oltp_tables_count=10 表示会生成 10 个测试表
#--oltp-table-size=100000 表示每个测试表填充数据量为 100000 
#--rand-init=on 表示每个测试表都是用随机数据来填充的
#-num-threads=8 表示发起 8个并发连接
#--oltp-read-only=off 表示不要进行只读测试,也就是会采用读写混合模式测试
#--report-interval=10 表示每10秒输出一次测试进度报告
#--rand-type=uniform 表示随机类型为固定模式,其他几个可选随机模式:uniform(固定),gaussian(高斯),special(特定的),pareto(帕累托)
#--max-time=120 表示最大执行时长为 120秒
#--max-requests=0 表示总请求数为 0,因为上面已经定义了总执行时长,所以总请求数可以设定为 0;也可以只设定总请求数,不设定最大执行时长

#--percentile=99 表示设定采样比例,默认是 95%,即丢弃1%的长请求,在剩余的99%里取最大值


首先创建你的数据库dbName,然后执行:


sysbench --test=oltp --mysql-db=你的dbName --db-driver=mysql --mysql-host=你的url --mysql-port=你的端口 \
 --mysql-user=你的用户 --mysql-password=你的密码 \
 --oltp-num-tables=10 --oltp-table-size=100000 --oltp-test-mode=complex  --report-interval=10 prepare >> ./log/sysbench_oltp_prepare_30t.log


这边建了10张表,每张表100000的数据,并输出日志。


然后开始测试:


sysbench --test=oltp --mysql-db=你的dbName --db-driver=mysql --mysql-host=你的url --mysql-port=你的端口 \
 --mysql-user=你的用户 --mysql-password=你的密码 \
 --oltp-num-tables=10 --oltp-table-size=100000 --oltp-test-mode=complex --num-threads=128 --max-time=120 --report-interval=10 run >> ./log/sysbench_oltp_run_30t.log


max-time最大执行时间120s


num-threads线程数128


report-interval日志输出间隔10s


测试结果报告:


sysbench 0.4.12.10:  multi-threaded system evaluation benchmark


Running the test with following options:
Number of threads: 128
Report intermediate results every 10 second(s)
Random number generator seed is 0 and will be ignored




Doing OLTP test.
Running mixed OLTP test
Using Special distribution (12 iterations,  1 pct of values are returned in 75 pct cases)
Using "BEGIN" for starting transactions
Using auto_inc on the id column
Maximum number of requests for OLTP test is limited to 10000
Using 10 test tables

Threads started!



-- 每10秒钟报告一次测试结果,tps、每秒读、每秒写、95%以上的响应时长统计

[  10s] Intermediate results: 128 threads, tps: 227.025468, reads/s: 3178.356546, writes/s: 1135.127338 response time: 909.996224ms (95%)

[  20s] Intermediate results: 128 threads, tps: 259.560235, reads/s: 3633.843295, writes/s: 1297.801177 response time: 705.145084ms (95%)
[  30s] Intermediate results: 128 threads, tps: 287.042827, reads/s: 4018.599575, writes/s: 1435.214134 response time: 572.357762ms (95%)
Done.


OLTP test statistics:
    queries performed:

        read:                            140028 --读总数

        write:                           50010 --写总数

        other:                           20004 --其他操作(CURD之外的操作,例如COMMIT)

        total:                           210042 --全部总数

    transactions:                        10002  (263.58 per sec.) --总事务数(每秒事务数)

    deadlocks:                           0      (0.00 per sec.) --死锁数

    read/write requests:                 190038 (5008.09 per sec.) --读写总数(每秒读写次数)

    other operations:                    20004  (527.17 per sec.) --其他操作总数(每秒其他操作次数)



General statistics:

    total time:                          37.9462s --总耗时

    total number of events:              10002 --共发生的事务数

    total time taken by event execution: 4839.2554 --所有事务时间相加(不考虑并行)
    response time:
         min:                                224.48ms --最小响应时间
         avg:                                483.83ms --平均响应时间
         max:                               1315.39ms --最大响应时间
         approx.  95 percentile:             694.46ms --超过95%平均耗时

Threads fairness:

    events (avg/stddev):           78.1406/6.65 --总处理事件数/标准偏差

    execution time (avg/stddev):   37.8067/0.09 --总执行时间/标准偏差


最后可以修改线程数num-threads 来测试,也可以修改表的数量和每张表的数据量、测试时常等 来进一步的测试。

Logo

更多推荐