• linux性能测试


    基准测试工具sysbench

        (1)安装。

    yum -y install libtool gcc

    wget http://imysql.com/wp-content/uploads/2014/09/sysbench-0.4.12-1.1.tgz

    wget http://downloads.mysql.com/source/sysbench-0.4.12.7.tar.gz

        tar -zxvf sysbench-0.4.12-1.1.tgz -C /usr/local/src/

       cd /usr/local/src/sysbench-0.4.12-1.1/

       ./autogen.sh

       ./configure --with-mysql-includes=/usr/local/mysql/include --with-mysql-libs=/usr/local/mysql/lib

     如果mysql是默认安装直接./configure

    make && make install

    运行sysbench时报错找不到libmysqlclient.so.18创建以下链接

    ln -s /opt/mysql-advanced-5.6.13-linux-glibc2.5-x86_64/lib/libmysqlclient.so.18 /usr/lib/

    (1)使用

    a).cpu性能测试

    sysbench --test=cpu --cpu-max-prime=20000 run

    cpu测试主要是进行素数的加法运算,在上面的例子中,指定了最大的素数为 20000,自己可以根据机器cpu的性能来适当调整数值,查看执行时间。

    [root@CentOS-01 bin]# sysbench --test=cpu --cpu-max-prime=20000 run

    sysbench 0.5:  multi-threaded system evaluation benchmark

    Running the test with following options:

    Number of threads: 1

    Random number generator seed is 0 and will be ignored

    Primer numbers limit: 20000

    Threads started!

    General statistics:

        total time:                          34.5993s

        total number of events:              10000

        total time taken by event execution: 34.5608s

        response time:

             min:                                  2.94ms

             avg:                                  3.46ms

             max:                                 20.15ms

             approx.  95 percentile:               4.26ms

    Threads fairness:

        events (avg/stddev):           10000.0000/0.00

        execution time (avg/stddev):   34.5608/0.00

    b). 磁盘IO性能测试

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

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

    sysbench --test=fileio --num-threads=16 --file-total-size=3G --file-test-mode=rndrw cleanup

     

    Extra file open flags: 0

    128 files, 8Mb each

    1Gb total file size

    Block size 16Kb

    Number of IO requests: 10000

    Read/Write ratio for combined random IO test: 1.50

    Periodic FSYNC enabled, calling fsync() each 100 requests.

    Calling fsync() at the end of test, Enabled.

    Using synchronous I/O mode

    Doing random r/w test

    Threads started!

     

    Operations performed:  6006 reads, 3994 writes, 12800 Other = 22800 Total

    Read 93.844Mb  Written 62.406Mb  Total transferred 156.25Mb  (4.7421Mb/sec)

      303.49 Requests/sec executed

     

    General statistics:

        total time:                          32.9499s

        total number of events:              10000

        total time taken by event execution: 445.0669s

        response time:

             min:                                  0.00ms

             avg:                                 44.51ms

             max:                                864.01ms

             approx.  95 percentile:             292.90ms

     

    Threads fairness:

        events (avg/stddev):           625.0000/54.95

    execution time (avg/stddev):   27.8167/0.57

     

    上述参数指定了最大创建16个线程,创建的文件总大小为3G,文件读写模式为随机读写。随机读写的性能为4.7m/s ,IOPS为303

    --file-test-mode的6种模式

    seqwr(顺序写), seqrewr(顺序读写), seqrd(顺序读), rndrd(随机读), rndwr(随机写), rndrw(随机读写)

    c). 内存测试

    sysbench --test=memory --memory-block-size=8k --memory-total-size=4G run

    上述参数指定了本次测试整个过程是在内存中传输 4G 的数据量,每个 block 大小为 8K

    d). OLTP测试

    准备数据(数据库mytest要先创建好):

    sysbench --test=/usr/local/src/sysbench-0.4.12-1.1/sysbench/tests/db/oltp.lua --oltp-table-size=1000 --olpt-tables-count=16 --num-threads=16 --max-requests=1000000 --db-driver=mysql --mysql-socket=/tmp/mysql.sock --mysql-user=root --mysql-password='P@ssw0rd' --mysql-db=mytest prepare

     

    测试数据:

    sysbench --test=/usr/local/src/sysbench-0.4.12-1.1/sysbench/tests/db/oltp.lua --oltp-table-size=10000 --olpt-tables-count=10 --num-threads=16 --max-requests=1000000 --db-driver=mysql --mysql-socket=/tmp/mysql.sock --mysql-user=root --mysql-password='P@ssw0rd' --mysql-db=mytest run

    sysbench 0.5:  multi-threaded system evaluation benchmark

     

    Running the test with following options:

    Number of threads: 16

    Random number generator seed is 0 and will be ignored

     

     

    Threads started!

     

    OLTP test statistics:

        queries performed:

            read:                            327040

            write:                           80893

            other:                           41984

            total:                           449917

        transactions:                        18624  (155.16 per sec.)

        deadlocks:                           4736   (39.46 per sec.)

        read/write requests:                 407933 (3398.48 per sec.)

        other operations:                    41984  (349.77 per sec.)

     

    General statistics:

        total time:                          120.0341s

        total number of events:              18624

        total time taken by event execution: 1917.8749s

        response time:

             min:                                  4.76ms

             avg:                                102.98ms

             max:                               1230.99ms

             approx.  95 percentile:             224.80ms

     

    Threads fairness:

        events (avg/stddev):           1164.0000/18.72

    execution time (avg/stddev):   119.8672/0.05

    transactions代表测试结果的评判标准即TPS,上述测试结果是 155.16 per sec

     

    清除数据:

    sysbench --test=/usr/local/src/sysbench-0.4.12-1.1/sysbench/tests/db/oltp.lua --oltp-table-size=1000 --olpt-tables-count=10 --num-threads=16 --max-requests=1000000 --db-driver=mysql --mysql-socket=/tmp/mysql.sock --mysql-user=root --mysql-password='P@ssw0rd' --mysql-db=mytest cleanup

    OLTP测试常用参数

    --oltp-test-mode=STRING         test type to use {simple,complex,nontrx,sp} [complex]//采用得测试模式
    --oltp-reconnect-mode=STRING    reconnect mode {session,transaction,query,random} [session]//重新连接模式{session(不使用重新连接。每个线程断开只在测试结束),transaction(在每次事务结束后重新连接),query(在每个SQL语句执行完重新连接),random(对于每个事务随机选择以上重新连接模式)}。默认是session
    --oltp-sp-name=STRING           name of store procedure to call in SP test mode []//跟上面的测试对应,采用自定义存储过程
    --oltp-read-only=[on|off]       generate only 'read' queries (do not modify database) [off]//产生只读查询
    --oltp-skip-trx=[on|off]        skip BEGIN/COMMIT statements [off]//感觉相当于事务没用
    --oltp-range-size=N             range size for range queries [100]//查询的范围1-100行,可定小于--oltp-table-size
    --oltp-point-selects=N          number of point selects [10]//一个事物中点(点指的是测试模式语句中的id=N)查询十次
    --oltp-simple-ranges=N          number of simple ranges [1]//一个事务中的范围查询的次数(范围指的是between N and M)
    --oltp-sum-ranges=N             number of sum ranges [1]
    --oltp-order-ranges=N           number of ordered ranges [1]
    --oltp-distinct-ranges=N        number of distinct ranges [1]
    --oltp-index-updates=N          number of index update [1]
    --oltp-non-index-updates=N      number of non-index updates [1]
    --oltp-nontrx-mode=STRING       mode for non-transactional test {select, update_key, update_nokey, insert, delete} [select]//nontrx模式只用select语句
    --oltp-auto-inc=[on|off]        whether AUTO_INCREMENT (or equivalent) should be used on id column [on]//AUTO_INCREMENT开启
    --oltp-connect-delay=N          time in microseconds to sleep after connection to database [10000]//什么含义?
    --oltp-user-delay-min=N         minimum time in microseconds to sleep after each request [0]
    --oltp-user-delay-max=N         maximum time in microseconds to sleep after each request [0]
    --oltp-table-name=STRING        name of test table [sbtest]//测试的表,默认sbtest
    --oltp-table-size=N             number of records in test table [10000]//表的行数
    --oltp-dist-type=STRING         random numbers distribution {uniform,gaussian,special} [special]----参考全局参数
    --oltp-dist-iter=N              number of iterations used for numbers generation [12]
    --oltp-dist-pct=N               percentage of values to be treated as 'special' (for special distribution) [1]
    --oltp-dist-res=N               percentage of 'special' values to use (for special distribution) [75]
     --oltp-tables-count=N    表示生成几个测试表
    --mysql-table-engine=innodb  指定表类型

    网络性能测试

        1. iperf的安装与使用

    (1).iperf安装

     wget https://iperf.fr/download/iperf_3.1/iperf-3.1-source.tar.gz

     yum –y intall gcc

         tar –zxvf iperf-3.1-source.tar.gz

             cd iperf-3.1

             ./configure

          make && make install

    (2)使用

    服务端

    iperf3 -s -D

    客户端

     iperf3 -c X.X.X.X -t 10 –b 1000M –P 10

    X.X.X.X替换为服务器端IP

    [ ID] Interval           Transfer     Bandwidth       Retr

    [  4]   0.00-10.00  sec  3.45 GBytes  2.96 Gbits/sec    0             sender

    [  4]   0.00-10.00  sec  3.44 GBytes  2.96 Gbits/sec                  receiver

    Transfer 10s内发送的总数据,Bandwidth传输带宽

    (2) 常用参数

    -s 服务端运行

    -D 服务端己daemon方式运行

    -c  客户端模式运行

    -P  设定并发连接数

    -R reverse模式(服务端发送,客户端接收)

    -u  以UDP协议发送

    -t  测试时间多少秒,默认10s

     

     

    五.附

    Sysbench 测试IO的脚本

    如果需要测试seqwr(顺序写), seqrewr(顺序读写), seqrd(顺序读), rndrd(随机读), rndwr(随机写), rndrw(随机读写)等6种模式,并且还可能需要测试不同的线程和不同的文件块下磁盘的性能表现,这时,可以使用如下脚本达到测试目的

     

     

    #!/bin/bash

    #==============================================================================

    #

    #          FILE: sysbench_auto.sh

    #

    #         USAGE: ./sysbench_auto.sh

    #

    #   DESCRIPTION: This file is sysbench_auto.sh 

    #        AUTHOR: Kevin Lu (kevin), kevin@gmail.com

    #  ORGANIZATION: cmcc

    #       CREATED: 02/26/2014 17:35

    #      REVISION: v1.0.1

    #==============================================================================

     

    for size in {8G,64G}

    do

    for mode in {seqwr,seqrewr,seqrd,rndrd,rndwr,rndrw}

    do

    for blksize in {4096,16384}

    do

    sysbench --test=fileio --file-num=64 --file-total-size=$size prepare

    for threads in {1,4,8,16,32}

    do

    echo "=============testing $blksize in $threads threads"

    echo PARAS $size $mode $threads $blksize> sysbench-size-$size-mode-$mode-threads-$threads-blksz-$blksize

    for i in {1,2,3}

    do

    sysbench --test=fileio --file-total-size=$size --file-test-mode=$mode --max-time=180 --max-requests=100000 --num-threads=$threads --

    init-rng=on --file-num=64 --file-extra-flags=direct --file-fsync-freq=0 --file-block-size=$blksize run|tee -a sysbench-size-$size-mo

    de-$mode-threads-$threads-blksz-$blksize 2>&1

    done

    done

    sysbench --test=fileio --file-total-size=$size cleanup

    done

    done

    done

  • 相关阅读:
    mongodb 的主从配置
    python 操作mongoDB数据库
    git常用操作
    基于canvas与原生JS的H5动画引擎
    mongodb的使用(入门)
    mongodb 的安装(Centor OS )
    NIO概述及实例(时钟服务器)
    netty上手
    BootStrap概述
    Spark SQL访问PostgreSQL
  • 原文地址:https://www.cnblogs.com/nbuntu/p/5546320.html
Copyright © 2020-2023  润新知