zoukankan      html  css  js  c++  java
  • ubuntu 18.04使用sysbench测试MySQL性能

    首先下载安装sysbench:

    sudo apt-get install sysbench -y
    

    查看一下sysbench版本是多少:

    zifeiy@zifeiy-S1-Series:~$ sysbench --version
    sysbench 1.0.11
    

    这个版本根一些书上的比较旧的版本稍有一些参数不一样,要注意。

    在MySQL中新建一个名为testdb的database:

    mysql> CREATE DATABASE IF NOT EXISTS testdb DEFAULT CHARSET utf8 COLLATE utf8_general_ci;
    Query OK, 1 row affected, 2 warnings (0.05 sec)
    

    执行如下命令进行测试:

    sysbench /usr/share/sysbench/oltp_write_only.lua --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=root --mysql-password=password --mysql-db=testdb --db-driver=mysql --tables=10 --table_size=1000000 --report-interval=10 --threads=128 --time=120 prepare|run|cleanup
    

    也就是分三步走:

    1.准备数据

    sysbench /usr/share/sysbench/oltp_write_only.lua --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=root --mysql-password=password --mysql-db=testdb --db-driver=mysql --tables=10 --table_size=1000000 --report-interval=10 --threads=128 --time=120 prepare
    

    显示信息:

    zifeiy@zifeiy-S1-Series:~$ sysbench /usr/share/sysbench/oltp_write_only.lua --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=root --mysql-password=password --mysql-db=testdb --db-driver=mysql --tables=10 --table_size=1000000 --report-interval=10 --threads=128 --time=120 prepare
    sysbench 1.0.11 (using system LuaJIT 2.1.0-beta3)
    
    Initializing worker threads...
    
    Creating table 'sbtest1'...
    Creating table 'sbtest6'...
    Creating table 'sbtest7'...
    Creating table 'sbtest9'...
    Creating table 'sbtest2'...Creating table 'sbtest8'...
    
    Creating table 'sbtest4'...
    Creating table 'sbtest5'...
    Creating table 'sbtest10'...
    Creating table 'sbtest3'...
    Inserting 1000000 records into 'sbtest7'
    Inserting 1000000 records into 'sbtest4'
    Inserting 1000000 records into 'sbtest8'
    Inserting 1000000 records into 'sbtest2'
    Inserting 1000000 records into 'sbtest9'
    Inserting 1000000 records into 'sbtest6'
    Inserting 1000000 records into 'sbtest3'
    Inserting 1000000 records into 'sbtest10'
    Inserting 1000000 records into 'sbtest1'
    Inserting 1000000 records into 'sbtest5'
    
    Creating a secondary index on 'sbtest10'...
    Creating a secondary index on 'sbtest8'...
    Creating a secondary index on 'sbtest2'...
    Creating a secondary index on 'sbtest7'...
    Creating a secondary index on 'sbtest3'...
    Creating a secondary index on 'sbtest5'...
    Creating a secondary index on 'sbtest6'...
    Creating a secondary index on 'sbtest1'...
    Creating a secondary index on 'sbtest4'...
    Creating a secondary index on 'sbtest9'...
    

    2.运行以测试

    sysbench /usr/share/sysbench/oltp_write_only.lua --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=root --mysql-password=password --mysql-db=testdb --db-driver=mysql --tables=10 --table_size=1000000 --report-interval=10 --threads=128 --time=120 run
    

    显示信息:

    zifeiy@zifeiy-S1-Series:~$ sysbench /usr/share/sysbench/oltp_write_only.lua --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=root --mysql-password=password --mysql-db=testdb --db-driver=mysql --tables=10 --table_size=1000000 --report-interval=10 --threads=128 --time=120 run
    sysbench 1.0.11 (using system LuaJIT 2.1.0-beta3)
    
    Running the test with following options:
    Number of threads: 128
    Report intermediate results every 10 second(s)
    Initializing random number generator from current time
    
    
    Initializing worker threads...
    
    Threads started!
    
    [ 10s ] thds: 128 tps: 630.48 qps: 3826.40 (r/w/o: 0.00/2552.33/1274.07) lat (ms,95%): 580.02 err/s: 0.30 reconn/s: 0.00
    [ 20s ] thds: 128 tps: 1911.67 qps: 11457.64 (r/w/o: 0.00/7633.90/3823.75) lat (ms,95%): 189.93 err/s: 0.40 reconn/s: 0.00
    [ 30s ] thds: 128 tps: 2713.62 qps: 16306.79 (r/w/o: 0.00/10878.86/5427.93) lat (ms,95%): 114.72 err/s: 0.70 reconn/s: 0.00
    [ 40s ] thds: 128 tps: 2571.20 qps: 15423.28 (r/w/o: 0.00/10280.98/5142.29) lat (ms,95%): 118.92 err/s: 1.00 reconn/s: 0.00
    [ 50s ] thds: 128 tps: 2658.13 qps: 15944.05 (r/w/o: 0.00/10625.50/5318.55) lat (ms,95%): 108.68 err/s: 1.30 reconn/s: 0.00
    [ 60s ] thds: 128 tps: 2601.99 qps: 15597.92 (r/w/o: 0.00/10395.75/5202.17) lat (ms,95%): 110.66 err/s: 1.00 reconn/s: 0.00
    [ 70s ] thds: 128 tps: 2666.24 qps: 16016.36 (r/w/o: 0.00/10679.08/5337.29) lat (ms,95%): 112.67 err/s: 1.90 reconn/s: 0.00
    [ 80s ] thds: 128 tps: 2403.12 qps: 14405.61 (r/w/o: 0.00/9599.07/4806.54) lat (ms,95%): 130.13 err/s: 0.60 reconn/s: 0.00
    [ 90s ] thds: 128 tps: 2846.27 qps: 17099.03 (r/w/o: 0.00/11405.19/5693.84) lat (ms,95%): 102.97 err/s: 1.00 reconn/s: 0.00
    [ 100s ] thds: 128 tps: 2759.08 qps: 16561.49 (r/w/o: 0.00/11042.22/5519.26) lat (ms,95%): 118.92 err/s: 1.10 reconn/s: 0.00
    [ 110s ] thds: 128 tps: 2668.21 qps: 16006.77 (r/w/o: 0.00/10671.75/5335.02) lat (ms,95%): 112.67 err/s: 1.00 reconn/s: 0.00
    [ 120s ] thds: 128 tps: 2571.56 qps: 15433.17 (r/w/o: 0.00/10286.65/5146.52) lat (ms,95%): 118.92 err/s: 1.10 reconn/s: 0.00
    SQL statistics:
        queries performed:
            read:                            0
            write:                           1160697
            other:                           580404
            total:                           1741101
        transactions:                        290145 (2417.05 per sec.)
        queries:                             1741101 (14504.22 per sec.)
        ignored errors:                      114    (0.95 per sec.)
        reconnects:                          0      (0.00 per sec.)
    
    General statistics:
        total time:                          120.0394s
        total number of events:              290145
    
    Latency (ms):
             min:                                  1.36
             avg:                                 52.94
             max:                               1248.60
             95th percentile:                    130.13
             sum:                            15361679.30
    
    Threads fairness:
        events (avg/stddev):           2266.7578/46.19
        execution time (avg/stddev):   120.0131/0.01
    
    

    3.清理数据

    sysbench /usr/share/sysbench/oltp_write_only.lua --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=root --mysql-password=password --mysql-db=testdb --db-driver=mysql --tables=10 --table_size=1000000 --report-interval=10 --threads=128 --time=120 cleanup
    

    (电脑崩了一次~~重启)

    显示信息:

    zifeiy@zifeiy-S1-Series:~$ sysbench /usr/share/sysbench/oltp_write_only.lua --mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=root --mysql-password=password --mysql-db=testdb --db-driver=mysql --tables=10 --table_size=1000000 --report-interval=10 --threads=128 --time=120 cleanup
    sysbench 1.0.11 (using system LuaJIT 2.1.0-beta3)
    
    Dropping table 'sbtest1'...
    Dropping table 'sbtest2'...
    Dropping table 'sbtest3'...
    Dropping table 'sbtest4'...
    Dropping table 'sbtest5'...
    Dropping table 'sbtest6'...
    Dropping table 'sbtest7'...
    Dropping table 'sbtest8'...
    Dropping table 'sbtest9'...
    Dropping table 'sbtest10'...
    
    
  • 相关阅读:
    我的本科毕业论文——Messar即时通讯系统
    你为什么不用Flash做程序的表示层呢?
    用于Blog的天气预报服务-改进20050806
    写了个小程序,方便大家编程(QuickDog,快捷键帮手)
    庆祝"上海.NET俱乐部"今天成立,请申请加入的朋友在这里Sign you name
    HTML+CSS+Javascript教学视频【0409更新】
    关于推迟7月9日上海.NET俱乐部第一次技术交流会的通知
    关于“上海.NET俱乐部”第一次技术交流会进展报告
    2005年8月13日 上海.NET俱乐部第一次活动纪实 已经发布,资料提供下载
    喜欢互联网行业,是因为它拥有着无穷的变数
  • 原文地址:https://www.cnblogs.com/zifeiy/p/10271348.html
Copyright © 2011-2022 走看看