Sysbench

2018-05-19  本文已影响0人  qingshuiting

Sysbench的搭建与使用

对于从事数据库开发或者数据库运维的同学来说,benchmark这个工具是不可缺少的。好的benchmark可以模拟出我们想测试到的各种场景以及不同的负载压力,通过对系统进行bench可以得到系统当前的性能指标,并进一步分析系统可以改进的方向。

sysbench简介

sysbensh是一个非常通用的benchmark工具,其提供多种方面的测试:

  1. cpu :提供一个简单的cpu benchmark测试
  2. fileio:文件磁盘io的benchmark测试
  3. memory:内存访问 benchmark测试
  4. thread:线程调度 benchmark测试
  5. mutex:POSIX的锁 benchmark测试
  6. OLTP:数据库 benchmark测试,支持MySQL,Pgsql

sysbench安装

sysbench的安装非常简单,其支持各类操作系统。安装的主要过程见github

因为我这里使用的是ubuntu系统,所以直接使用:

curl -s https://packagecloud.io/install/repositories/akopytov/sysbench/script.deb.sh | sudo bash
sudo apt -y install sysbench

进行安装。

sysbench使用

为了更加熟悉使用sysbench,我们需要熟悉一些通用的 options参数

--threads=N  线程数目,默认使用1
--events=N   默认为0
--time=N     默认为0
--forced-shutdown=STRING  默认为‘off’,另一个选项为‘on’
--thread-stack-size=SIZE  默认为64K
--rate=N     平均transactions率,默认为0,不限制
--report-interval=N  周期性(periodically)汇报统计信息,单位seconds,默认为0,表示disable interval report
--debug[=on|off]  print debug 信息,默认为off

还有一些其他的参数,因为很少使用所有就不介绍了。

语法表达式

sysbench [options]... [testname] [command] 

其中testname,可以是fileio,memory等,或者是一个lua script或者是lua script的path。

command表示prepare,run,cleanup或者help

具体详细的每一个options参数的含义,参考github

bench file/io

fileio 有一些独有的参数,可以直接使用sysbench fileio help查看。
主要使用的参数为

--file-num=N 默认为128
--file-block-size=N  默认为16384bytes
--file-total-size=SIZE 默认为2G
--file-test-mode=STRING       test mode {seqwr, seqrewr, seqrd, rndrd, rndwr, rndrw}
--file-io-mode=STRING         file operations mode {sync,async,mmap} [sync]
等参数

在设置file-total-size的时候应该比内存的大小大,来确保内存的cache不会影响workload太多。
这里主要说明一下file-test-mode中几个参数的含义:

bench cpu

cpu 参数比较简单,只有一个就是:

--cpu-max-prime=N upper limit for primes generator [10000]

表示需要计算的prime的数量;还有一些参数就是general options,比如线程数等。

bench memory

memory的访问参数:

  --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]

bench threads

参数有:

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

bench mutex

参数有:

  --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 outside mutex lock [10000]

OLTP workload

后续补充

上一篇 下一篇

猜你喜欢

热点阅读