How to get read / write speed on disk in Python?

In the Python program, I need to get the accumulated read / write speeds of all the drives on the host. I did this using subprocess.check_output() to call the following Linux shell command:

 $ sudo hdparm -t /dev/sda 

This results in:

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

then I can make out 495.55. Ok, so far so good.

But on the hdparm man page, I found this explanation for the -t flag, which basically says that when taking measurements, no other process should read / write to disk at the same time:

Perform device reader timings for comparison and comparison. For significant results, this operation should be repeated 2-3 times otherwise in an inactive system (without any other active processes) with at least several megabytes of free memory. This displays the read speed through the buffer cache to disk without first caching data. This measurement is an indicator of how fast the drive can support serial data read in Linux without any overhead on the file system. To ensure accurate measurements, the buffer cache is flushed during -t processing using BLKFLSBUF ioctl.

Question :

How can I guarantee that no other process will access the disk at the same time when taking measurements?

+5
source share
1 answer

According to https://unix.stackexchange.com/questions/55212/how-can-i-monitor-disk-io, the most usable solution includes the sysstat or iostat tool (same package).

But seriously, since you have sudo permissions on the host, you can check if any intensive I / O tasks are working using any of the popular system monitoring tools. You cannot kill all AIs efficiently, even if your measurements also fail. Over a longer time period, the measurements should give you reasonable results, however, as the deviations converge towards a stable background noise.

Also, why do you need artificial measurements? If you just want to test the hardware capabilities without any RL context, do not mount the drive and test it in binary mode. Measurement in real motion occurs, as a rule, gives results that are closer to what you can really expect during boot.

+3
source

Source: https://habr.com/ru/post/1258399/


All Articles