目前我需要做一些吞吐量测试。我的硬件设置是,我有一个三星950 Pro连接到一个NVMe控制器,该控制器通过PCIe端口连接到主板。我有一个linuxnvme设备,它与我在文件系统上安装的设备相对应。在
我希望使用Python来实现这一点。我计划在安装SSD的文件系统上打开一个文件,记录时间,向文件写入一些n长度的字节流,记录时间,然后使用os模块文件操作实用程序关闭文件。这里有一个用于测量写吞吐量的函数。在def perform_timed_write(num_bytes, blocksize, fd):
"""
This function writes to file and records the time
The function has three steps. The first is to write, the second is to
record time, and the third is to calculate the rate.
Parameters
----------
num_bytes: int
blocksize that needs to be written to the file
fd: string
location on filesystem to write to
Returns
-------
bytes_per_second: float
rate of transfer
"""
# generate random string
random_byte_string = os.urandom(blocksize)
# open the file
write_file = os.open(fd, os.O_CREAT | os.O_WRONLY | os.O_NONBLOCK)
# set time, write, record time
bytes_written = 0
before_write = time.clock()
while bytes_written < num_bytes:
os.write(write_file, random_byte_string)
bytes_written += blocksize
after_write = time.clock()
#close the file
os.close(write_file)
# calculate elapsed time
elapsed_time = after_write - before_write
# calculate bytes per second
bytes_per_second = num_bytes / elapsed_time
return bytes_per_second
在/fsmnt/fs1安装SSD之后,我使用这个jobfile来测试吞吐量
^{pr2}$
我注意到Python函数返回的写入速度明显高于fio。因为Python是如此高的级别,所以您会放弃很多控制。我想知道Python是否在做一些事情来欺骗它的速度。有人知道为什么Python生成的写入速度会比fio生成的高出很多吗?在