CPU Load Generator Project
Welcome to the CPU Load Generator project โ a Python-based tool that generates a fixed CPU load for a finite period using a PID regulator.
๐ก Motivation
This project is ideal for:
- Performance Testing
- Resource Allocation Optimization
- Benchmarking
- Education & Training
- Thermal & Power Analysis
๐ง Architecture
The system consists of:
- CPU Target Load
- Monitor Thread for actual CPU usage measurement
- Controller Thread (PID regulator)
- Actuator adjusting sleep time for control
- Disturbances (e.g., other processes)
๐งช Monitor Thread
Uses psutil
to sample CPU load:
psutil.cpu_percent(interval)
This blocks the thread for the sampling interval, ensuring timing consistency.
๐ง Controller Thread (PID Regulator)
Calculates a control signal to modulate load. If error is positive (load too low), it reduces sleep to increase load, and vice versa.
def generate_load(self, sleep_time):
interval = time.time() + self.period - sleep_time
while time.time() < interval:
pr = 213123
_ = pr * pr
pr += 1
time.sleep(sleep_time)
Tuned experimentally with kp
and ki
.
๐ Results
The figure below shows the controller maintaining 50% CPU load.
๐ Resources
Thanks for checking out this project! Feel free to contribute or raise issues on the repository.