How to Use Sysbench for Linux Performance Testing

Introduction

Before we begin talking about how to use Sysbench for Linux Performance Testing, let's briefly understand – What is Sysbench?

The sysbench is a valuable multipurpose utility that offers a rapid benchmark performance report of the system CPU, MySQL database, memory, and I/O report. Under demanding testing situations, such as high CPU usage, higher database load, or low free memory, this tool can reveal the system's performance details. This utility uses the command line to quickly give system results.

In this tutorial, you will use Sysbench for Linux Performance Testing. We will also address a few FAQs on how to use Sysbench for Linux Performance Testing.

How to Use Sysbench for Linux Performance Testing?

On Linux, the sysbench is used to do performance testing. Linux's releases do not include the sysbench by default; the installation methods for various Linux distributions are listed below:

For installation in Linux distributions based on Debian:

sudo apt install sysbench

For installation in CentOS and Linux distributions based on RHEL:

sudo yum install sysbench

For Fedora installation:

dnf install sysbench

After setting up the sysbench in your preferred Linux distribution (in my instance, Ubuntu 22.04), let's utilise it to run benchmark performance tests under specific circumstances.

CPU Benchmark

Use the "CPU" test specifier and the following command to use the sysbench utility to determine the system's CPU performance under the present CPU operating conditions:

sysbench --test=cpu run

It takes a few seconds to display the whole system CPU performance report. In under "10.0004" seconds, the output below shows the current CPU report, complete with information on CPU performance, latency, and thread fairness:

In a matter of seconds, this command offers a thorough performance report on both the default and supplied conditions.

When checking the performance of the CPU under heavy loads, the maximum prime number limit on the CPU can be extended from "10000" to "15000" with the command:

sysbench --test=cpu --cpu-max-prime=15000 run

The output displays the performance metrics under heavy load:

The low load and high load CPU statistics display specifics of the CPU's operation under the specified conditions. For instance, a heavy load displays more latency and events per second.

Memory Benchmark

To acquire information on how much memory is still available and being used, we try to continuously check on it. The benchmark test with the sysbench utility can be run using the sysbench. Run the following command to assess the system memory's specifics under working conditions:

sysbench --test=memory run

The output provides information on the system memory, where the total operations and MiB transferred are significant parameters:

To test the memory under specific conditions, such as raising the memory block size from the default "1KiB" to "1M" while maintaining the total memory capacity of "8GB," do the following:

sysbench --test=memory --memory-block-size=1M --memory-total-size=8G run

The output displays many statistics that differ from those under normal circumstances and illustrate how the system performed in certain circumstances:

Moreover, run the following command to discover the parameters for the "memory" test:

sysbench --test=memory help

The memory test has the aforementioned possibilities.

To assess the system's performance under these circumstances, the file size can be increased to a value bigger than the system RAM. For example, the following command raises the file size to "150GB" while testing the file I/O performance in sequential write mode:

sysbench --test=fileio --file-total-size=150G --file-test-mode=seqwr run

The output displays several I/O performance test metrics under specific conditions, where file operations and written MiB/s are key components of this test:

After finishing the I/O performance test, use the following command to remove the "150GB" file that was made for the test:

sysbench --test=fileio --file-total-size=150G cleanup

The system removes the test file.

Using the sysbench help command, you can investigate all the options available for the I/O performance test as follows:

sysbench --test=fileio help

Perform Complete Benchmark with Sysbech Using Shell Script

Use the shell script to run all the sysbench tests under the desired conditions. For instance, the "testsysbench.sh" bash script file below combines performance tests for the CPU, File I/O, and Memory:

!/bin/bash
 
# CPU Benchmark
sysbench --test=cpu --cpu-max-prime=150000 run
sysbench --test=cpu --cpu-max-prime=15000 run --num-threads=4
 
#FILE IO Benchmark
sysbench --test=fileio --file-total-size=150G --file-test-mode=seqwr run
sysbench --test=fileio --file-total-size=150G cleanup
 
#MEMROY Benchmark
sysbench --test=memory --memory-block-size=1M --memory-total-size=8G run

Use the bash command below to run the bash script:

bash testsysbench.sh

The output displays the results of the File I/O performance test:

The results of the memory test are also shown in the output:

The output simultaneously lists the outputs of the three tests.

FAQs to Use Sysbench for Linux Performance Testing

How do I interpret the Sysbench benchmark results?

Sysbench provides detailed benchmark reports, including metrics like operations per second (OPS), latency, and execution time, to help you analyze and interpret the performance of your system.

Can I customize the benchmark parameters in Sysbench? 

Yes, Sysbench offers various parameters that can be customized according to your requirements. Refer to the Sysbench documentation for an in-depth understanding of available options.

Are there any additional resources for learning more about Sysbench? 

Yes, there are several online resources available, including the official Sysbench documentation, tutorials, and user forums, where you can find more detailed information and community support for using Sysbench.

Which components can I benchmark with Sysbench? 

Sysbench allows benchmarking of CPU, file I/O, memory, mutex performance, threads, and MySQL database performance.

What options are available for testing MySQL performance with Sysbench?

Sysbench provides various options for testing MySQL performance, including OLTP and read/write workload benchmarks.

Is it possible to simulate multi-threaded workloads? 

Yes, Sysbench supports multi-threaded workloads. You can specify the number of threads using the --threads parameter.

What does the output of Sysbench performance tests indicate? 

The output includes metrics like operations per second (OPS), latency, CPU usage, total time, and other relevant statistics for the specific benchmark.

Conclusion

On Linux, the CPU, I/O, and memory performance of the system can be evaluated using the sysbench benchmark utility. In order to evaluate the system's performance under certain conditions, this tutorial runs performance tests under both the default system conditions and increasing testing conditions.