简体   繁体   English

如何在Python中获得读/写磁盘速度?

[英]How to get read/write disk speed in Python?

In a Python program I need to get the accumulated read/write speeds of all disks on the host. 在Python程序中,我需要获得主机上所有磁盘的累计读/写速度。 I was doing it with subprocess.check_output() to call the following Linux shell command: 我使用subprocess.check_output()来调用以下Linux shell命令:

$ sudo hdparm -t /dev/sda

This gives as a result: 这给出了结果:

/dev/sda:
 Timing buffered disk reads: 1488 MB in  3.00 seconds = 495.55 MB/sec

then I can parse the 495.55. 然后我可以解析495.55。 OK, so far so good. 好的,到目前为止一切顺利。

But on the man page of hdparm i found this explanation for the -t flag that basically says that when performing measurements no other process should read/write to disk at same time: 但是在hdparm的手册页上我找到了-t标志的这个解释,基本上说在执行测量时没有其他进程应该同时读/写磁盘:

Perform timings of device reads for benchmark and comparison purposes. 执行设备读取的时间以进行基准测试和比较。 For meaningful results, this operation should be repeated 2-3 times on an otherwise inactive system (no other active processes) with at least a couple of megabytes of free memory. 为了获得有意义的结果,此操作应在其他非活动系统(没有其他活动进程)上重复2-3次,并且至少有几兆字节的可用内存。 This displays the speed of reading through the buffer cache to the disk without any prior caching of data. 这将显示通过缓冲区高速缓存读取磁盘的速度,而无需事先缓存数据。 This measurement is an indication of how fast the drive can sustain sequential data reads under Linux, without any filesystem overhead. 此测量表明驱动器在Linux下可以维持顺序数据读取的速度,而不会产生任何文件系统开销。 To ensure accurate measurements, the buffer cache is flushed during the processing of -t using the BLKFLSBUF ioctl. 为确保准确测量,在使用BLKFLSBUF ioctl处理-t期间刷新缓冲区高速缓存。

The question is : 问题是

How can I ensure that no other process is accessing disk at the same time when measurements are performed? 如何在执行测量时确保没有其他进程同时访问磁盘?

According to https://unix.stackexchange.com/questions/55212/how-can-i-monitor-disk-io the most usable solution includes the tool sysstat or iostat (same package). 根据https://unix.stackexchange.com/questions/55212/how-can-i-monitor-disk-io ,最有用的解决方案包括工具sysstat或iostat(相同的包)。

But seriously, since you have sudo permissions on the host, you can check yourself whether any IO intensive tasks are going on using any of the popular system monitoring tools. 但严重的是,由于您在主机上拥有sudo权限,因此您可以使用任何常用的系统监视工具自行检查是否有任何IO密集型任务。 You cannot kill all IO effectively without your measurements also going nuts. 如果没有您的测量结果,您也无法有效地杀死所有IO。 Over a longer time the measurements should give you reasonable results nonetheless, since the deviations converge towards stable background noise. 在较长时间内,测量应该给出合理的结果,因为偏差会收敛到稳定的背景噪声。

Aside from that what would you need artificial measurements for? 除此之外,您需要进行人工测量? If you simply want to test the hardware capabilities without any RL context, do not mount the disk and test it in binary mode. 如果您只想在没有任何RL上下文的情况下测试硬件功能, 请不要安装磁盘并以二进制模式进行测试。 A measurement while real traffic is going on usually gives you results that are closer to what you can actually expect at load times. 实际流量进行时的测量通常会使您的结果更接近加载时的实际预期结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM