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 tool to generate CPU load on a system with runtime configuration through a WebUI and REST API.

Features

  • 🔥 Controllable CPU Load: Generate precise CPU load per thread
  • 🎛️ Per-Thread Control: Individual sliders for each CPU thread
  • 🚀 REST API: Full programmatic control via HTTP endpoints
  • 🌐 Modern WebUI: Beautiful, responsive interface for real-time control
  • Instant Response: Changes take effect immediately
  • 📊 Live Monitoring: View active threads and average load in real-time

Screenshots

WebUI Interface

CPU Loader Control - 25% Load Individual thread control with sliders and preset buttons

CPU Loader Control - 50% Load Setting all threads to 50% load

CPU Loader Control - 100% Load Maximum load across all threads

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.2.tar.gz (14.0 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.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (27.2 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

cpu_loader-0.0.2-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (27.6 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ ARM64

cpu_loader-0.0.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (27.2 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

cpu_loader-0.0.2-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (27.7 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ ARM64

cpu_loader-0.0.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (27.1 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

cpu_loader-0.0.2-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (27.7 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ ARM64

cpu_loader-0.0.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (26.9 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

cpu_loader-0.0.2-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (27.4 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ ARM64

cpu_loader-0.0.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (27.4 kB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

cpu_loader-0.0.2-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (27.9 kB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ ARM64

File details

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

File metadata

  • Download URL: cpu_loader-0.0.2.tar.gz
  • Upload date:
  • Size: 14.0 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.2.tar.gz
Algorithm Hash digest
SHA256 f08f26fdc368275140d4061cb378c8d556401ceb05728ba1707b10eea7043139
MD5 1df034e2cc1617bda2df37397583fc8a
BLAKE2b-256 a095432a1b05cc8aa427496ede0d9cfefebf897904e507b88c39c5736447dd85

See more details on using hashes here.

Provenance

The following attestation bundles were made for cpu_loader-0.0.2.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.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for cpu_loader-0.0.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 191dab0c91202ba700c3894e8a9019b0d9145c9dfd9987384e5bd8f4da96dc78
MD5 ca6973f9ca74f4daf77714e5b821f776
BLAKE2b-256 476e170e284455908f7c88db18880807e0768f4d272b7cabd00d840a132e2c3f

See more details on using hashes here.

Provenance

The following attestation bundles were made for cpu_loader-0.0.2-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.2-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for cpu_loader-0.0.2-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 ff56df1a4ea8af04c22bcdb6e3d56a44c6706b4a4947d501a7293fc62f32031b
MD5 1c512fde11096a0a5889d70cb2ee7057
BLAKE2b-256 672ccbf3ce4163e66b7a9fbabdb458bca8e98d56a85c857320aafbb5abb22ebb

See more details on using hashes here.

Provenance

The following attestation bundles were made for cpu_loader-0.0.2-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.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for cpu_loader-0.0.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 59a4f76b4d3fadbce8c07e32a4255b5be5bfe55a22c2634eb1777d97e08fbf59
MD5 6549ba09beb1619cf19414eaae7583e4
BLAKE2b-256 fa6771e1f914957b805576f04d6cd0d334db400748802a5cc46741750c9943b8

See more details on using hashes here.

Provenance

The following attestation bundles were made for cpu_loader-0.0.2-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.2-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for cpu_loader-0.0.2-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 e5548be00151c7db1d65e01edb5082777a90ba437735c4be9c5b9164233c07c9
MD5 db825a33e631e765f9cb0c310eaf4515
BLAKE2b-256 f0983a0c478b68b0024576c94bc89c373f97c831018481bf9d3ee089db4541cc

See more details on using hashes here.

Provenance

The following attestation bundles were made for cpu_loader-0.0.2-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.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for cpu_loader-0.0.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 7ad62ef93d72da8d8bcb54df69a8bf6f712cfc1ff8af2fff789d7e3b12ccab09
MD5 e1b43667d0047aecee3a4b9dddadacbe
BLAKE2b-256 e175b9621e9295e72b76c036e5dd4f89e18e8926cc8ade3955b36c8c92265b6f

See more details on using hashes here.

Provenance

The following attestation bundles were made for cpu_loader-0.0.2-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.2-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for cpu_loader-0.0.2-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 5498e87a2c5f592441a269944f30fd80de0f048cfabf614b45c494f4cd3354aa
MD5 53463be2928d39c7ba33dad3da01ed71
BLAKE2b-256 6db31687fa71473eb196a54b09f0ecd98e2cb902dd832f31aed858f532e332d0

See more details on using hashes here.

Provenance

The following attestation bundles were made for cpu_loader-0.0.2-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.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for cpu_loader-0.0.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 091d91ee83d4d8fa1f1b3d357e30af9048a077b48f9dcb2d26fa3d0eb60a5a6d
MD5 cb5be012d5d00dcb6b9a126d563f95c1
BLAKE2b-256 ef03e4c2816951664250681c707e2a791b07d555cace51b91d83d0df46e00838

See more details on using hashes here.

Provenance

The following attestation bundles were made for cpu_loader-0.0.2-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.2-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for cpu_loader-0.0.2-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 fb2f9f87806410783d4b3df39171e1626825509e44b09501a83066870d306ebf
MD5 9ada7d5f51a26e0e644ad8b875da580a
BLAKE2b-256 cfc1f425a942cfa85cee1d69fb988c6d383744edd0013182578a201ff7bb64b4

See more details on using hashes here.

Provenance

The following attestation bundles were made for cpu_loader-0.0.2-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.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for cpu_loader-0.0.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 4d24c79b9cb49957fd187fd0898107025fa3514b6d542de59d264f5aae91d403
MD5 a3325e9850eae9019599dfb1d14ef1b6
BLAKE2b-256 7f6d7f088424f9ff4e03d3aec05ac3b3f1bcfd115a8bfe73295f67c02e7222a3

See more details on using hashes here.

Provenance

The following attestation bundles were made for cpu_loader-0.0.2-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.2-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for cpu_loader-0.0.2-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 fca7d48b69c7f9c342624240f186170a9513879964813a23d1d8a6f42e4e14ca
MD5 c3c586c41aade918871969987b6aabe3
BLAKE2b-256 c5aaa52c5c711195ece8d37cd9b9d4faf8503220180941a13a1c976cae149053

See more details on using hashes here.

Provenance

The following attestation bundles were made for cpu_loader-0.0.2-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