服务器基准测试工具sysbench
基准测试工具介绍
- sysbench
一个开源的、模块化的、跨平台的多线程性能测试工具,可以用来进行CPU、内存、磁盘I/O、线程、数据库的性能测试,目前支持的数据库有MySQL、Oracle和PostgreSQL - Github地址:https://github.com/akopytov/sysbench/
安装
以Centos系统为例,分为在线安装和离线安装
在线安装
curl -s https://packagecloud.io/install/repositories/akopytov/sysbench/script.rpm.sh | sudo bash
sudo yum -y install sysbench
离线安装
- 下载项目zip包 / git clone
- 安装yum依赖
yum -y install make automake libtool pkgconfig libaio-devel # For MySQL support, replace with mysql-devel on RHEL/CentOS 5 yum -y install mariadb-devel openssl-devel # For PostgreSQL support yum -y install postgresql-devel
- 解压zip包
-
进入目录源码编译安装
./autogen.sh ./configure make -j make install
安装后验证
[root@localhost ~]# sysbench --version
sysbench 1.1.0
测试
基本语法和参数
- 基本语法:
sysbench [options]... [testname] [command]
- options:参数
- 每个测试模块都有对应的参数(如下通用参数)
- testname:测试模块
- fileio:磁盘
- memory:内存
- cpu:cpu
- 其他
- command:命令
- prepare:数据准备 (磁盘和数据库测试需要先进行数据准备)
- run:执行
- cleanup:清除prepare测试数据
- help:帮助
- options:参数
- 通用参数:
通用参数 描述 默认值 –threads 执行线程数 1
内存
- 使用方法
[root@localhost ~]# sysbench memory help sysbench 1.1.0 (using bundled LuaJIT 2.1.0-beta3) 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]
- 参数说明
参数 描述 默认值 –memory-block-size=SIZE 内存block大小 1KB –memory-total-size=SIZE 生成文件大小 100GB –memory-scope=STRING 内存访问的范围,包括global(全局)和(local)本地范围,默认为global global –memory-hugetlb=[on/off] 是否从HugeTLB池分配内存的开关 off –memory-oper=STRING 内存操作的类型,包括read, write, none write –memory-access-mode=STRING 内存访问模式,包括seq(顺序),rnd(随机)两种模式 seq - 示例
测试内存顺序写 sysbench memory --memory-access-mode=seq --memory-oper=write run
- 结果查看
磁盘
-
使用方法
[root@localhost ~]# sysbench fileio help sysbench 1.1.0 (using bundled LuaJIT 2.1.0-beta3) 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} --file-io-mode=STRING file operations mode {sync,async,mmap} [sync] --file-async-backlog=N number of asynchronous operatons to queue per thread [128] --file-extra-flags=[LIST,...] list of additional flags to use to open 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]
- 参数说明
参数 描述 默认值 –file-num=N 生成测试文件的数量 128 –file-block-size=N 测试时所使用文件块的大小,如果想磁盘针对innodb存储引擎进行测试,可以将其设置为16384,即innodb存储引擎页的大小 16384 –file-total-size=SIZE 创建测试文件的总大小 2GB –file-test-mode=STRING 文件测试模式:seqwr(顺序写), seqrewr(顺序读写),seqrd(顺序读),rndrd(随机读),rndwr(随机写),rndrw(随机读写) 无 –file-io-mode=STRING 文件操作的模式:sync(同步),async(异步),fastmmap(快速mmap),slowmmap(慢速mmap) sync(同步) –file-async-backlog=N 对应每个线程队列的异步操作数 128 –file-extra-flags=STRING 打开文件时的选项,这是与API相关的参数 无 –file-fsync-freq=N 执行fsync()函数的频率。fsync主要是同步磁盘文件,因为可能有系统和磁盘缓冲的关系。0代表不使用fsync函数 100 –file-fsync-all=[on/off] 每执行完一次写操作,就执行一次fsync off –file-fsync-end=[on/off] 在测试结束时执行fsync函数 on –file-fsync-mode=STRING 文件同步函数的选择,同样是和API相关的参数,由于多个操作系统对于fdatasync支持不同,因此不建议使用fdatasync fsync –file-merged-requests=N 大多情况下,合并可能的IO的请求数 0 –file-rw-ratio=N 测试时的读写比例 1.5, 即3:2 - 示例
测试磁盘随机写效率 sysbench fileio --file-test-mode=rndwr prepare sysbench fileio --file-test-mode=rndwr run sysbench fileio --file-test-mode=rndwr cleanup
- 结果查看
Cpu
-
使用方法
[root@localhost ~]# sysbench cpu help sysbench 1.1.0 (using bundled LuaJIT 2.1.0-beta3) cpu options: --cpu-max-prime=N upper limit for primes generator [10000]
- 参数说明
参数 描述 默认值 –cpu-max-prime=N 用来选项指定最大的素数,具体参数可以根据CPU的性能来设置 10000 - 示例
测试3个线程cpu效率 sysbench cpu --threads=3 run
-
结果查看
https://helloworld.com