Search code examples
pythonlinuxiopsutiliowait

Why iowait of reading file is zero?


After finding the psutil, I had a simple experiment. There is a completely IO base function that repeatedly reads some numpy array from files (each of them has 763M size). Then, time usage of the function is measured using "cpu_times" after 100 seconds. I expect most of the time elapse on iowait, But the result is as below:

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

Why the iowait is zero? Why most of the time is elapsed for system?

The code is as below:

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())

The result of this experiment for writing numpy arrays is reasonable, and 74% of the time is for iowait.


Solution

  • psutil author here. Probably the file is already in cache? You can try using vmtouch cmdline utility to evict the file cache. If you read the file multiple times and evict the cache at each loop am pretty sure the counter will increase. I introduced iowait to experiment with file copies some time ago and this was my experience at the time.