2020-08-11 13:13:59 -04:00
<!--
2020-12-03 06:29:52 -05:00
Title: How to benchmark server performance using Speedtest and SysBench
Description: Learn how to benchmark server performance using Speedtest and SysBench.
2020-08-11 13:13:59 -04:00
Author: Sun Knudsen < https: / / github . com / sunknudsen >
Contributors: Sun Knudsen < https: / / github . com / sunknudsen >
2020-09-10 10:07:07 -04:00
Reviewers:
2020-08-11 13:13:59 -04:00
Publication date: 2020-07-31T12:39:56.670Z
2020-11-10 07:13:35 -05:00
Listed: true
2023-09-06 19:23:39 -04:00
Pinned:
2020-08-11 13:13:59 -04:00
-->
2020-12-03 06:29:52 -05:00
# How to benchmark server performance using Speedtest and SysBench
2020-08-11 13:13:59 -04:00
2023-09-06 19:28:21 -04:00
[](https://www.youtube.com/watch?v=zcq2iZUcQQY "How to benchmark server performance using Speedtest and SysBench")
2020-08-16 09:28:52 -04:00
2021-11-05 09:08:23 -04:00
> Heads-up: Speedtest is known for tracking users therefore it is recommended to run the following benchmark tests on staging servers.
2020-08-11 13:13:59 -04:00
## Requirements
2021-11-05 09:08:23 -04:00
- Virtual private server (VPS) or dedicated server running Debian 10 (buster) or Debian 11 (bullseye)
2020-08-11 13:13:59 -04:00
2020-08-25 07:40:01 -04:00
## Caveats
- When copy/pasting commands that start with `$` , strip out `$` as this character is not part of the command
- When copy/pasting commands that start with `cat << "EOF"` , select all lines at once (from `cat << "EOF"` to `EOF` inclusively) as they are part of the same (single) command
2020-12-31 10:35:49 -05:00
## Setup guide
2020-08-11 13:13:59 -04:00
2021-11-05 09:08:23 -04:00
### Step 1: check if [backports](https://backports.debian.org/) repository is enabled
2020-08-11 13:13:59 -04:00
```shell
2021-11-05 09:08:23 -04:00
cat /etc/apt/sources.list | grep "backports"
2020-08-11 13:13:59 -04:00
```
2021-11-05 09:08:23 -04:00
### Step 2: enable backports repository (required if previous command returned nothing)
2022-03-02 07:06:05 -05:00
> Heads-up: run `cat /etc/debian_version` to find Debian version.
2021-11-05 09:08:23 -04:00
#### Debian 10 (buster)
2020-08-11 13:13:59 -04:00
```shell
cat < < "EOF" >> /etc/apt/sources.list
deb http://deb.debian.org/debian buster-backports main
EOF
apt update
```
2021-11-05 09:08:23 -04:00
#### Debian 11 (bullseye)
2020-08-11 13:13:59 -04:00
2021-11-05 09:08:23 -04:00
```shell
cat < < "EOF" >> /etc/apt/sources.list
deb http://deb.debian.org/debian bullseye-backports main
EOF
apt update
2020-08-11 13:13:59 -04:00
```
2021-11-05 09:08:23 -04:00
### Step 3: install apt-transport-https, cURL and GnuPG
2020-08-11 13:13:59 -04:00
```shell
2020-08-13 08:37:00 -04:00
apt update
2021-11-05 09:08:23 -04:00
apt install -y apt-transport-https curl gnupg2
2020-08-11 13:13:59 -04:00
```
2021-11-05 09:08:23 -04:00
### Step 4: import [Speedtest](https://www.speedtest.net/)’ s PGP public key
2020-08-13 08:48:08 -04:00
```shell
2021-12-03 17:48:44 -05:00
curl -fsSL https://packagecloud.io/ookla/speedtest-cli/gpgkey | gpg --dearmor > /usr/share/keyrings/speedtest-cli.gpg
2020-08-13 08:48:08 -04:00
```
2021-11-05 09:08:23 -04:00
### Step 5: enable Speedtest’ s repository
2020-08-11 13:13:59 -04:00
2022-03-02 07:06:05 -05:00
> Heads-up: run `cat /etc/debian_version` to find Debian version.
2021-11-05 09:08:23 -04:00
#### Debian 10 (buster)
2020-08-11 13:13:59 -04:00
2021-11-05 09:08:23 -04:00
```shell
echo -e "deb [signed-by=/usr/share/keyrings/speedtest-cli.gpg] https://packagecloud.io/ookla/speedtest-cli/debian/ buster main\ndeb-src [signed-by=/usr/share/keyrings/speedtest-cli.gpg] https://packagecloud.io/ookla/speedtest-cli/debian/ buster main" > /etc/apt/sources.list.d/speedtest-cli.list
apt update
```
2020-08-11 13:13:59 -04:00
2021-11-05 09:08:23 -04:00
#### Debian 11 (bullseye)
```shell
echo -e "deb [signed-by=/usr/share/keyrings/speedtest-cli.gpg] https://packagecloud.io/ookla/speedtest-cli/debian/ bullseye main\ndeb-src [signed-by=/usr/share/keyrings/speedtest-cli.gpg] https://packagecloud.io/ookla/speedtest-cli/debian/ bullseye main" > /etc/apt/sources.list.d/speedtest-cli.list
apt update
2020-08-11 13:13:59 -04:00
```
2021-11-05 09:08:23 -04:00
### Step 6: install Speedtest and SysBench
2020-08-11 13:13:59 -04:00
```shell
apt install -y speedtest sysbench
```
2020-12-03 06:29:52 -05:00
👍
2020-08-11 13:13:59 -04:00
---
## Usage guide
### Benchmark network
2022-02-19 11:24:21 -05:00
> Heads-up: depending on iptables or nftables firewall configuration, running following commands may be required.
#### iptables
2020-08-11 13:13:59 -04:00
```shell
iptables -A OUTPUT -p tcp -m tcp --dport 8080 -m state --state NEW -j ACCEPT
ip6tables -A OUTPUT -p tcp -m tcp --dport 8080 -m state --state NEW -j ACCEPT
```
2022-02-19 11:24:21 -05:00
#### nftables
> Heads-up: replace `firewall` if needed (see `nft list ruleset`).
```shell
nft add rule ip firewall output tcp dport http-alt accept
nft add rule ip6 firewall output tcp dport http-alt accept
```
2020-08-11 13:13:59 -04:00
```console
$ speedtest
Speedtest by Ookla
2022-03-19 17:12:30 -04:00
Server: Siminn - Reykjavik (id = 4818)
2020-08-11 13:13:59 -04:00
ISP: 1984 ehf
2022-03-19 17:12:30 -04:00
Latency: 0.56 ms (0.04 ms jitter)
Download: 952.13 Mbps (data used: 429.5 MB )
Upload: 994.18 Mbps (data used: 1.6 GB )
2020-08-11 13:13:59 -04:00
Packet Loss: 0.0%
2022-03-19 17:12:30 -04:00
Result URL: https://www.speedtest.net/result/c/541db9ff-1731-4998-b137-9d6dd959f6aa
2020-08-11 13:13:59 -04:00
```
2022-03-15 20:04:22 -04:00
Network download speed: 940.03 Mbps
2020-08-11 13:13:59 -04:00
2022-03-15 20:04:22 -04:00
Network upload speed: 941.49 Mbps
2020-08-11 13:13:59 -04:00
2021-03-25 06:38:48 -04:00
👍
2020-08-11 13:13:59 -04:00
### Benchmark CPU
```console
2022-03-19 17:12:30 -04:00
$ sysbench cpu --threads=$(nproc) run
2022-03-02 07:06:05 -05:00
sysbench 1.0.20 (using system LuaJIT 2.1.0-beta3)
2020-08-11 13:13:59 -04:00
Running the test with following options:
Number of threads: 1
Initializing random number generator from current time
2022-03-02 07:06:05 -05:00
Prime numbers limit: 10000
2020-08-11 13:13:59 -04:00
Initializing worker threads...
Threads started!
CPU speed:
2022-03-19 17:12:30 -04:00
events per second: 4312.04
2020-08-11 13:13:59 -04:00
General statistics:
2022-03-15 20:04:22 -04:00
total time: 10.0002s
2022-03-19 17:12:30 -04:00
total number of events: 43123
2020-08-11 13:13:59 -04:00
Latency (ms):
2022-03-02 07:06:05 -05:00
min: 0.23
avg: 0.23
2022-03-19 17:12:30 -04:00
max: 0.64
95th percentile: 0.24
sum: 9989.38
2020-08-11 13:13:59 -04:00
Threads fairness:
2022-03-19 17:12:30 -04:00
events (avg/stddev): 43123.0000/0.00
execution time (avg/stddev): 9.9894/0.00
2020-08-11 13:13:59 -04:00
```
2022-03-19 17:12:30 -04:00
CPU events per second: 4312.04
2020-08-11 13:13:59 -04:00
2021-03-25 06:38:48 -04:00
👍
2020-08-11 13:13:59 -04:00
### Benchmark memory
```console
2022-03-19 17:12:30 -04:00
$ sysbench memory --threads=$(nproc) run
2022-03-02 07:06:05 -05:00
sysbench 1.0.20 (using system LuaJIT 2.1.0-beta3)
2020-08-11 13:13:59 -04:00
Running the test with following options:
Number of threads: 1
Initializing random number generator from current time
Running memory speed test with the following options:
block size: 1KiB
total size: 102400MiB
operation: write
scope: global
Initializing worker threads...
Threads started!
2022-03-19 17:12:30 -04:00
Total operations: 62470941 (6246793.35 per second)
2020-08-11 13:13:59 -04:00
2022-03-19 17:12:30 -04:00
61006.78 MiB transferred (6100.38 MiB/sec)
2020-08-11 13:13:59 -04:00
General statistics:
2022-03-15 20:04:22 -04:00
total time: 10.0000s
2022-03-19 17:12:30 -04:00
total number of events: 62470941
2020-08-11 13:13:59 -04:00
Latency (ms):
min: 0.00
avg: 0.00
2022-03-19 17:12:30 -04:00
max: 0.23
2020-08-11 13:13:59 -04:00
95th percentile: 0.00
2022-03-19 17:12:30 -04:00
sum: 4481.00
2020-08-11 13:13:59 -04:00
Threads fairness:
2022-03-19 17:12:30 -04:00
events (avg/stddev): 62470941.0000/0.00
execution time (avg/stddev): 4.4810/0.00
2020-08-11 13:13:59 -04:00
```
2022-03-19 17:12:30 -04:00
Memory speed: 6100.38 MiB/sec
2020-08-11 13:13:59 -04:00
2021-03-25 06:38:48 -04:00
👍
2020-08-11 13:13:59 -04:00
### Benchmark disk
2022-03-19 17:12:30 -04:00
> Heads-up: use `--file-block-size=16K` to simulate database or `apt install` workloads and `--file-block-size=1M` to simulate web server workload.
2020-08-11 13:13:59 -04:00
```console
$ sysbench fileio --file-total-size=8G prepare
2022-03-19 17:12:30 -04:00
sysbench 1.0.20 (using system LuaJIT 2.1.0-beta3)
2020-08-11 13:13:59 -04:00
128 files, 65536Kb each, 8192Mb total
Creating files for the test...
Extra file open flags: (none)
Creating file test_file.0
2022-03-02 07:06:05 -05:00
…
2020-08-11 13:13:59 -04:00
Creating file test_file.127
2022-03-19 17:12:30 -04:00
8589934592 bytes written in 81.95 seconds (99.96 MiB/sec).
2020-08-11 13:13:59 -04:00
2022-03-19 17:12:30 -04:00
$ sysbench fileio --file-block-size=16K --file-total-size=8G --file-test-mode=rndrw --threads=$(nproc) run
2022-03-02 07:06:05 -05:00
sysbench 1.0.20 (using system LuaJIT 2.1.0-beta3)
2020-08-11 13:13:59 -04:00
Running the test with following options:
Number of threads: 1
Initializing random number generator from current time
Extra file open flags: (none)
2022-03-15 20:04:22 -04:00
128 files, 64MiB each
8GiB total file size
2020-08-11 13:13:59 -04:00
Block size 16KiB
Number of IO requests: 0
Read/Write ratio for combined random IO test: 1.50
Periodic FSYNC enabled, calling fsync() each 100 requests.
Calling fsync() at the end of test, Enabled.
Using synchronous I/O mode
Doing random r/w test
Initializing worker threads...
Threads started!
File operations:
2022-03-19 17:12:30 -04:00
reads/s: 4042.23
writes/s: 2694.82
fsyncs/s: 8629.92
2020-08-11 13:13:59 -04:00
Throughput:
2022-03-19 17:12:30 -04:00
read, MiB/s: 63.16
written, MiB/s: 42.11
2020-08-11 13:13:59 -04:00
General statistics:
2022-03-19 17:12:30 -04:00
total time: 10.0040s
total number of events: 153609
2020-08-11 13:13:59 -04:00
Latency (ms):
min: 0.00
2022-03-19 17:12:30 -04:00
avg: 0.06
max: 10.10
95th percentile: 0.15
sum: 9963.22
Threads fairness:
events (avg/stddev): 153609.0000/0.00
execution time (avg/stddev): 9.9632/0.00
$ sysbench fileio --file-block-size=1M --file-total-size=8G --file-test-mode=rndrw --threads=$(nproc) run
sysbench 1.0.20 (using system LuaJIT 2.1.0-beta3)
Running the test with following options:
Number of threads: 1
Initializing random number generator from current time
Extra file open flags: (none)
128 files, 64MiB each
8GiB total file size
Block size 1MiB
Number of IO requests: 0
Read/Write ratio for combined random IO test: 1.50
Periodic FSYNC enabled, calling fsync() each 100 requests.
Calling fsync() at the end of test, Enabled.
Using synchronous I/O mode
Doing random r/w test
Initializing worker threads...
Threads started!
File operations:
reads/s: 63.57
writes/s: 42.38
fsyncs/s: 136.57
Throughput:
read, MiB/s: 63.57
written, MiB/s: 42.38
General statistics:
total time: 10.3782s
total number of events: 2390
Latency (ms):
min: 0.01
avg: 4.19
max: 160.43
95th percentile: 15.00
sum: 10004.76
2020-08-11 13:13:59 -04:00
Threads fairness:
2022-03-19 17:12:30 -04:00
events (avg/stddev): 2390.0000/0.00
execution time (avg/stddev): 10.0048/0.00
2020-08-11 13:13:59 -04:00
2022-03-19 17:12:30 -04:00
$ sysbench fileio --file-total-size=8G cleanup
2022-03-02 07:06:05 -05:00
sysbench 1.0.20 (using system LuaJIT 2.1.0-beta3)
2020-08-11 13:13:59 -04:00
2022-03-02 07:06:05 -05:00
Removing test files...
2020-08-11 13:13:59 -04:00
```
2022-03-19 17:12:30 -04:00
Disk read throughput (16K): 63.16 MiB/s
Disk write throughput (16K): 42.11 MiB/s
2020-08-11 13:13:59 -04:00
2022-03-19 17:12:30 -04:00
Disk read throughput (1M): 63.57 MiB/s
Disk write throughput (1M): 42.38 MiB/s
2021-03-25 06:38:48 -04:00
👍