Skip to main content

A tool to generate CPU load on a system with runtime configuration through a WebUI and REST API

Project description

CPU Loader

CI Build Wheels Python Version License

A high-performance CPU load generator with per-thread control through an intuitive WebUI and REST API. Built with a native C extension using pthreads for accurate, nanosecond-precision load generation.

✨ Key Features

  • 🎯 Precise Per-Thread Control: Set individual CPU load (0-100%) for each core independently
  • ⚡ High Performance: Native C implementation with pthreads ensures accurate load generation
  • 📊 Real-Time Monitoring: Live WebSocket updates showing actual CPU usage via psutil
  • 🎛️ Interactive WebUI: Beautiful gradient interface with sliders and visual feedback
  • 🚀 REST API: Complete programmatic control for automation and testing
  • 📱 Responsive Design: Works seamlessly on desktop and mobile devices
  • 🔄 Instant Updates: Changes take effect immediately with sub-second response time

🖼️ Screenshots

Desktop Interface

Initial view with zero load

Clean interface showing all CPU threads at idle

Mixed load across threads

Different load levels: 50%, 75%, and 25% on individual threads

Live CPU metrics updating

Real-time metrics showing actual CPU usage with color-coded bars

Mobile responsive view

Fully responsive mobile interface

Features Shown

  • Visual Load Bars: Green progress bars show target load, blue bars display actual CPU usage
  • Real-Time Updates: WebSocket connection provides live metrics every second
  • Preset Buttons: Quick-set options (0%, 25%, 50%, 75%, 100%) for all threads
  • Smooth Gradients: Modern UI with purple-to-blue gradient design

Installation

From Pre-built Wheels (Recommended)

Pre-compiled wheels are available for Linux (x86_64, ARM64) and macOS (x86_64, ARM64):

pip install cpu-loader

From Source

  1. Clone the repository:
git clone https://github.com/the78mole/cpu-loader.git
cd cpu-loader
  1. Install dependencies and build C extension:
uv pip install -e .

This will compile the high-performance C extension for efficient CPU load generation.

  1. (Optional) Set up pre-commit hooks for development:
pre-commit install
  1. (Optional) Set up commit message template for semantic versioning:
git config commit.template .gitmessage

See COMMIT_MESSAGE_FORMAT.md for commit message guidelines.

Usage

Starting the Server

uv run src/main.py

The server will start on http://localhost:8000

WebUI

Open your browser and navigate to http://localhost:8000

Features:

  • Individual Thread Control: Use sliders to set load for each thread (0-100%)
  • Preset Buttons: Quick-set all threads to 0%, 10%, 25%, 50%, 80%, 90%, or 100%
  • Live Stats: View active thread count and average load
  • Real-time Updates: Changes are applied instantly with visual feedback

REST API

Get Thread Status

curl http://localhost:8000/api/threads

Response:

{
  "num_threads": 4,
  "loads": {
    "0": 0.0,
    "1": 0.0,
    "2": 0.0,
    "3": 0.0
  }
}

Set Load for Specific Thread

curl -X PUT http://localhost:8000/api/threads/0/load \
  -H "Content-Type: application/json" \
  -d '{"load_percent": 50.0}'

Set Load for All Threads

curl -X POST http://localhost:8000/api/threads/load/all \
  -H "Content-Type: application/json" \
  -d '{"load_percent": 75.0}'

Change Number of Threads

curl -X POST http://localhost:8000/api/threads \
  -H "Content-Type: application/json" \
  -d '{"num_threads": 8}'

API Documentation

Once the server is running, visit http://localhost:8000/docs for interactive API documentation powered by Swagger UI.

Example Script

An example script (src/example.py) is provided to demonstrate programmatic control:

# Start the server first
uv run src/main.py

# In another terminal, run the example
uv run src/example.py

The example demonstrates:

  • Getting current status
  • Setting all threads to a specific load
  • Gradually increasing load
  • Individual thread control
  • Resetting to idle

Architecture

  • src/cpu_loader_core.c: High-performance C implementation using pthreads for CPU load generation
  • src/cpu_loader.py: Python wrapper providing a clean API to the C extension
  • src/main.py: FastAPI application with REST API and embedded WebUI
  • Threading Model: Native pthreads for maximum efficiency and precise timing
  • Load Algorithm: High-resolution busy-wait loops with nanosecond precision

