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
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
2021-02-11 17:44:27 -05: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)
#### 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-11-05 09:08:23 -04:00
curl -L 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
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
Depending on iptables configuration, running the following commands may be required.
```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
```
```console
$ speedtest
Speedtest by Ookla
Server: Vodafone - Reykjavík (id = 4141)
ISP: 1984 ehf
Latency: 0.64 ms (0.06 ms jitter)
Download: 95.82 Mbps (data used: 158.0 MB)
Upload: 95.63 Mbps (data used: 155.7 MB)
Packet Loss: 0.0%
Result URL: https://www.speedtest.net/result/c/19654353-3d2e-4ed3-ac22-824e1376b838
```
Network download speed: 95.82 Mbps
Network upload speed: 95.63 Mbps
2021-03-25 06:38:48 -04:00
👍
2020-08-11 13:13:59 -04:00
### Benchmark CPU
```console
$ sysbench cpu --cpu-max-prime=20000 run
sysbench 1.0.18 (using system LuaJIT 2.1.0-beta3)
Running the test with following options:
Number of threads: 1
Initializing random number generator from current time
Prime numbers limit: 20000
Initializing worker threads...
Threads started!
CPU speed:
events per second: 403.87
General statistics:
total time: 10.0012s
total number of events: 4040
Latency (ms):
min: 2.43
avg: 2.47
max: 4.60
95th percentile: 2.52
sum: 9995.53
Threads fairness:
events (avg/stddev): 4040.0000/0.00
execution time (avg/stddev): 9.9955/0.00
```
CPU events per second: 403.87
2021-03-25 06:38:48 -04:00
👍
2020-08-11 13:13:59 -04:00
### Benchmark memory
```console
$ sysbench memory run
sysbench 1.0.18 (using system LuaJIT 2.1.0-beta3)
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!
Total operations: 40219144 (4020984.62 per second)
39276.51 MiB transferred (3926.74 MiB/sec)
General statistics:
total time: 10.0003s
total number of events: 40219144
Latency (ms):
min: 0.00
avg: 0.00
max: 1.84
95th percentile: 0.00
sum: 4358.06
Threads fairness:
events (avg/stddev): 40219144.0000/0.00
execution time (avg/stddev): 4.3581/0.00
```
Memory speed: 3926.74 MiB/sec
2021-03-25 06:38:48 -04:00
👍
2020-08-11 13:13:59 -04:00
### Benchmark disk
```console
$ sysbench fileio --file-total-size=8G prepare
sysbench 1.0.18 (using system LuaJIT 2.1.0-beta3)
128 files, 65536Kb each, 8192Mb total
Creating files for the test...
Extra file open flags: (none)
Creating file test_file.0
Creating file test_file.1
Creating file test_file.2
Creating file test_file.3
Creating file test_file.4
Creating file test_file.5
...
Creating file test_file.127
8589934592 bytes written in 85.92 seconds (95.34 MiB/sec).
$ sysbench fileio --file-total-size=8G --file-test-mode=rndrw --max-time=300 --max-requests=0 run
sysbench 1.0.18 (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 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:
reads/s: 2727.09
writes/s: 1818.06
fsyncs/s: 5818.16
Throughput:
read, MiB/s: 42.61
written, MiB/s: 28.41
General statistics:
total time: 300.0100s
total number of events: 3109023
Latency (ms):
min: 0.00
avg: 0.10
max: 11.59
95th percentile: 0.23
sum: 298089.49
Threads fairness:
events (avg/stddev): 3109023.0000/0.00
execution time (avg/stddev): 298.0895/0.00
$ sysbench fileio --file-total-size=8G cleanup
sysbench 1.0.18 (using system LuaJIT 2.1.0-beta3)
Removing test files..
```
Disk read throughput: 42.61 MiB/s
Disk write throughput: 28.41 MiB/s
2021-03-25 06:38:48 -04:00
👍