I am currently working on implementing a PI controller to manage the stress on the system's disk I/O. To accomplish this, I have written a Python code that generates the desired load. However, I am encountering an issue with the behavior of the controller. Once the target disk I/O stress percentage is reached, there is a slight overshoot, causing the stress to exceed the desired level (e.g., reaching 90% instead of the target of 85%). Following the overshoot, the stress remains constant, as depicted in the graph Graph. So my problem, overshoot is fine for me, I need overshoot but then I want it to decrease to 85% rather than remain constant. I also tried reading the file instead of writing but same behavior.
def generate_load(self, sleep_time):
current_stress = self.controller.getDisk()
target_stress = (self.controller.getDiskTarget())*100
stress_difference = (target_stress) - current_stress
target_size = int(stress_difference * 1024 * 1024) # Convert stress difference to bytes
interval = time.time() + self.period - sleep_time
while time.time() < interval:
#print("target",target_size)
with open("sample.txt", "wb") as f:
f.write(b"\0" * target_size)
try:
os.remove("sample.txt")
except OSError:
pass
#time.sleep(self.period / 10) # Adjusted sleep time based on interval impac
time.sleep(sleep_time) # Controller actuation
Below code shows how I am getting the Disk IO stats from the system
def getDiskUage(self):
p_io = psutil.Process()
io_counters = p_io.io_counters()
disk_usage_process = io_counters[2] + io_counters[3] # read_bytes + write_bytes
disk_io_counter = psutil.disk_io_counters()
disk_total = disk_io_counter[2] + disk_io_counter[3] # read_bytes + write_bytes
usage = math.ceil(disk_usage_process/disk_total * 1000)
return usage