简介

源码地址:https://github.com/akopytov/sysbench

sysbench is a scriptable multi-threaded benchmark tool based on LuaJIT. It is most frequently used for database benchmarks, but can also be used to create arbitrarily complex workloads that do not involve a database server.

sysbench comes with the following bundled benchmarks:

  • oltp_*.lua: a collection of OLTP-like database benchmarks
  • fileio: a filesystem-level benchmark
  • cpu: a simple CPU benchmark
  • memory: a memory access benchmark
  • threads: a thread-based scheduler benchmark
  • mutex: a POSIX mutex benchmark

Features

  • extensive statistics about rate and latency is available, including latency percentiles and histograms;
  • low overhead even with thousands of concurrent threads. sysbench is capable of generating and tracking hundreds of millions of events per second;
  • new benchmarks can be easily created by implementing pre-defined hooks in user-provided Lua scripts;
  • can be used as a general-purpose Lua interpreter as well, simply replace #!/usr/bin/lua with #!/usr/bin/sysbench in your script.

简单的说,sysbench是一个基于Lua即时编译器(http://luajit.org/luajit.html )实现的多线程基准测试工具。它被频繁用于数据库基准测试,除此之外,它也可以被用于进行其他复杂的负载测试,比如fileio,cpu,memory等。

安装

本文以“sysbench-1.0.20”版本为例,下载源码,并编译安装。

  1. 下载地址:
  2. 安装sysbench的依赖包。
1
yum install gcc gcc-c++ automake make libtool mariadb-devel -y
  1. 下载并安装sysbench。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# 下载sysbench源码
wget https://github.com/akopytov/sysbench/archive/refs/tags/1.0.20.tar.gz

# 解压
mv 1.0.20.tar.gz sysbench-1.0.20.tar.gz
tar zxvf sysbench-1.0.20.tar.gz && cd sysbench-1.0.20

# 配置及生成编译文件
./autogen.sh && ./configure

# 编译并安装
make && make install

# 验证sysbench
sysbench --version

使用

CPU性能测试

1
2
# 10秒钟CPU素数计算次数
sysbench cpu --cpu-max-prime=20000 --threads=1 run

内存性能测试

1
2
3
4
5
# 内存顺序:10秒钟,内存顺序访问次数与速度
sysbench memory --threads=1 --memory-block-size=8K --memory-total-size=200G --memory-access-mode=seq run

# 内存随机:10秒钟,内存随机访问次数与速度
sysbench memory --threads=1 --memory-block-size=8K --memory-total-size=200G --memory-access-mode=rnd run

存储性能测试

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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-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]

# 加载4k测试数据
sysbench fileio --threads=1 --file-block-size=4k --file-total-size=20G --file-test-mode=rndrw prepare

# 随机读
sysbench fileio --threads=1 --file-block-size=4k --file-total-size=20G --time=60 --file-test-mode=rndrd run

# 随机写
sysbench fileio --threads=1 --file-block-size=4k --file-total-size=20G --time=60 --file-test-mode=rndwr run

# 加载1M测试数据
sysbench fileio --threads=1 --file-block-size=1M --file-total-size=20G --file-test-mode=rndrw prepare

# 顺序读
sysbench fileio --threads=1 --file-block-size=1M --file-total-size=20G --time=60 --file-test-mode=seqrd run

# 顺序写
sysbench fileio --threads=1 --file-block-size=1M --file-total-size=20G --time=60 --file-test-mode=seqwr run

MySQL性能测试

参考本博客文档:《MySQL测试:性能基准测试》

参考文档