文件系统测试工具filebench

1.filebench安装

首先检测是否安装了gcc:

gcc –version

如果已经安装则执行:

sudo apt-get install flex bison

Ubuntu下安装filebench,首先下载安装包。

szp@szp-pc:~$ wget https://phoenixnap.dl.sourceforge.net/project/filebench/1.5-alpha3/filebench-1.5-alpha3.tar.gz

将filebench解压到/usr/local目录下。

szp@szp-pc:~$ sudo tar -zxf filebench-1.5-alpha3.tar.gz -C /usr/local

进入解压后的目录下,

szp@szp-pc:~$ cd /usr/local/

依次执行以下命令进行安装。

szp@szp-pc:/usr/local/filebench-1.5-alpha3$ sudo ./configure 
szp@szp-pc:/usr/local/filebench-1.5-alpha3$ sudo make
szp@szp-pc:/usr/local/filebench-1.5-alpha3$ sudo make install

为了不影响filebench自带的负载文件,复制一份workloads下自带的工作负载文件,然后根据自身需要进行修改。

szp@szp-pc:~$ cp -r /usr/local/share/filebench/workloads/ ./workloads

使用WML语言进行编写,教程如下:workload model language

2.filebench模拟web服务器测试

使用

sudo filebench -f webserver.f

运行webserver测试。

直接运行会出现无法停止的问题,修改webserver.f,加入退出模式。

1
2
// 设置退出模式,支持[ timeout | alldone | firstdone ]
set mode quit firstdone

然后有可能出现以下错误:

szp@szp-pc:~/workloads$ sudo filebench -f webserver.f 
Filebench Version 1.5-alpha3
0.002: Allocated 173MB of shared memory
0.027: Web-server Version 3.1 personality successfully loaded
0.027: Populating and pre-allocating filesets
0.032: logfiles populated: 1 files, avg. dir. width = 2, avg. dir. depth = 0.0, 0 leafdirs, 0.002MB total size
0.032: Removing logfiles tree (if exists)
0.039: Pre-allocating directories in logfiles tree
0.039: Pre-allocating files in logfiles tree
0.040: bigfileset populated: 10 files, avg. dir. width = 2, avg. dir. depth = 3.3, 0 leafdirs, 0.132MB total size
0.040: Removing bigfileset tree (if exists)
0.046: Pre-allocating directories in bigfileset tree
0.046: Pre-allocating files in bigfileset tree
0.047: Waiting for pre-allocation to finish (in case of a parallel pre-allocation)
0.047: Population and pre-allocation of filesets completed
0.049: Starting 1 filereader instances
9.063: Waiting for pid 8269 thread filereaderthread-1
10.063: Waiting for pid 8269 thread filereaderthread-1
11.064: Running...
11.064: Unexpected Process termination Code 3, Errno 0 around line 77
12.065: Run took 1 seconds...
12.065: Run took 1 seconds...

原因是系统打开了ASLR。
ASLR(Address Space Layout Randomization)在2005年被引入到Linux的内核 kernel 2.6.12 中,当然早在2004年就以patch的形式被引入。随着内存地址的随机化,使得响应的应用变得随机。这意味着同一应用多次执行所使用内存空间完全不同,也意味着简单的缓冲区溢出攻击无法达到目的。

使用root权限以及如下命令关闭ASLR。

1
echo 0 > /proc/sys/kernel/randomize_va_space

重新执行filebench程序:

