Install and Use Sysbench on RHEL 9 | CentOS 9

Install and Use Sysbench on RHEL 9

Learn how to install and use Sysbench on RHEL 9 and CentOS 9 to benchmark CPU, memory, disk, and database performance. Step-by-step instructions, CLI examples, and optimization tips included.

Table of Contents

Introduction

Sysbench is a versatile, modular, and open-source benchmarking tool widely used to evaluate system performance in various environments. It can test CPU, memory, I/O, file I/O, and database performance, making it indispensable for systems administrators and database engineers. In this post, we’ll walk through how to install Sysbench on RHEL 9 and CentOS 9, and explore some CLI examples to help you get started with benchmarking on your setup.

Prerequisites

To begin, ensure that you have:

  • Root or sudo access to your RHEL 9 or CentOS 9 machine.
  • A working internet connection to download and install Sysbench from the official repositories.
PrerequisiteDescription
OS VersionRHEL 9 or CentOS 9
User AccessRoot or sudo privileges
NetworkActive internet connection

Let’s dive in!

Install and Use Sysbench on RHEL 9 | CentOS 9

To install Sysbench on RHEL 9 or CentOS 9, we’ll need the EPEL (Extra Packages for Enterprise Linux) repository, as Sysbench isn’t available in the default repository for these distributions.

Add the EPEL Repository

				
					sudo dnf install -y epel-release
				
			

This command installs the EPEL repository, which provides additional packages for RHEL-based distributions, including Sysbench.

Install Sysbench

				
					sudo dnf install -y sysbench
				
			
Install and Use Sysbench on RHEL 9

Photo by admingeek from Infotechys

Once completed, verify the installation by checking the Sysbench version:

				
					sysbench --version
				
			

You should see output similar to:

				
					sysbench 1.0.20
				
			

Using Sysbench for Benchmarking

Sysbench allows you to perform several types of benchmarks, such as CPU, memory, and I/O tests. Here’s a look at some of the most common benchmarking commands you can use.

CPU Benchmarking

Test your CPU performance by running:

				
					sysbench cpu --cpu-max-prime=20000 run
				
			

The --cpu-max-prime parameter defines the upper limit for calculating prime numbers, with higher values providing more stress on the CPU.

				
					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


Prime numbers limit: 20000

Initializing worker threads...

Threads started!

CPU speed:
    events per second:   333.66

General statistics:
    total time:                          10.0023s
    total number of events:              3338

Latency (ms):
         min:                                    2.86
         avg:                                    3.00
         max:                                    5.70
         95th percentile:                        3.30
         sum:                                 9998.99

Threads fairness:
    events (avg/stddev):           3338.0000/0.00
    execution time (avg/stddev):   9.9990/0.00
				
			

This output provides an idea of how well your CPU can handle high workloads.

Memory Benchmarking

Memory performance testing involves writing to and reading from memory. Run the following command to test memory read and write speed:

				
					sysbench memory --memory-block-size=1M --memory-total-size=4G run
				
			
  • --memory-block-size: Sets the block size for each read/write operation.
  • --memory-total-size: Total data size to transfer.

Memory Benchmark Result Table:

MetricValue
Transfer Rate4096.00 MiB transferred (9906.76 MiB/sec)
General Statisticstotal time: 0.4112s
total number of events: 4096
Threads fairnessevents (avg/stddev): 4096.0000/0.00
execution time (avg/stddev): 0.4084/0.00

Disk I/O Benchmarking

Disk performance benchmarking in Sysbench can help assess read and write speeds on your storage. First, you’ll need to create a test file:

				
					sysbench fileio --file-total-size=5G prepare
				
			
				
					sysbench 1.0.20 (using system LuaJIT 2.1.0-beta3)

128 files, 40960Kb each, 5120Mb 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.6
Creating file test_file.7
Creating file test_file.8
Creating file test_file.9
Creating file test_file.10
Creating file test_file.11
Creating file test_file.12
Creating file test_file.13
Creating file test_file.14
...omitted for brevity...
Creating file test_file.127
5368709120 bytes written in 53.33 seconds (96.01 MiB/sec).
				
			

After creating the files, run the following command to benchmark disk I/O performance:

				
					sysbench fileio --file-total-size=5G --file-test-mode=rndrw run
				
			
Install and Use Sysbench on RHEL 9

Photo by admingeek from Infotechys

  • --file-total-size: Sets the size of the test file.
  • --file-test-mode: Configures Sysbench to perform random read/write operations (rndrw).

Database Benchmarking

Sysbench supports benchmarking for MySQL and PostgreSQL databases. Ensure you have the appropriate database software installed and a test database created. Here’s a simple example with MySQL:

Prepare the database

				
					sysbench oltp_read_write --db-driver=mysql --mysql-user=root --mysql-password=yourpassword --tables=10 --table-size=10000 prepare
				
			

Run the Database Benchmark

				
					sysbench oltp_read_write --db-driver=mysql --mysql-user=root --mysql-password=yourpassword --tables=10 --table-size=10000 run
				
			
Sample Database Benchmark Result Table
TestValue
Transactions/sec500
Reads/sec2500
Writes/sec1500
Latency (avg)4.1 ms

Sysbench Commands Cheat Sheet

To make things easier, here’s a table summarizing essential Sysbench commands for quick reference:

Benchmark TypeCommand Example
CPUsysbench cpu --cpu-max-prime=20000 run
Memorysysbench memory --memory-block-size=1M --memory-total-size=10G run
Disk I/Osysbench fileio --file-total-size=5G --file-test-mode=rndrw run
Databasesysbench oltp_read_write --db-driver=mysql --mysql-user=root --mysql-password=yourpassword run

Optimizing Performance Based on Results

Once you’ve gathered benchmark data, consider these steps to optimize performance:

  1. CPU Optimization: If CPU performance is lower than expected, consider upgrading your processor or increasing CPU resources in virtualized environments.

  2. Memory Tuning: Increase the available memory if your workload requires high memory throughput. Adjusting the swap size can also help in memory-bound applications.

  3. Disk I/O: Upgrade to SSDs or NVMe storage if disk read/write speeds are low, or explore using RAID for improved redundancy and performance.

  4. Database Optimization: Tune database settings such as cache size, query optimization, and indexing. For MySQL, for example, adjusting innodb_buffer_pool_size can lead to improved performance.

Conclusion

Sysbench offers robust and flexible benchmarking capabilities, making it an essential tool for administrators and engineers looking to optimize their systems on RHEL 9 or CentOS 9. With CPU, memory, disk, and database benchmarking available, Sysbench can reveal vital insights into where your system may need adjustments. By following this guide, you should be well on your way to accurately assessing and enhancing the performance of your infrastructure.

Ensure to run these benchmarks periodically to monitor the impact of any changes or upgrades, and stay ahead in keeping your system optimized.

Did you find this article useful? Your feedback is invaluable to us! Please feel free to share your thoughts in the comments section below and share this post!

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *