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.

PID Regulator Block Diagram

๐Ÿ’ก Motivation

This project is ideal for:

๐Ÿง  Architecture

The system consists of:

๐Ÿงช 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.

50% Target CPU Load

๐Ÿ“Ž Resources


Thanks for checking out this project! Feel free to contribute or raise issues on the repository.