Performance Measurement

⏱️ Duration: 1.5–2 hours (hands-on) 📊 Difficulty: Intermediate 🎯 Hyperscale-rs Specific

Learning Objectives

After the hands-on lab, continue to libp2p then cryptography. Optional reading: Rust optimizations ties measurements to implementation idioms.

How performance is measured today

Hyperscale-rs measures performance in two main contexts: deterministic simulation (simulator + workload) and production (Prometheus metrics). The same consensus and execution logic runs in both; the difference is I/O (simulated time and network vs real libp2p and RocksDB) and what is instrumented.

Simulation

The simulator (hyperscale-sim) runs a controlled workload for a fixed duration (e.g. --seed 42 -s 2 -v 4 -d 60 --tps 1000). It collects:

Reports are produced by MetricsCollector / SimulationReport and printed at the end (and optionally a livelock report for stuck transactions). The simulation uses simulated time and a network simulator (configurable latency, no real validator QUIC/gossipsub mesh and no wallet HTTP—just in-memory delivery with optional fake latency).

Production (metrics crate + Prometheus)

In production, hyperscale_metrics defines a MetricsRecorder trait; hyperscale_metrics_prometheus implements it and is installed at startup. Recorded metrics include:

So in production you get real wall-clock latency, real network and disk behavior, and rich counters/gauges/histograms for debugging and capacity planning.

What simulation can miss vs real life

Simulation is excellent for correctness and deterministic regression, but it does not fully reflect production performance. Gaps include:

So: use simulation for throughput and latency trends and regression (e.g. “no slowdown after this change”), but always validate with production or production-like benchmarks (e.g. spammer against a local cluster with real network and storage).

Recommendations for additional performance measures

To close gaps and support both operations and development, consider the following.

Simulation

Production

Shared

Step-by-step: Instrument and measure with simulation

Follow these steps to add or use performance instrumentation and run the simulator to collect throughput and latency.

  1. Build and run the simulator. From the hyperscale-rs repo root: cargo build --release, then cargo run --release --bin hyperscale-sim -- --seed 42 -s 2 -v 4 -d 60 --tps 1000. This runs 2 shards, 4 validators per shard, 60 seconds of simulated time, with a target of 1000 TPS. The binary uses SimulationRunner and MetricsCollector; no extra instrumentation is required for built-in metrics.
  2. Read the simulation report. At the end of the run, SimulationReport::print_summary() prints: Submitted / Completed / Rejected / Retries / In-flight; Average TPS and Peak TPS; P50 / P90 / P99 / Max / Avg latency; peak lock contention (locked nodes, deferred count, contention ratio). Use this to judge throughput and tail latency for the workload and parameters.
  3. Vary parameters to measure behavior. Change -s (shards), -v (validators), -d (duration), and --tps to see how TPS and latency change. For example: -s 1 -v 4 -d 30 --tps 500 for a single-shard baseline; -s 2 -v 4 -d 60 --tps 2000 to stress cross-shard. Compare reports to spot regressions or scaling limits.
  4. Add a custom metric in simulation (optional). Extend MetricsCollector in the simulator metrics module (see study table) with a new field and record_*; update SimulationReport and finalize / print_summary. Call your recorder where the sim observes the event.
  5. Add a metric used in both sim and production (optional). Define the semantic on the shared MetricsRecorder trait in the metrics crate; implement it in the Prometheus backend; call hyperscale_metrics::record_*(...) from production paths. The simulator’s report uses MetricsCollector — align naming with the study table paths or install a no-op recorder in sim if you call record_* from both worlds.
  6. Optional: livelock report. After run_for, call analyze_livelocks() on the runner and print_summary() on the returned report to see stuck or deferred transactions and potential cycles. This helps interpret high in-flight or low completion rate.

Summary: run hyperscale-sim with chosen -s -v -d --tps, read the printed report for TPS and latency, vary parameters to compare; optionally extend MetricsCollector or the shared MetricsRecorder and wire calls from the right code paths.

Suggested crates / files to study

Paths relative to the hyperscale-rs repo root (crate names may vary slightly if the workspace is reorganized).

Focus Path
Metrics trait + record_* crates/metrics (hyperscale_metrics) — MetricsRecorder, storage / consensus / execution / network / sync / fetch / backpressure / livelock
Prometheus backend crates/metrics-prometheus — counters, gauges, histograms (e.g. block_commit_latency, transactions_finalized, rocksdb_read_latency)
Simulator report crates/simulator — workload, run_for, MetricsCollector, SimulationReport; crates/simulator/src/metrics/mod.rs — report + print_summary
Storage metrics hooks crates/storage-rocksdbrecord_storage_read, record_storage_write, record_block_persisted, …
Tx finalized metric crates/node/src/shard/actions.rsrecord_transaction_finalized(latency_secs, cross_shard)

Hands-on: measure with hyperscale-sim

You will run the simulator, capture the built-in SimulationReport, and compare two runs—no quiz. Keep a short lab journal (copy/paste the summary block each time). Requires a local hyperscale-rs clone and release build.

Lab 1 — Baseline run

From the repository root:

cargo build --release
cargo run --release --bin hyperscale-sim -- --seed 42 -s 2 -v 4 -d 60 --tps 1000

In your journal, record:

Lab 2 — Parameter sweep (compare two runs)

Run a second configuration and compare to Lab 1. Example stress run:

cargo run --release --bin hyperscale-sim -- --seed 42 -s 1 -v 4 -d 30 --tps 2000

Write 3–5 sentences: which metric moved most (TPS vs P99 vs rejections), and one hypothesis tied to -s, --tps, or duration—not guesswork about unrelated subsystems.

Lab 3 — Map sim metrics to code (15 min read-only)

Open crates/simulator/src/metrics/mod.rs and find where print_summary formats TPS and latency. Then skim one production hook: record_transaction_finalized in crates/node/src/shard/actions.rs (study table above).

In your journal, complete:

Lab 4 — Optional: production metrics inventory

If you have run a production node with Prometheus enabled, list three metric names (or grep record_ in crates/metrics-prometheus) that have no analogue in the sim summary. If not, grep instead:

rg 'fn record_' crates/metrics-prometheus/src -n | head -20

Pick three functions and note what each measures in plain language.

What “done” looks like