# 🧪 Benchmarking a Server for Substrate/Polkadot

## ***Automatic Installation***

```bash
source <(curl -s https://raw.githubusercontent.com/validexisinfra/polkadot/main/install-benchmark.sh)
```

## ***Manual Installation***

#### ***Installing Rust and Dependencies***

```bash
sudo apt update && sudo apt install -y build-essential clang cmake pkg-config libssl-dev git curl unzip protobuf-compiler libclang-dev llvm-dev && curl https://sh.rustup.rs -sSf | sh -s -- -y && source $HOME/.cargo/env && rustup update stable && rustup target add wasm32-unknown-unknown && rustup component add rust-src

curl https://sh.rustup.rs -sSf | sh -s -- -y
source $HOME/.cargo/env
rustup update stable

rustup target add wasm32-unknown-unknown
rustup component add rust-src
```

#### *Install the benchmarking tool*

```bash
cargo install frame-omni-bencher
```

*Check that the installed version is available*

```bash
frame-omni-bencher --version
```

#### *Clone Polkadot SDK*

```bash
git clone https://github.com/paritytech/polkadot-sdk.git
cd polkadot-sdk
```

#### *Run build with the feature flag included*

```bash
cargo build --features runtime-benchmarks --release
```

#### *Locate the generated `.wasm`*

```bash
find target/ -name "*.wasm"
```

{% hint style="info" %}
Expected output:

* Westend:
  * `target/release/wbuild/westend-runtime/westend_runtime.compact.compressed.wasm`&#x20;
* Rococ&#x6F;**:**
  * &#x20;`target/release/wbuild/rococo-runtime/rococo_runtime.compact.compressed.wasm`
    {% endhint %}

#### *Download the frame-weight template*

```bash
mkdir -p scripts
curl https://raw.githubusercontent.com/paritytech/polkadot-sdk/refs/tags/polkadot-stable2412/substrate/.maintain/frame-weight-template.hbs \
  --output scripts/frame-weight-template.hbs
```

#### *Run the benchmarking tool to measure extrinsic weights*

```bash
frame-omni-bencher v1 benchmark pallet \
  --runtime target/release/wbuild/westend-runtime/westend_runtime.compact.compressed.wasm \
  --pallet pallet_balances \
  --extrinsic "*" \
  --template scripts/frame-weight-template.hbs \
  --output weights.rs
```

#### *Result*

Benchmark results will be saved in **weights.rs**

This file contains execution weights for the pallet's extrinsics, useful for evaluating node performance or preparing validator applications.

#### *Run hardware benchmark*

To benchmark server hardware performance:

```bash
cargo run --release --features=runtime-benchmarks --bin polkadot -- benchmark machine
```

This command evaluates system performance and prints results in the console.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://services.validexis.com/mainnets/polkadot/benchmarking-a-server-for-substrate-polkadot.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
