Sysbench安装和测试

https://github.com/akopytov/sysbench

sysbench是一个开源的、模块化的、跨平台的多线程性能测试工具,可以用来进行CPU、内存、磁盘I/O、线程、数据库的性能测试。目前支持的数据库有MySQLOraclePostgreSQL

# cd sysbench-0.4.12
# ./autogen.sh
关键的三步:configure && make && make install
首先是./configure命令,sysbench默认是支持MySQL的benchmarking的,如果不加任何选项则要求保证MySQL的安装路径都是默认的标准路径,headfile位于/usr/include目录下,libraries位于/usr/lib/目录下。因为我的MySQL是源码编译安装的,安装路径是放在/usr/local/mysql下,所以这里要添加相应的选项命令:
# ./configure --prefix=/usr/local/sysbench --with-mysql=/usr/local/mysql \
--with-mysql-includes=/usr/local/mysql/include/mysql/ \
--with-mysql-libs=/usr/local/mysql/lib/mysql/
注意:这里在编译时要将路径写到最后的include/mysql及lib/mysql,如下所示:
–with-mysql-includes=/usr/local/mysql/include/mysql/
--with-mysql-libs=/usr/local/mysql/lib/mysql/

因为网上好多资料都没有提到这一层,在编译时总是编译不过去,这里浪费了好多精力。
如果需要测试PostgreSQL、Oracle,则在configure时需要加上--with-oracle或者--with-pgsql 参数。

# sysbench --help
Usage:
  sysbench [general-options]... --test=<test-name> [test-options]... command
General options:
  --num-threads=N            number of threads to use [1]
  --max-requests=N           limit for total number of requests [10000]
  --max-time=N               limit for total execution time in seconds [0]
  --forced-shutdown=STRING   amount of time to wait after --max-time before forcing shutdown [off]
  --thread-stack-size=SIZE   size of stack per thread [32K]
  --init-rng=[on|off]        initialize random number generator [off]
  --test=STRING              test to run
  --debug=[on|off]           print more debugging info [off]
  --validate=[on|off]        perform validation checks where possible [off]
  --help=[on|off]            print help and exit
  --version=[on|off]         print version and exit
Compiled-in tests:
  fileio - File I/O test
  cpu - CPU performance test
  memory - Memory functions speed test
  threads - Threads subsystem performance test
  mutex - Mutex performance test 调度程序性能
  oltp - OLTP test
Commands: prepare run cleanup help version
See 'sysbench --test=<name> help' for a list of options for each test.

https://github.com/akopytov/sysbench

https://dev.mysql.com/downloads/benchmarks.html 

http://blog.chinaunix.net/uid-7589639-id-4123266.html

http://blog.chinaunix.net/uid-7589639-id-4126046.html

http://www.cnblogs.com/conanwang/p/5910079.html

http://imysql.cn/2014/10/17/sysbench-full-user-manual.shtml
http://imysql.com/node/312


sysbench --test=fileio --file-num=16 --file-total-size=10M prepare
sysbench --test=fileio --file-num=16 --file-total-size=10M --file-test-mode=rndrd --file-extra-flags=direct --file-fsync-freq=0 --file-block-size=16384--max-time=60 --max-requests=100000000 --num-threads=16 --init-rng=on run
sysbench --test=fileio --file-num=16 --file-total-size=10M cleanup

sysbench --test=oltp --oltp-table-size=8000 --db-driver=mysql --mysql-db=test prepare
sysbench --test=oltp --oltp-table-size=8000 --db-driver=mysql --mysql-db=test --oltp-read-only=off --oltp-dist-type=uniform --init-rng=on --num-threads=16 --max-requests=0 --max-time=3600 run 

mysql> desc sbtest;
+-------+------------------+------+-----+---------+----------------+
| Field | Type             | Null | Key | Default | Extra          |
+-------+------------------+------+-----+---------+----------------+
| id    | int(10) unsigned | NO   | PRI | NULL    | auto_increment |
| k     | int(10) unsigned | NO   | MUL | 0       |                |
| c     | char(120)        | NO   |     |         |                |
| pad   | char(60)         | NO   |     |         |                |
+-------+------------------+------+-----+---------+----------------+


export LD_LIBRARY_PATH=~/sysbench/lib

1、cpu性能测试
sysbench --test=cpu --cpu-max-prime=20000 run
cpu测试主要是进行素数的加法运算,指定了最大的质数发生器数量为 20000


2、线程测试
sysbench --test=threads --num-threads=64 --thread-yields=100 --thread-locks=2 run
发送64次/个测试线程请求,每次/个线程请求产生/生成100个数量,每个线程的锁数量为2


3、磁盘IO性能测试
首先创建要测试用的文件
sysbench --test=fileio --num-threads=16 --file-total-size=3G --file-test-mode=rndrw prepare
其次进行磁盘IO测试
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
上述参数指定了最大创建16个线程,创建的文件总大小为3G,文件读写模式为随机读。


4、内存测试
sysbench --test=memory --memory-block-size=8k --memory-total-size=4G run
上述参数指定了本次测试整个过程是在内存中传输 4G 的数据量,每个 block 大小为 8K。


5、OLTP测试
sysbench --test=oltp help
sysbench --test=oltp --mysql-table-engine=myisam --oltp-table-size=1000000 --mysql-socket=/tmp/mysql.sock --mysql-user=test --mysql-host=localhost --mysql-password=test --percentile=99 run
上述参数指定了本次测试的表存储引擎类型为 myisam,指定了表最大记录数为 1000000,其他参数就很好理解了,主要是指定登录方式。测试 OLTP 时,可以自己先创建数据库 sbtest,或者自己用参数 --mysql-db 来指定其他数据库。--mysql-table-engine 还可以指定为 innodb 等 MySQL 支持的表存储引擎类型。--percentile=99 表示设定采样比例,默认是 95%,即丢弃1%的长请求,在剩余的99%里取最大值

注意,针对不同的选项取值就会有不同的子选项。比如oltp-dist-type=special,就有比如oltp-dist-pct=1oltp-dist-res=50两个子选项,代表有50%的查询落在1%的行(即热点数据)上,另外50%均匀的(sample uniformly)落在另外99%的记录行上。

再比如oltp-test-mode=nontrx时, 就可以有oltp-nontrx-mode,可选值有select(默认), update_key, update_nokey, insert, delete,代表非事务式模式下使用的测试sql类型。


真实测试场景中,数据表建议不低于 10个 ,单表数据量不低于 500万行 ,当然了,要视服务器硬件配置而定。如果是配备了SSD或者PCIE SSD这种高IOPS设备的话,则建议单表数据量最少不低于 1亿行
真实测试场景中,建议持续压测时长不小于30分钟,否则测试数据可能不具参考意义。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值