sysbench使用笔记

项目地址 https://launchpad.net/sysbench (目前已迁移至https://github.com/akopytov/sysbench)


下载源码包,解压,

执行autogen.sh, 可能会提示缺少automake 和libtoolize  ,自行yum install automake  libtool 即可

之后./configure


mysql 自行编译安装的可能会提示 configure: error: mysql_config executable not found 需要添加如下参数

--with-mysql-includes=/usr/local/mysql/include \
--with-mysql-libs=/usr/local/mysql/lib

之后make 即可...  make完之后会在源码目录的sysbench下生成一个sysbench二进制文件

直接执行即可看到相关的参数信息..


Q:  mysql 若是自行编译安装的话,执行sysbench可能会遇到错误提示

error while loading shared libraries: libmysqlclient.so.18: cannot open shared object file:
No such file or directory

A:export LD_LIBRARY_PATH=/usr/local/mysql/lib

  • CPU 性能测试 / CPU performance test

    CPU测试使用64位整数,测试计算素数直到某个最大值所需要的时间

    ./sysbench --test=cpu  --num-threads=2  --cpu-max-prime=20000   run

    sysbench 0.5:  multi-threaded system evaluation benchmark

    Running the test with following options:
    Number of threads: 2
    Random number generator seed is 0 and will be ignored

    Prime numbers limit: 20000

    Threads started!

    General statistics:
        total time:                          29.3082s
        total number of events:              10000
        total time taken by event execution: 58.5971s
        response time:
             min:                                  2.86ms
             avg:                                  5.86ms
             max:                                107.92ms
             approx.  95 percentile:               3.10ms

    Threads fairness:
        events (avg/stddev):           5000.0000/7.00
        execution time (avg/stddev):   29.2985/0.00

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

    其中 --num-threads The total number of worker threads to create

    默认为1, 一般设置为CPU核数(线程数)即可,设置过大也不会对性能带来影响

    • cpu options:
        --cpu-max-prime=N      upper limit for primes generator [10000]
  • 线程(thread)测试  / Threads subsystem performance test

    测试线程调度器的性能。对于高负载情况下测试线程调度器的行为非常有用。

    多核性能,线程调度 线程并发执行,循环响应信号量花费的时间

    ./sysbench --test=threads --num-threads=2 run  

    sysbench 0.5:  multi-threaded system evaluation benchmark

    Running the test with following options:
    Number of threads: 2
    Random number generator seed is 0 and will be ignored

    Threads started!

    General statistics:
        total time:                          3.9964s
        total number of events:              10000
        total time taken by event execution: 7.9829s
        response time:
             min:                                  0.76ms
             avg:                                  0.80ms
             max:                                  2.22ms
             approx.  95 percentile:               0.82ms

    Threads fairness:
        events (avg/stddev):           5000.0000/0.00
        execution time (avg/stddev):   3.9914/0.00

    threads options:
      --thread-yields=N      number of yields to do per request [1000]
      --thread-locks=N       number of locks per thread [8]

  • 互斥锁(mutex) /Mutex performance test

    并发线程同时申请互斥锁循环一定次数花费的时间 测试互斥锁的性能

    方式是模拟所有线程在同一时刻并发运行,并都短暂请求互斥锁。

    ./sysbench --test=mutex --num-threads=2 --mutex-locks=1000000 run

    sysbench 0.5:  multi-threaded system evaluation benchmark

    Running the test with following options:
    Number of threads: 2
    Random number generator seed is 0 and will be ignored

    Threads started!

    General statistics:
        total time:                          0.0874s
        total number of events:              2
        total time taken by event execution: 0.1312s
        response time:
             min:                                 43.82ms
             avg:                                 65.60ms
             max:                                 87.37ms
             approx.  95 percentile:              87.38ms

    Threads fairness:
        events (avg/stddev):           1.0000/0.00
        execution time (avg/stddev):   0.0656/0.02

    mutex options:
      --mutex-num=N        total size of mutex array [4096]
      --mutex-locks=N      number of mutex locks to do per thread [50000]
      --mutex-loops=N      number of empty loops to do inside mutex lock [10000]

  • 内存测试 / Memory functions speed test

    以不同块大小传输一定数量的数据,测试内存读写性能

    sysbench --test=memory --memory-block-size=8K --memory-total-size=2G  --num-threads=2 run

    sysbench 0.5:  multi-threaded system evaluation benchmark

    Running the test with following options:
    Number of threads: 2
    Random number generator seed is 0 and will be ignored

    Threads started!

    Operations performed: 262144 (743947.40 ops/sec)

    2048.00 MB transferred (5812.09 MB/sec)

    General statistics:
        total time:                          0.3524s
        total number of events:              262144
        total time taken by event execution: 0.4492s
        response time:
             min:                                  0.00ms
             avg:                                  0.00ms
             max:                                100.97ms
             approx.  95 percentile:               0.00ms

    Threads fairness:
        events (avg/stddev):           131072.0000/20186.00
        execution time (avg/stddev):   0.2246/0.02

    memory options:
      --memory-block-size=SIZE    size of memory block for test [1K]
      --memory-total-size=SIZE    total size of data to transfer [100G]
      --memory-scope=STRING       memory access scope {global,local} [global]
      --memory-hugetlb=[on|off]   allocate memory from HugeTLB pool [off]
      --memory-oper=STRING        type of memory operations {read, write, none} [write]
      --memory-access-mode=STRING memory access mode {seq,rnd} [seq]

  • 文件IO基准测试 / File I/O test

    测试系统在不同IO负载下的IOPS性能

    准备工作(创建测试文件)

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

    测试

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

    清理测试文件

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

    ./sysbench --test=fileio --num-threads=2 --file-total-size=4G --file-test-mode=rndrw run
    sysbench 0.5:  multi-threaded system evaluation benchmark

    Running the test with following options:
    Number of threads: 2
    Random number generator seed is 0 and will be ignored

    Extra file open flags: 0
    128 files, 32Mb each
    4Gb 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:  5999 reads, 4001 writes, 12800 Other = 22800 Total
    Read 93.734Mb  Written 62.516Mb  Total transferred 156.25Mb  (9.1877Mb/sec)
      588.01 Requests/sec executed

    General statistics:
        total time:                          17.0064s
        total number of events:              10000
        total time taken by event execution: 0.6489s
        response time:
             min:                                  0.00ms
             avg:                                  0.06ms
             max:                                 97.59ms
             approx.  95 percentile:               0.03ms

    Threads fairness:
        events (avg/stddev):           5000.0000/618.00
        execution time (avg/stddev):   0.3245/0.06

    fileio options:
      --file-num=N                  number of files to create [128]
      --file-block-size=N           block size to use in all IO operations [16384]
      --file-total-size=SIZE        total size of files to create [2G]
      --file-test-mode=STRING       test mode {seqwr, seqrewr, seqrd, rndrd, rndwr, rndrw}
      seqwr 顺序写入 seqrewr 顺序重写 seqrd 顺序读取 rndrd 随机读取 rndwr 随机写入 rndrw 混合随机读/写

      --file-io-mode=STRING         file operations mode {sync,async,mmap} [sync]
      --file-extra-flags=STRING     additional flags to use on opening files {sync,dsync,direct} []
      --file-fsync-freq=N           do fsync() after this number of requests (0 - don‘t use fsync()) [100]
      --file-fsync-all=[on|off]     do fsync() after each write operation [off]
      --file-fsync-end=[on|off]     do fsync() at the end of test [on]
      --file-fsync-mode=STRING      which method to use for synchronization {fsync, fdatasync} [fsync]
      --file-merged-requests=N      merge at most this number of IO requests if possible (0 - don‘t merge) [0]
      --file-rw-ratio=N             reads/writes ratio for combined test [1.5]

    引用网上的一段总结

  • 性能测试【找范围内最大素数{时间越短越好}】

  • 线程调度【线程并发执行,循环响应信号量花费的时间{越少越好}】

  • 互斥锁【并发线程同时申请互斥锁循环一定次数花费的时间{越少越好}】

  • 内存【以不同块大小传输一定数量的数据吞吐量大小{越大越好}】

  • IO【不同场景下IOPS{越大越好}】

    • MySQL数据库测试

    sysbench 0.5通过一系列LUA脚本来替换之前的oltp,来模拟更接近真实的基准测试环境。这些测试脚本包含:insert.lua、oltp.lua、 parallel_prepare.lua、select_random_points.lua、update_index.lua、 delete.lua oltp_simple.lua、select.lua、select_random_ranges.lua、 update_non_index.lua,脚本使用方式基本类似。

    sysbench 0.5默认使用sbtest库,但是需要自己手工先创建好,也可以使用--mysql-db指定,其他非默认项指定选项:

    1. -mysql-host

    2. -mysql-port
    3. -mysql-socket
    4. -mysql-user
    5. -mysql-password
    6. -mysql-db
    7. -mysql-ssl
    • prepare
      生成表并插入数据,可使用parallel_prepare.lua脚本来并行准备数据。
    1. –db-driver 服务器类型 mysql | drizzle,默认为mysql

    2. –mysql-table-engine 表存数引擎
    3. –myisam-max-rows MyISAM表MAX_ROWS选项(用于大表)
    4. –oltp-tables-count 生成表数量[sbtest1、sbtest2...]
    5. –oltp-table-size 生成表的行数
    6. –oltp-secondary ID列生成二级索引而不是主键
    7. –oltp-auto-inc 设置ID列是否自增 on | off,默认为on

    注意  -oltp-tables-count 和 –oltp-table-size之类的参数 ,sysbench 参数写错了不会提示出错,会按原参数默认值执行

    ./sysbench --test=tests/db/oltp.lua --mysql-user=sysbench --oltp-tables-count=10 --oltp-table-size=100000 --mysql-password=sysbench --mysql-host=192.168.200.2 --report-interval=1 --num-threads=16 run
    sysbench 0.5:  multi-threaded system evaluation benchmark

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

    Threads started!

    OLTP test statistics:
        queries performed:
            read:                            140000
            write:                           40000
            other:                           20000
            total:                           200000
        transactions:                        10000  (375.41 per sec.)##(这就是大家评测的TPS,即每秒处理的事务数)
        read/write requests:                 180000 (6757.36 per sec.)###(每秒读写次数)
        other operations:                    20000  (750.82 per sec.)
        ignored errors:                      0      (0.00 per sec.)
        reconnects:                          0      (0.00 per sec.)

    
    

    General statistics:
        total time:                          26.6376s
        total number of events:              10000
        total time taken by event execution: 425.6943s
        response time:
             min:                                 11.18ms
             avg:                                 42.57ms
             max:                                194.44ms
             approx.  95 percentile:              78.24ms

    Threads fairness:
        events (avg/stddev):           625.0000/6.95
        execution time (avg/stddev):   26.6059/0.01

    execution time (avg/stddev):   46.9500/0.01

    如何避免压测时受到缓存的影响  有2点建议
    a、填充测试数据比物理内存还要大,至少超过 innodb_buffer_pool_size 值,不能将数据全部装载到内存中,除非你的本意就想测试全内存状态下的MySQL性能。
    b、每轮测试完成后,都重启mysqld实例,并且用下面的方法删除系统cache,释放swap(如果用到了swap的话),甚至可以重启整个OS。

    [[email protected]]# sync  -- 将脏数据刷新到磁盘
    [[email protected]]# echo 3 > /proc/sys/vm/drop_caches  -- 清除OS Cache
    [[email protected]]# swapoff -a && swapon -a
  • 时间: 2024-08-04 15:56:51

    sysbench使用笔记的相关文章

    【安全牛学习笔记】

    弱点扫描 ╋━━━━━━━━━━━━━━━━━━━━╋ ┃发现弱点                                ┃ ┃发现漏洞                                ┃ ┃  基于端口五福扫描结果版本信息(速度慢)┃ ┃  搜索已公开的漏洞数据库(数量大)      ┃ ┃  使用弱点扫描器实现漏洞管理            ┃ ╋━━━━━━━━━━━━━━━━━━━━╋ [email protected]:~# searchsploit Usage:

    51CTO持续更新《通哥的运维笔记》

    <通哥的运维笔记>将持续在51CTO网站更新,希望大家多多关注.互相学习,后期,我将会退出<通哥的运维笔记>系列视频教程,希望带给大家最大的收获,帮助大家更好的学习.进步.<通哥的运维笔记>主要从linux系统管理.虚拟化.cloudstack云平台以及网络管理之CCNA.CCNP.CCIE,等等方面深入讲解.

    WPF笔记整理 - Bitmap和BitmapImage

    项目中有图片处理的逻辑,因此要用到Bitmap.而WPF加载的一般都是BitmapImage.这里就需要将BitmapImage转成Bitmap 1. 图片的路径要用这样的,假设图片在project下的Images目录,文件名XXImage.png. pack://application:,,,/xxx;component/Images/XXImage.png 2. 代码: Bitmap bmp = null; var image = new BitmapImage(new Uri(this.X

    java String 类 基础笔记

    字符串是一个特殊的对象. 字符串一旦初始化就不可以被改变. String s = "abc";//存放于字符串常量池,产生1个对象 String s1=new String("abc");//堆内存中new创建了一个String对象,产生2个对象 String类中的equals比较字符串中的内容. 常用方法: 一:获取 1.获取字符串中字符的个数(长度):length();方法. 2.根据位置获取字符:charAt(int index); 3.根据字符获取在字符串中

    vector 学习笔记

    vector 使用练习: /**************************************** * File Name: vector.cpp * Author: sky0917 * Created Time: 2014年04月27日 11:07:33 ****************************************/ #include <iostream> #include <vector> using namespace std; int main

    学习笔记之邮件发送篇

    用脚本语言发送邮件是系统管理员必备技能 对系统定期检查或者当服务器受到攻击时生成文档和报表. 发布这些文档最快速有效的方法就是发送邮件. python中email模块使得处理邮件变得比较简单 发送邮件主要用到了smtplib和email两个模块,这里首先就两个模块进行一下简单的介绍: 本段摘录于    http://www.cnblogs.com/xiaowuyi/archive/2012/03/17/2404015.html 1.smtplib模块 smtplib.SMTP([host[, p

    15.1-全栈Java笔记:Java事件模型是什么?事件控制的过程有哪几步??

    应用前边两节上一章节的内容,大家可以完成一个简单的界面,但是没有任何的功能,界面完全是静态的,如果要实现具体功能的话,必须要学习事件模型. 事件模型简介及常见事件模型 对于采用了图形用户界面的程序来说,事件控制是非常重要的. 一个源(事件源)产生一个事件并把它(事件对象)送到一个或多个监听器那里,监听器只是简单地等待,直到它收到一个事件,一旦事件被接收,监听器将处理这些事件. 一个事件源必须注册监听器以便监听器可以接收关于一个特定事件的通知. 每种类型的事件都有其自己的注册方法,一般形式为: v

    Java设计模式学习笔记,一:单例模式

    开始学习Java的设计模式,因为做了很多年C语言,所以语言基础的学习很快,但是面向过程向面向对象的编程思想的转变还是需要耗费很多的代码量的.所有希望通过设计模式的学习,能更深入的学习. 把学习过程中的笔记,记录下来,只记干货. 第一部分:单例模式的内容 单例模式:类只能有一个实例. 类的特点:1.私有构造器:2.内部构造实例对象:3.对外提供获取唯一实例的public方法. 常见的单例模式实现有五种形式: 1.饿汉式. 2.懒汉式. 3.双重检查锁式. 4.静态内部类式. 5.枚举式. 以下分别

    Caliburn.Micro学习笔记(一)----引导类和命名匹配规则

    Caliburn.Micro学习笔记(一)----引导类和命名匹配规则 用了几天时间看了一下开源框架Caliburn.Micro 这是他源码的地址http://caliburnmicro.codeplex.com/ 文档也写的很详细,自己在看它的文档和代码时写了一些demo和笔记,还有它实现的原理记录一下 学习Caliburn.Micro要有MEF和MVVM的基础 先说一下他的命名规则和引导类 以后我会把Caliburn.Micro的 Actions IResult,IHandle ICondu