Requirements

  • Python 3.8+
  • FastAPI 0.115.0+
  • Uvicorn 0.32.0+
  • Pydantic 2.10.0+
  • C compiler (gcc or clang) for building the extension

Use Cases

  • Performance Testing: Test application behavior under various CPU loads
  • Stress Testing: Validate system stability under high CPU utilization
  • Thermal Testing: Check cooling system effectiveness
  • Power Consumption Analysis: Measure power usage at different load levels
  • Benchmarking: Create reproducible load scenarios

Development

Pre-commit Hooks

This project uses pre-commit hooks to ensure code quality. The hooks include:

  • Code Formatting: Black and isort for consistent Python formatting
  • Linting: Flake8 for code quality checks
  • Type Checking: Mypy for static type analysis
  • General Checks: Trailing whitespace, end-of-file fixes, YAML/JSON/TOML validation

To run pre-commit manually on all files:

pre-commit run --all-files

The hooks will run automatically on git commit after installation.

Building and Publishing Releases

The project uses automatic semantic versioning with GitHub Actions:

Versioning Rules

Versions are automatically determined based on commit messages:

  • Patch bump (0.0.X): Every commit to main
  • Minor bump (0.X.0): Commits prefixed with feat:
    git commit -m "feat: add new CPU monitoring feature"
    
  • Major bump (X.0.0): Commits with major:, breaking:, or BREAKING CHANGE:
    git commit -m "major: redesign API interface"
    git commit -m "breaking: remove deprecated endpoints"
    

Release Process

  1. Commit and push to main:

    git add .
    git commit -m "feat: add WebSocket support"
    git push origin main
    
  2. Automated workflow:

    • Version is automatically calculated using semantic versioning
    • Wheels are built for Linux (x86_64, ARM64) and macOS (x86_64, ARM64)
    • Python versions: 3.8, 3.9, 3.10, 3.11, 3.12
    • Source distribution (sdist) is created
    • All artifacts are published to PyPI
    • A GitHub Release is created with version tag and artifacts

License

