forked from opencurve/curve
-
Notifications
You must be signed in to change notification settings - Fork 0
/
perf_test.py
133 lines (118 loc) · 4.28 KB
/
perf_test.py
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import time
import subprocess
import time
import sys
def run_exec(cmd, lock=None):
'''
@param log_id
@param cmd
@param lock
@return: None
'''
try:
if lock:
lock.acquire()
ret_code = subprocess.call(cmd, shell=True)
except Exception as e:
raise e
finally:
if lock:
lock.release()
if ret_code == 0:
return 0
else:
return -1
class CFioCfg:
rw = 'randrw'
direct = 1
numjobs = 1
ioengine = 'psync'
#ioengine = 'libaio'
bsrange = '4k-4k'
iops = 0
runtime = 300
ramp_time = 5
rwmixwrite = 30
rwmixread = -1
cfgPath = ''
device = ''
# configure your own information
#The performance test results will be saved in the execution directory perf-test
size = '50G'
testpath = '/home/curvefs'
filenum = 5
def writeCfg(self):
if (self.rw == 'randrw' or self.rw == 'rw') and self.rwmixwrite > 0:
self.cfgName = "%s_mixwrite%d_%s_%03djobs_iops%06d.cfg" % (self.rw, self.rwmixwrite, self.bsrange, self.numjobs, self.iops)
elif (self.rw == 'randrw' or self.rw == 'rw') and self.rwmixread > 0:
self.cfgName = "%s_mixread%d_%s_%03djobs_iops%06d.cfg" % (self.rw, self.rwmixread, self.bsrange, self.numjobs, self.iops)
else:
self.cfgName = "%s_%s_%03djobs_iops%06d.cfg" % (self.rw, self.bsrange, self.numjobs, self.iops)
f = open(self.cfgPath + '/' + self.cfgName, "w")
f.write("[global]\n")
f.write("rw=%s\n" % self.rw)
if (self.rw == 'randrw' or self.rw == 'rw') and self.rwmixwrite >0:
f.write("rwmixwrite=%d\n" % self.rwmixwrite)
elif (self.rw == 'randrw' or self.rw == 'rw') and self.rwmixread >0:
f.write("rwmixread=%d\n" % self.rwmixread)
f.write("direct=%d\n" % self.direct)
f.write("size=%s\n" % self.size)
f.write("numjobs=%d\n" % self.numjobs)
# f.write("iodepth=%d\n" % self.numjobs)
f.write("ioengine=%s\n" % self.ioengine)
f.write("bsrange=%s\n" % self.bsrange)
if self.iops > 0:
f.write("rate_iops=%d\n" % (self.iops / self.numjobs))
f.write("ramp_time=%d\n" % self.ramp_time)
f.write("runtime=%d\n" % self.runtime)
f.write("group_reporting\n")
for i in range(0,self.filenum):
j = i + 1
f.write("\n[disk0%d]\n"%j)
f.write("filename=%s/%d.txt\n"%(self.testpath,j))
f.close()
def getCfgName(self):
return self.cfgName
if __name__ == "__main__":
cfg = CFioCfg()
cfg.runtime = 300
cfg.ramp_time = 10
deviceFlag = 0
deviceList = ['']
deviceList[0] = cfg.testpath
testBasePath = 'perf-test'
testCfgPath = '%s/cfg' % testBasePath
testFioDataPath = '%s/fiodata' % testBasePath
if not os.path.isdir(testBasePath):
os.makedirs(testBasePath)
if not os.path.isdir(testCfgPath):
os.makedirs(testCfgPath)
if not os.path.isdir(testFioDataPath):
os.makedirs(testFioDataPath)
# rand test
for bsrange in ['512k-512k','128k-128k','4k-4k']:
for numjobs in [1,4]:
for rw in ['write','read','randwrite','randread']:
cfg.rwmixwrite = 30
for iops in [000]:
cfg.rw = rw
cfg.iops = iops
cfg.numjobs = numjobs
cfg.bsrange = bsrange
cfg.cfgPath = testCfgPath
# set device name
deviceIndex = deviceFlag % len(deviceList)
cfg.device = deviceList[deviceIndex]
cfg.writeCfg()
cfgFileName = cfg.getCfgName()
ts = time.strftime("%Y%m%d%H%M%S", time.localtime(time.time()))
print "================ %s_%s ================" % (cfgFileName[:-4], ts)
cmd = " sudo fio %s/%s | tee -a %s/%s_%s.txt 2>&1" % (testCfgPath, cfgFileName, testFioDataPath, cfgFileName[:-4], ts)
print cmd
clear = "echo 3 | sudo tee -a /proc/sys/vm/drop_caches"
os.system(clear)
os.system(cmd)
deviceFlag = deviceFlag + 1