如何在Linux中通过python进程限制磁盘I / O

问题描述

向SSD写入大量文件的Python程序和从同一SSD读取大量文件的python程序同时在Linux(ubuntu18.04,48vcpu)上运行。

读取文件的程序使用多进程,如下所示。

# read files
from concurrent.futures import ProcesspoolExecutor

def read_file(file_name):
    f = open(filename,"r")
    text = f.read()
    f.close()
    return text

file_list = [str(i) + "to_read.txt" for i in range(100000000)]

with ProcesspoolExecutor(max_workers=20) as executor:
    results = executor.map(read_file,file_list)
    results = list(results)

写入文件的程序也使用多进程执行。

# write files
from concurrent.futures import ProcesspoolExecutor

def write_file(file_name):
    f = open(filename,"w")
    f.write("test¥n")
    f.close()
    return text

file_list = [str(i) + "to_write.txt" for i in range(100000000)]

with ProcesspoolExecutor(max_workers=20) as executor:
    results = executor.map(write_file,file_list)
    results = list(results)

如果这两个程序同时运行,则一个程序将垄断SSD的I / O,而另一个程序的I / O将非常慢。

所以我希望这两个程序以50%的速率对SSD进行IO,但是如何限制这些使用多进程的Python程序的磁盘I / O?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)