[关闭]
@ljm 2018-01-03T01:08:03.000000Z 字数 1205 阅读 868

httperf benchmark辅助程序

experiment


辅助程序

描述一下程序的功能需求吧:
从命令行输入一个目录,访问这个目录下的所有非目录文件,将所有的文件名shuffle,然后将shuffle后的文件名放入一个文本文件中,在文本之中,不同的文件名之间用'\0'间隔开。

python代码如下:

  1. #!/usr/bin/python
  2. import sys
  3. import os
  4. import random
  5. if __name__ == "__main__":
  6. basepath = sys.argv[1] # get the path
  7. listfile = []
  8. dirs = os.listdir(basepath)
  9. for file in dirs:
  10. filepath = basepath + file
  11. if(os.path.isfile(filepath)):
  12. listfile.append(file) # only remain the file name in the list
  13. random.shuffle(listfile) # shuffle the list
  14. length = len(listfile) # writre the string list to file,and the seperate between the string is NUL
  15. f = open("wlog.log", "w")
  16. i = 1
  17. for file in listfile:
  18. f.write('/'+file+'\0')
  19. f.write('\0')

运行代码:

chmod a+x test.py

sudo ./test.py /var/www/html/

sudo chmod 777 wlog.log

结果保留在wlog.log中

生成文本文件

crfile可以生成文本文件。
autobench官网下载autobench压缩包并安装,其自带crfile。
用法:
crfile -f filename -s size

demo:
crfile -f test1.txt -s 4096

生成测试数据

编写了shell程序,生成测试数据:

  1. #!/bin/bash
  2. num_of_files=$1
  3. min_size=$2
  4. max_size=$3
  5. rm text*.txt
  6. for (( c=1; c<=num_of_files; c++ ))
  7. do
  8. size=$(shuf -i $min_size-$max_size -n 1)
  9. crfile -f text$c.txt -s $size
  10. done

usage:
1. chmod +x ./test.sh
2. ./test.sh 1000 1024 2048
- 第一个参数为生成文本文件的数目
- 第二个参数为文本文件size的最小值(以byte为单位)
- 第三个参数为文本文件size的最大值(以byte为单位)

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注