root@szp-pc:/home/szp/workloads# filebench -f webserver.f 
Filebench Version 1.5-alpha3
0.002: Allocated 173MB of shared memory
0.018: Web-server Version 3.1 personality successfully loaded
0.019: Populating and pre-allocating filesets
0.021: logfiles populated: 1 files, avg. dir. width = 2, avg. dir. depth = 0.0, 0 leafdirs, 0.002MB total size
0.021: Removing logfiles tree (if exists)
0.025: Pre-allocating directories in logfiles tree
0.025: Pre-allocating files in logfiles tree
0.026: bigfileset populated: 10 files, avg. dir. width = 2, avg. dir. depth = 3.3, 0 leafdirs, 0.132MB total size
0.026: Removing bigfileset tree (if exists)
0.030: Pre-allocating directories in bigfileset tree
0.031: Pre-allocating files in bigfileset tree
0.033: Waiting for pre-allocation to finish (in case of a parallel pre-allocation)
0.033: Population and pre-allocation of filesets completed
0.035: Starting 1 filereader instances
1.052: Running...
61.333: Run took 60 seconds...
61.335: Per-Operation Breakdown
appendlog            160003ops     2654ops/s  20.7mb/s      0.1ms/op [0.00ms - 151.46ms]
closefile10          160003ops     2654ops/s   0.0mb/s      0.0ms/op [0.00ms -  0.19ms]
readfile10           160003ops     2654ops/s  16.0mb/s      0.0ms/op [0.00ms -  0.52ms]
openfile10           160003ops     2654ops/s   0.0mb/s      0.0ms/op [0.00ms -  1.19ms]
closefile9           160003ops     2654ops/s   0.0mb/s      0.0ms/op [0.00ms -  0.20ms]
readfile9            160003ops     2654ops/s  13.9mb/s      0.0ms/op [0.00ms -  0.33ms]
openfile9            160003ops     2654ops/s   0.0mb/s      0.0ms/op [0.00ms -  0.84ms]
closefile8           160003ops     2654ops/s   0.0mb/s      0.0ms/op [0.00ms -  0.30ms]
readfile8            160003ops     2654ops/s  30.3mb/s      0.0ms/op [0.00ms -  0.49ms]
openfile8            160003ops     2654ops/s   0.0mb/s      0.0ms/op [0.00ms -  0.88ms]
closefile7           160003ops     2654ops/s   0.0mb/s      0.0ms/op [0.00ms -  0.28ms]
readfile7            160003ops     2654ops/s  28.2mb/s      0.0ms/op [0.00ms -  0.71ms]
openfile7            160003ops     2654ops/s   0.0mb/s      0.0ms/op [0.00ms -  0.85ms]
closefile6           160003ops     2654ops/s   0.0mb/s      0.0ms/op [0.00ms -  0.18ms]
readfile6            160003ops     2654ops/s 125.5mb/s      0.0ms/op [0.00ms -  0.68ms]
openfile6            160003ops     2654ops/s   0.0mb/s      0.0ms/op [0.00ms -  1.47ms]
closefile5           160003ops     2654ops/s   0.0mb/s      0.0ms/op [0.00ms -  0.10ms]
readfile5            160003ops     2654ops/s   9.5mb/s      0.0ms/op [0.00ms -  0.25ms]
openfile5            160003ops     2654ops/s   0.0mb/s      0.0ms/op [0.00ms -  0.77ms]
closefile4           160003ops     2654ops/s   0.0mb/s      0.0ms/op [0.00ms -  0.18ms]
readfile4            160003ops     2654ops/s  58.3mb/s      0.0ms/op [0.00ms -  0.31ms]
openfile4            160003ops     2654ops/s   0.0mb/s      0.0ms/op [0.00ms -  1.12ms]
closefile3           160003ops     2654ops/s   0.0mb/s      0.0ms/op [0.00ms -  0.13ms]
readfile3            160003ops     2654ops/s  30.2mb/s      0.0ms/op [0.00ms -  0.20ms]
openfile3            160003ops     2654ops/s   0.0mb/s      0.0ms/op [0.00ms -  1.24ms]
closefile2           160003ops     2654ops/s   0.0mb/s      0.0ms/op [0.00ms -  0.17ms]
readfile2            160003ops     2654ops/s  26.7mb/s      0.0ms/op [0.00ms -  0.48ms]
openfile2            160003ops     2654ops/s   0.0mb/s      0.0ms/op [0.00ms -  2.47ms]
closefile1           160003ops     2654ops/s   0.0mb/s      0.0ms/op [0.00ms -  0.18ms]
readfile1            160003ops     2654ops/s  12.0mb/s      0.0ms/op [0.00ms -  0.25ms]
openfile1            160003ops     2654ops/s   0.0mb/s      0.0ms/op [0.00ms -  0.76ms]
61.335: IO Summary: 4960093 ops 82283.522 ops/s 26543/2654 rd/wr 371.3mb/s   0.0ms/op
61.335: Shutting down processes

结果分析:

  • flowop name - 支持的flowop(测试流程)有很多

  • 所有threads的ops

  • 所有threads的ops / run time

  • 所有threads的READ/WRITE带宽

  • 所有threads的每个op的平均latency

  • 测试中op的最小和最大latency

3.测试程序解释

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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# 自定义变量
set $dir=/home/szp/test
set $nfiles=10
set $meandirwidth=2
set $filesize=cvar(type=cvar-gamma,parameters=mean:16384;gamma:1.5)
set $nthreads=1
set $iosize=1m
set $meanappendsize=16k
# 设置退出模式,支持[ timeout | alldone | firstdone ]
set mode quit firstdone

