Skip to content

Instantly share code, notes, and snippets.

@YoungForest YoungForest/disk_read.py
Last active Jan 14, 2017

Embed
What would you like to do?
硬盘读操作压力测试
import time
import sys
def main():
if (len(sys.argv) != 3):
sys.exit("Ususage: %s diskname level.(level can be 0, 1, 2, 3, Bigger level means higer disk read speed.)" %(sys.argv[0]))
disk = sys.argv[1]
# disk = r'/dev/vda'
if sys.argv[2] == '0':
speed = 10
elif sys.argv[2] == '1':
speed = 50
elif sys.argv[2] == '2':
speed = 100
elif sys.argv[2] == '3':
speed = 200
else:
sys.exit("Level has to be 0, 1, 2 or 3")
speed = 1024 * 1024 * speed
with open(disk, 'rb+') as f:
f.seek(0)
while True:
start = time.clock()
d = f.read(speed)
if len(d) <= 0:
break
end = time.clock()
if 1 > end - start:
time.sleep(1 - (end - start))
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.