加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

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

发布时间:2020-12-16 22:45:21 所属栏目:Python 来源:网络整理
导读:在Python程序中,我需要获得主机上所有磁盘的累计读/写速度.我使用subprocess.check_output()来调用以下Linux shell命令: $sudo hdparm -t /dev/sda 这给出了结果: /dev/sda: Timing buffered disk reads: 1488 MB in 3.00 seconds = 495.55 MB/sec 然后我

在Python程序中,我需要获得主机上所有磁盘的累计读/写速度.我使用subprocess.check_output()来调用以下Linux shell命令:

$sudo hdparm -t /dev/sda

这给出了结果:

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

然后我可以解析495.55.好的,到目前为止一切顺利.

但是在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. 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. To ensure accurate measurements,the buffer cache is flushed during the processing of -t using the BLKFLSBUF ioctl.

问题是:

如何在执行测量时确保没有其他进程同时访问磁盘?

最佳答案
根据https://unix.stackexchange.com/questions/55212/how-can-i-monitor-disk-io,最有用的解决方案包括工具sysstat或iostat(相同的包).

但严重的是,由于您在主机上拥有sudo权限,因此您可以使用任何常用的系统监视工具自行检查是否有任何IO密集型任务.如果没有您的测量结果,您也无法有效地杀死所有IO.在较长时间内,测量应该给出合理的结果,因为偏差会收敛到稳定的背景噪声.

除此之外,您需要进行人工测量吗?如果您只想在没有任何RL上下文的情况下测试硬件功能,请不要装入磁盘并以二进制模式进行测试.实际流量进行时的测量通常会使您的结果更接近加载时的实际预期结果.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读