MIT License - see LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cpu_loader-0.0.3.tar.gz (14.4 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

cpu_loader-0.0.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (27.6 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

cpu_loader-0.0.3-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (27.9 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ ARM64

cpu_loader-0.0.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (27.5 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

cpu_loader-0.0.3-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (28.1 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ ARM64

cpu_loader-0.0.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (27.5 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

cpu_loader-0.0.3-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (28.0 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ ARM64

cpu_loader-0.0.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (27.3 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

cpu_loader-0.0.3-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (27.8 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ ARM64

cpu_loader-0.0.3-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (27.8 kB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

cpu_loader-0.0.3-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (28.3 kB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ ARM64

File details

Details for the file cpu_loader-0.0.3.tar.gz.

File metadata

  • Download URL: cpu_loader-0.0.3.tar.gz
  • Upload date:
  • Size: 14.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for cpu_loader-0.0.3.tar.gz
Algorithm Hash digest
SHA256 2853b8f07de8dbce43c37c4b6b2c0ce04a52fb96c4d1721877c7add293b7e637
MD5 1a6b0b94d907922253f016b9945baf1a
BLAKE2b-256 1b1fc2ee9451512612abf48e656e2d042f1d0ea165e6520db89bda44468f6129

See more details on using hashes here.

Provenance

The following attestation bundles were made for cpu_loader-0.0.3.tar.gz:

Publisher: build-wheels.yml on the78mole/cpu-loader

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cpu_loader-0.0.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for cpu_loader-0.0.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 7ba2818bf3e4f29d81887f597831c007c585319d6584151cde7946037dc7aa47
MD5 abe6cdd6da7df171ba2e01851c98f588
BLAKE2b-256 0440eef6035b64b053aaa63a6980170085c0aa0e4d0fb9e31afd5cbc31475c44

See more details on using hashes here.

Provenance

The following attestation bundles were made for cpu_loader-0.0.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: build-wheels.yml on the78mole/cpu-loader

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cpu_loader-0.0.3-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for cpu_loader-0.0.3-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 3c1c2cd7ed5b236cd63d8ec816e8000a8157b76c5473745062db7bb810710d27
MD5 e3ab36e048ad68c9105e2f21a891192a
BLAKE2b-256 c1ef41190d36a2dab59f8baa4b726da3697068758ac68af7fd65abc86e2a2497

See more details on using hashes here.

Provenance

The following attestation bundles were made for cpu_loader-0.0.3-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: build-wheels.yml on the78mole/cpu-loader

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cpu_loader-0.0.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for cpu_loader-0.0.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 707a3b3b42261d863b8177d7ec319d34588857008e4fa41b23f1755ac611dba1
MD5 badc9d745ab7136a625b777ebee99ec7
BLAKE2b-256 13c5dc5450b205000c8457973ea342f4ec1fe9b494032f90474725497fc77ae8

See more details on using hashes here.

Provenance

The following attestation bundles were made for cpu_loader-0.0.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: build-wheels.yml on the78mole/cpu-loader

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cpu_loader-0.0.3-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for cpu_loader-0.0.3-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 7c8be70e3e7e18757a148eb782c803e2ef3db9fdd6b24f81ccbb5ba0b9d2755b
MD5 bf019ffdbac30f3261682df42fb3d0fa
BLAKE2b-256 f89fc483136f60771c2491b87162f9c9fd7918afa7bce70871fef199720366c1

See more details on using hashes here.

Provenance

The following attestation bundles were made for cpu_loader-0.0.3-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: build-wheels.yml on the78mole/cpu-loader

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cpu_loader-0.0.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for cpu_loader-0.0.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8996e812c2f0e72437e8c6b32205e6b03732d4bb436c598047435119faf10c16
MD5 11bcac6f41bb21680f7cb5943a6b343a
BLAKE2b-256 ea0ce113ec1a715f32b994cb1dc167adf069e391e4e525578ef5bda3a4c2d2bc

See more details on using hashes here.

Provenance

The following attestation bundles were made for cpu_loader-0.0.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: build-wheels.yml on the78mole/cpu-loader

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cpu_loader-0.0.3-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for cpu_loader-0.0.3-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 6763d0367f43f7911e239da9ffa2452bec9800549bb2592714012556345ad67b
MD5 a5bb3f972742d5db216811ce96daef9c
BLAKE2b-256 90fe2b6dc6f37e413af9f9e58b03155b364cd2b84eeb05b24a3b30945003f64d

See more details on using hashes here.

Provenance

The following attestation bundles were made for cpu_loader-0.0.3-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: build-wheels.yml on the78mole/cpu-loader

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cpu_loader-0.0.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for cpu_loader-0.0.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2e24cbc5aab31978fadf004e4d32783ea943f705a21d181c8565105069adef97
MD5 97ab8643970ce3121e08265e84610bbd
BLAKE2b-256 b12957972a4f2109aa3751a224af9a09b0fbc42cc0bc5ac4e9b297df52eb9043

See more details on using hashes here.

Provenance

The following attestation bundles were made for cpu_loader-0.0.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: build-wheels.yml on the78mole/cpu-loader

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cpu_loader-0.0.3-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for cpu_loader-0.0.3-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 711553db03b9a761de9fd1086aee278c5747ffbb3b102dcd6fc6a9fe97738a7a
MD5 d06f6698e634b1282b01e6b14187228c
BLAKE2b-256 f9f53120b3a7248e48897cdc710595474917d6da34c6571b39dab85a24fcfbb0

See more details on using hashes here.

Provenance

The following attestation bundles were made for cpu_loader-0.0.3-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: build-wheels.yml on the78mole/cpu-loader

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cpu_loader-0.0.3-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for cpu_loader-0.0.3-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6d53fff71d95d76c6a45eaedd9721ecc068ab506def1b77db76fa384fc74e6a4
MD5 38e224b2591baa39eeb06153124dda85
BLAKE2b-256 67fb528ac0bf62b1fbd401fda66602ab78e604be96cd7dab0b1487a88c3236b7

See more details on using hashes here.

Provenance

The following attestation bundles were made for cpu_loader-0.0.3-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: build-wheels.yml on the78mole/cpu-loader

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cpu_loader-0.0.3-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for cpu_loader-0.0.3-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 60ef60c775113ba9b761db29aa2757ac2636d255d559d125b7a6ef18383a480f
MD5 fca3e6a438d698a10cb7365574980bca
BLAKE2b-256 58d94cdace05f294432249218b986a5b974c183556ebfa31ea94cfbac2601127

See more details on using hashes here.

Provenance

The following attestation bundles were made for cpu_loader-0.0.3-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: build-wheels.yml on the78mole/cpu-loader

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page