Skip to content

Commit 7011558

Browse files
committed
Updates and release test_cpu_parallel Rust v 1.3.1
1 parent 0489007 commit 7011558

7 files changed

Lines changed: 162 additions & 123 deletions

File tree

Performance_Testing/Test_CPU_parallel_Rust/Code_test_CPU_Rust/Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "test_cpu_parallel"
3-
version = "1.3.0" # bump every time you publish
3+
version = "1.3.1" # bump every time you publish
44
edition = "2021"
55
rust-version = "1.74" # MSRV; pick the oldest version you test on
66
description = "Generate CPU- or memory-intensive workloads for benchmarking."
@@ -20,6 +20,9 @@ include = [
2020
"LICENSE"
2121
]
2222

23+
[lib]
24+
path = "src/lib.rs"
25+
2326
[dependencies]
2427
# Libraries used in this project
2528
rayon = "1.10.0" # High-performance data parallelism and thread pool library
Lines changed: 88 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,100 @@
1-
## CPU load testing kit in Rust
2-
`test_cpu_parallel` is basic CPU workload generator written in Rust.
3-
It runs a CPU-burning loop using multithreading, with configurable parallelism degree.
1+
# test_cpu_parallel – CPU & Memory Load Generator in Rust
42

5-
More Detailed instructions available at [Project homepage:](../README.md)
3+
[![crate](https://img.shields.io/crates/v/test_cpu_parallel.svg)](https://crates.io/crates/test_cpu_parallel)
4+
[![docs.rs](https://docs.rs/test_cpu_parallel/badge.svg)](https://docs.rs/test_cpu_parallel)
65

7-
----
8-
Compile the tool using Rust with: `cargo build`
9-
- Using `cargo build --release` is not recommended for this tool,
10-
as the optimizations play against the simple "CPU burning loop" implemented in the tool
11-
- The Cargo version used for compiling has an impact on the output, notably the performance of the tool.
12-
- Version 1.3.0, compiled with Cargo version 1.86.0
6+
`test_cpu_parallel` is a **small, zero‑dependency load‑testing kit**. It can:
137

14-
Note: To compile a Rust project, you need to have the Rust programming language and its associated
15-
tools installed on your system. If you haven't installed Rust yet, you can do so by following
16-
the instructions at https://www.rust-lang.org/tools/install
8+
* load cores to verify scaling or system/container limits
9+
* sweep 1 → *N* threads and export a tidy CSV for speed‑up plots
10+
* hammer the memory hierarchy with random‑access touches beyond the LLC
11+
* run **stand‑alone** from the CLI *or* be **embedded** in your own Rust code
1712

18-
Examples:
19-
```
20-
# Run data collection with parallelism 2
21-
./test_cpu_parallel -w 2
13+
A two‑minute build, no external data files, works on Linux, macOS and Windows.
14+
15+
Link to the [Project page](https://github.com/LucaCanali/Miscellaneous/tree/master/Performance_Testing/Test_CPU_parallel_Rust)
16+
17+
---
18+
## 📦 Installation
2219

23-
# Get the help message
24-
./test_cpu_parallel --help
20+
| what you want | command |
21+
|------------------------------|---------|
22+
| **CLI binary** (optimised) | `cargo install test_cpu_parallel` |
23+
| **Library** in an app / lib | `cargo add test_cpu_parallel` |
24+
| **Dev build from source** | `git clone … && cargo build` |
2525

26-
Use test_cpu_parallel to generate CPU-intensive load on a system
27-
The tool runs multi-threaded loops with configurable parallelism
28-
Two workload types are implemented: CPU-intensive (default) and memory-intensive
29-
The output reports measurements of the workload execution time as a function of load
30-
Project homepage: https://github.com/LucaCanali/Miscellaneous/tree/master/Performance_Testing/Test_CPU_parallel_Rust
26+
> **Note** For benchmark *accuracy* the CLI defaults to an **un‑optimised** `opt‑level = 0` build. If you install with `cargo install` a `--release` build is produced; results will differ slightly. Re‑compile locally with `cargo build` to reproduce blog numbers.
3127
32-
Example:
33-
./test_CPU_parallel --num_workers 2
28+
---
29+
## ⚡ CLI quick‑start
3430

31+
```bash
32+
# Burn four threads for a few seconds
33+
$ test_cpu_parallel -w 4
34+
35+
# Sweep 1 → 16 threads, write CSV
36+
$ test_cpu_parallel --num_workers 16 --full -o results.csv
37+
38+
# Stress memory with 8 workers and a 512 MiB buffer
39+
$ test_cpu_parallel -w 8 --mode memory --memory_size 512
40+
```
3541

42+
Run `test_cpu_parallel --help` for the complete flag list (excerpt below).
43+
44+
```text
3645
Usage: test_cpu_parallel [OPTIONS]
46+
-w, --num_workers <N> parallel threads (default 2)
47+
-m, --mode <cpu|memory> workload type (default cpu)
48+
-f, --full sweep 1‥=N threads
49+
-o, --output_file <PATH> write CSV (full mode)
50+
--memory_size <MiB> buffer for memory test (default 1024)
51+
```
52+
53+
---
54+
## 📚 Library usage
55+
56+
Embed the engine in unit tests, benchmarks or monitoring agents:
57+
58+
```rust
59+
use test_cpu_parallel::TestCPUParallel;
3760

38-
Options:
39-
-f, --full
40-
Full mode will test all the values of num_workers from 1 to the value set with --num_workers, use this to collect speedup test measurements and create plots, default = False
41-
-w, --num_workers <num_workers>
42-
Number of parallel threads running concurrently [default: 2]
43-
-o, --output_file <output_file>
44-
Optional output file, applies only to the full mode [default: ]
45-
-m, --mode <mode>
46-
Specifies the workload mode: 'cpu' for CPU-intensive or 'memory' for memory-intensive [default: cpu] [possible values: cpu, memory]
47-
--num_job_execution_loops <num_job_execution_loops>
48-
Number of times the execution loop is run on each worker [default: 3]
49-
--worker_inner_loop_size <worker_inner_loop_size>
50-
Number of iterations in the inner loop of the worker thread [default: 1000]
51-
--memory_size <memory_size>
52-
Size of the buffer used by the 'memory' mode in MB, rounded to next power of 2 if needed. [default: 1024]
53-
-h, --help
54-
Print help
55-
-V, --version
56-
Print version
61+
fn main() -> anyhow::Result<()> {
62+
// 4 workers, one batch, memory workload, 64 MiB buffer
63+
let bench = TestCPUParallel::new(4, 1, 1_000, "", 64);
64+
let (thread_stats, batch_stats) = bench.test_one_load(None, "memory")?;
65+
println!("Per‑thread stats: {thread_stats:?}");
66+
println!("Per‑batch stats: {batch_stats:?}");
67+
Ok(())
68+
}
5769
```
70+
71+
API docs are hosted on **[docs.rs/test_cpu_parallel](https://docs.rs/test_cpu_parallel)**.
72+
73+
---
74+
## 🔧 Building from source
75+
76+
```bash
77+
# Clone and build a debug binary (recommended for comparable timings)
78+
$ git clone https://github.com/LucaCanali/Miscellaneous.git
79+
$ cd Miscellaneous/Performance_Testing/Test_CPU_parallel_Rust
80+
$ cargo build # ≈ 35 s on a modern laptop
81+
```
82+
83+
* Tested on Rust **1.74+** – that is the MSRV.
84+
* Setting `cargo build --release` enables heavy optimisations and changes loop timing; avoid if you care about exact comparability.
85+
86+
---
87+
## 📊 Analysing the CSV
88+
89+
Full‑mode output is a single CSV line per thread count, ready to feed into
90+
Python/pandas, gnuplot or Excel. See the `Notebooks/` directory in the repo for ready‑made Jupyter notebooks that plot speed‑up and efficiency curves.
91+
92+
---
93+
## More
94+
95+
* Project page & extended docs – <https://github.com/LucaCanali/Miscellaneous/tree/master/Performance_Testing/Test_CPU_parallel_Rust>
96+
* Blog article that motivated the tool – <https://db-blog.web.cern.ch/node/189>
97+
* Licence – **Apache‑2.0**
98+
99+
Enjoy hacking your CPUs 🔥
100+
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
//! test_cpu_parallel – library API
2+
//!
3+
//! See the README for a quick example.
4+
5+
pub mod test_cpu_parallel;
6+
pub use test_cpu_parallel::TestCPUParallel;

Performance_Testing/Test_CPU_parallel_Rust/Code_test_CPU_Rust/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use clap::{Command, Arg};
1414

1515
fn main() {
1616
let args = Command::new("test_cpu_parallel - A basic CPU workload generator written in Rust")
17-
.version("1.3.0")
17+
.version("1.3.1")
1818
.author("Luca.Canali@cern.ch")
1919
.about(r#"
2020
Use test_cpu_parallel to generate CPU-intensive load on a system

Performance_Testing/Test_CPU_parallel_Rust/Container/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# A basic CPU workload generator
33
# See https://github.com/LucaCanali/Miscellaneous/tree/master/Performance_Testing/Test_CPU_parallel_Rust
44

5-
FROM ubuntu:22.04
5+
FROM ubuntu:24.04
66

77
# The main goal of this container is to be used for running /opt/test_cpu_parallel
88
COPY test_cpu_parallel /opt/test_cpu_parallel

Performance_Testing/Test_CPU_parallel_Rust/Container/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@ tool written in Rust.
1212
wget https://sparkdltrigger.web.cern.ch/sparkdltrigger/test_cpu_parallel/test_cpu_parallel
1313
chmod +x test_cpu_parallel
1414
15-
# Checksum:
15+
# Checksum for test_cpu_parallel V 1.3.0:
1616
# sha256sum test_cpu_parallel
17-
# 6feabf4c59765e463e65e7150cd5636063af9d946ab56b8b5b45151b712d27e2
17+
# 94f904160b0d03dbbd3d6a56892271fc6c82ad09c1ab416fae69a94451a62f2e
1818
```
1919
- Build the docker image with:
2020
```
21-
docker build -t lucacanali/test_cpu_parallel:v1.2 .
22-
docker push lucacanali/test_cpu_parallel:v1.2
21+
docker build -t lucacanali/test_cpu_parallel:v1.3 .
22+
docker push lucacanali/test_cpu_parallel:v1.3
2323

24-
docker tag lucacanali/test_cpu_parallel:v1.2 lucacanali/test_cpu_parallel:latest
24+
docker tag lucacanali/test_cpu_parallel:v1.3 lucacanali/test_cpu_parallel:latest
2525
docker push lucacanali/test_cpu_parallel:latest
2626
```
2727

0 commit comments

Comments
 (0)