# fileset:定义一组测试中用的files
# name=bigfileset:必须指定 - fileset的名称,后面flowop中用到
# path=$dir:必须指定 - 创建测试文件的目录
# size=$meanfilesize:可选,关键字也可以为filesize,默认为1KB - 测试文件的size
# entries=$nfiles:可选,默认位1024 - fileset中的file个数
# dirwidth=$meandirwidth:可选,默认为0 - 每个目录中创建的file个数


define fileset name=bigfileset,path=$dir,size=$filesize,entries=$nfiles,dirwidth=$meandirwidth,prealloc=100,readonly
define fileset name=logfiles,path=$dir,size=$filesize,entries=1,dirwidth=$meandirwidth,prealloc

# process:定义处理过程
# name=filecreate:必须指定 - 处理过程的名称
# instances=1:可选,默认为1 - 处理过程的进程数
define process name=filereader,instances=1
{
# thread:process中的一个thread
# name=filecreatethread:必须指定 - 处理线程的名称
# memsize=10m:必须指定 - 线程启动后初始化为0的内存大小,用于read/write flowop
# instances=$nthreads:可选,默认为1 - 创建的线程数
thread name=filereaderthread,memsize=10m,instances=$nthreads
{

# flowop:定义处理流程中的每一步
# createfile/writewholefile/closefile:flowop的关键字,每个代表不同的操作
# name=$name:flowop的名称
# filesetname=bigfileset:指定op操作的fileset
# fd=1:指定file descriptor的值,在应用允许文件被多次open的场景中有用
# iosize=$iosize:指定读写的iosize
flowop openfile name=openfile1,filesetname=bigfileset,fd=1
flowop readwholefile name=readfile1,fd=1,iosize=$iosize
flowop closefile name=closefile1,fd=1
flowop openfile name=openfile2,filesetname=bigfileset,fd=1
flowop readwholefile name=readfile2,fd=1,iosize=$iosize
flowop closefile name=closefile2,fd=1
flowop openfile name=openfile3,filesetname=bigfileset,fd=1
flowop readwholefile name=readfile3,fd=1,iosize=$iosize
flowop closefile name=closefile3,fd=1
flowop openfile name=openfile4,filesetname=bigfileset,fd=1
flowop readwholefile name=readfile4,fd=1,iosize=$iosize
flowop closefile name=closefile4,fd=1
flowop openfile name=openfile5,filesetname=bigfileset,fd=1
flowop readwholefile name=readfile5,fd=1,iosize=$iosize
flowop closefile name=closefile5,fd=1
flowop openfile name=openfile6,filesetname=bigfileset,fd=1
flowop readwholefile name=readfile6,fd=1,iosize=$iosize
flowop closefile name=closefile6,fd=1
flowop openfile name=openfile7,filesetname=bigfileset,fd=1
flowop readwholefile name=readfile7,fd=1,iosize=$iosize
flowop closefile name=closefile7,fd=1
flowop openfile name=openfile8,filesetname=bigfileset,fd=1
flowop readwholefile name=readfile8,fd=1,iosize=$iosize
flowop closefile name=closefile8,fd=1
flowop openfile name=openfile9,filesetname=bigfileset,fd=1
flowop readwholefile name=readfile9,fd=1,iosize=$iosize
flowop closefile name=closefile9,fd=1
flowop openfile name=openfile10,filesetname=bigfileset,fd=1
flowop readwholefile name=readfile10,fd=1,iosize=$iosize
flowop closefile name=closefile10,fd=1
flowop appendfilerand name=appendlog,filesetname=logfiles,iosize=$meanappendsize,fd=2
}
}
# 开始运行filebench测试
# 格式:run [<runtime>],<runtime>不指定的话,默认为60s
echo "Web-server Version 3.1 personality successfully loaded"
run 60

PS:前往公众号“Linux工坊”,可以查看最新内容!关注即可免费领取面试&Linux技术书籍!

------ 本文结束------
  • 文章标题: 文件系统测试工具filebench
  • 本文作者: 你是我的阳光
  • 发布时间: 2021年03月13日 - 20:51:09
  • 最后更新: 2022年11月07日 - 16:45:00
  • 本文链接: https://szp2016.github.io/Linux/文件系统测试工具filebench/
  • 版权声明: 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
0%