【问题标题】:Why iowait of reading file is zero?为什么读取文件的iowait为零?
【发布时间】:2020-04-02 00:19:46
【问题描述】:

找到psutil后,做了一个简单的实验。有一个完全 IO 基础函数,可以从文件中重复读取一些 numpy 数组(每个文件都有 763M 大小)。然后,在 100 秒后使用"cpu_times" 测量函数的使用时间。我预计大部分时间都在 iowait 上,但结果如下:

pcputimes(user=22.92, system=77.1, children_user=0.0, children_system=0.0, iowait=0.0)

为什么 iowait 为零?为什么系统的大部分时间都过去了?

代码如下:

def io_read_bound():
    i=0
    while True:
        a = np.load("/tmp/a%d.npy"%i)
        print(a.sum()) # for forcing use of data
        i = (i+1)%10

p = multiprocessing.Process(target=io_read_bound)
p.start()
ps = psutil.Process(p.pid)
time.sleep(100)
print(ps.cpu_times())

这个写numpy数组的实验结果是合理的,74%的时间都是为了iowait。

【问题讨论】:

    标签: python linux io psutil iowait


    【解决方案1】:

    psutil 作者在这里。可能文件已经在缓存中了?您可以尝试使用 vmtouch cmdline 实用程序来逐出文件缓存。 如果您多次读取文件并在每个循环中逐出缓存,我很确定计数器会增加。前段时间我介绍了 iowait 来试验文件副本,这是我当时的经验。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-04-03
      • 1970-01-01
      • 1970-01-01
      • 2022-08-14
      • 2021-10-22
      • 1970-01-01
      • 2012-02-26
      相关资源
      最近更新 更多