RHEL BasedRocky Linux

How To Install Sysbench on Rocky Linux 9

Install Sysbench on Rocky Linux 9

In this tutorial, we will show you how to install Sysbench on Rocky Linux 9. Sysbench stands as one of the most powerful benchmarking tools in the Linux ecosystem, providing system administrators and database professionals with precise metrics about their hardware performance. This versatile, open-source utility enables comprehensive testing of CPU, memory, file I/O, and database operations, making it an essential tool for performance optimization on Rocky Linux 9 environments. Whether you’re evaluating server capabilities for database deployments or fine-tuning system parameters, mastering Sysbench installation and usage is invaluable for any Linux professional.

Understanding Sysbench and Its Importance

Sysbench is a free, open-source benchmarking tool designed specifically for evaluating operating system parameters critical to system performance. It provides a modular framework that allows users to run various performance tests including CPU computation speed, memory access patterns, file I/O operations, and database performance metrics. For administrators managing Rocky Linux 9 servers, particularly those running resource-intensive applications or databases, Sysbench offers invaluable insights that inform optimization decisions.

Rocky Linux 9, as a stable enterprise-grade distribution compatible with Red Hat Enterprise Linux (RHEL), provides an excellent foundation for performance-critical workloads. The distribution’s reliability combined with proper benchmarking creates an environment where applications can operate at peak efficiency. System benchmarking becomes particularly important when:

  • Establishing baseline performance for new hardware
  • Troubleshooting performance bottlenecks
  • Planning capacity for growing workloads
  • Validating system changes or updates
  • Comparing different hardware configurations

The metrics generated by Sysbench allow administrators to make data-driven decisions about hardware upgrades, kernel parameter tuning, and application optimization, ultimately resulting in more efficient resource utilization.

System Requirements and Prerequisites

Before proceeding with Sysbench installation on Rocky Linux 9, ensure your system meets these basic prerequisites:

  • A functioning Rocky Linux 9 installation (minimal or complete)
  • Root or sudo privileges for installing packages
  • Active internet connection for repository access
  • At least 1GB of RAM and 1 CPU core (more recommended for meaningful benchmarks)
  • Sufficient disk space (at least 10GB free) for benchmark files and results
  • Terminal access for command execution

It’s also advisable to ensure your system is fully updated before proceeding:

sudo dnf update -y

This command refreshes your package lists and applies any pending security or system updates, providing a clean slate for installation.

Additionally, if you plan to benchmark MySQL/MariaDB performance, you’ll need to have the database server installed and properly configured. For comprehensive benchmarking, consider creating a dedicated test environment that mirrors your production setup as closely as possible.

Installation Methods for Sysbench on Rocky Linux 9

Sysbench can be installed through several different methods on Rocky Linux 9, each with its own advantages. The following sections detail each approach, from the simplest to more advanced options.

Method 1: Installation Using EPEL Repository

The EPEL (Extra Packages for Enterprise Linux) repository contains many additional packages not found in the default Rocky Linux repositories, including Sysbench. This is often the simplest installation method:

# Install EPEL repository
sudo dnf install -y epel-release

# Install Sysbench from EPEL
sudo dnf install -y sysbench

After installation completes, verify the installation by checking the Sysbench version:

sysbench --version

You should see output showing the installed version, such as “sysbench 1.0.20”.

Method 2: Installation Using Packagecloud Repository

For the latest version of Sysbench, the Packagecloud repository maintained by the Sysbench developer (Alexey Kopytov) provides up-to-date packages. This method ensures you have access to the newest features and improvements:

# Add the Akopytov repository
curl -s https://packagecloud.io/install/repositories/akopytov/sysbench/script.rpm.sh | sudo bash

# Install Sysbench from the repository
sudo dnf -y install sysbench

This method typically provides a newer version than what’s available in EPEL, which can be beneficial if you need specific features or bugfixes found in recent releases.

Method 3: Compiling from Source

For maximum control over compilation options or if you need a specific version not available in repositories, compiling from source is an option:

# Install development tools and dependencies
sudo dnf groupinstall -y "Development Tools"
sudo dnf install -y automake libtool openssl-devel mysql-devel

# Clone the repository
git clone https://github.com/akopytov/sysbench.git

# Navigate to source directory
cd sysbench

# Generate configuration scripts
./autogen.sh

# Configure the build
./configure

# Compile the source
make -j$(nproc)

# Install Sysbench
sudo make install

This method requires more time and technical knowledge but offers complete flexibility in terms of compilation options and version selection.

Basic Configuration and First Steps

After installation, understanding the basic structure and operation of Sysbench will help you make the most of this benchmarking tool. Sysbench doesn’t rely on a central configuration file; instead, it uses command-line parameters to control its behavior.

To see all available options and built-in tests:

sysbench --help

For help with a specific test, such as the CPU benchmark:

sysbench cpu help

The basic syntax for running any Sysbench test follows this pattern:

sysbench [test] [options] [command]

Where:

  • [test] is the test type (cpu, memory, fileio, etc.)
  • [options] are specific parameters for the test
  • [command] is the action to perform (prepare, run, cleanup)

Before running intensive benchmarks, consider the impact on system performance. It’s best to run benchmarks on systems where temporary performance degradation won’t affect critical services.

CPU Benchmarking with Sysbench

CPU benchmarking is one of Sysbench’s core functions, providing insights into processor performance through mathematical calculations.

Basic CPU Test

To run a basic CPU test that calculates prime numbers:

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

This command tests your CPU by verifying prime numbers up to 20,000. The parameter --cpu-max-prime determines the computational load—higher values create more intensive tests.

The output includes:

  • Total execution time
  • Events per second (higher is better)
  • Latency statistics (minimum, average, maximum)
  • Thread fairness metrics

Multi-threaded CPU Testing

To evaluate multi-core performance, specify the number of threads:

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

This utilizes four processor threads, providing insight into parallel processing capabilities. For best results, match the thread count to your CPU’s core/thread count or test with various configurations to observe scaling behavior.

Analyzing CPU Benchmark Results

When interpreting CPU benchmark results, focus on:

  1. Events per second: Higher numbers indicate better CPU performance
  2. Total time: Less time to complete the same workload indicates better performance
  3. Latency: Lower latency (especially maximum latency) suggests more consistent performance
  4. Thread fairness: Even distribution indicates balanced core utilization

Comparing these metrics across different systems or before/after configuration changes helps quantify performance improvements.

Memory Benchmarking with Sysbench

Memory performance significantly impacts overall system speed, especially for data-intensive applications.

Running a Memory Benchmark

To test memory operations:

sysbench memory --memory-block-size=1K --memory-total-size=100G run

This command tests memory operations with 1KB blocks, continuing until 100GB of data has been processed (the test will finish much faster than that might suggest, as it repeatedly accesses a smaller memory footprint).

Key parameters include:

  • --memory-block-size: Size of each memory block operation
  • --memory-total-size: Total amount of data to transfer
  • --memory-oper: Operation type (read, write, or both)
  • --memory-access-mode: Sequential or random access pattern

Interpreting Memory Test Results

Memory test results include:

  • Operations per second (higher is better)
  • Transferred data rate (MB/s)
  • Latency statistics for memory operations

These metrics help identify memory bottlenecks and validate improvements from hardware upgrades or system tuning.

File I/O Benchmarking

Storage performance often becomes a critical bottleneck in many applications, particularly databases. Sysbench’s file I/O test helps evaluate your storage subsystem.

Preparing File I/O Test

File I/O testing requires a preparation step to create test files:

# Create test files
sysbench fileio --file-total-size=5G prepare

# Run random read/write test
sysbench fileio --file-total-size=5G --file-test-mode=rndrw run

# Clean up test files when finished
sysbench fileio --file-total-size=5G cleanup

The file I/O test offers several test modes:

  • seqrd: Sequential read
  • seqwr: Sequential write
  • seqrewr: Sequential rewrite
  • rndrd: Random read
  • rndwr: Random write
  • rndrw: Combined random read/write

Advanced File I/O Testing

For more realistic I/O testing that bypasses cache effects, use direct I/O:

sysbench fileio --file-total-size=5G --file-test-mode=rndrw --file-io-mode=async --file-extra-flags=direct run

This configuration:

  • Uses asynchronous I/O operations
  • Bypasses the filesystem cache with the direct flag
  • Provides more accurate representation of raw storage performance

Results include operations per second, I/O throughput (MB/s), and latency metrics that help identify storage bottlenecks and validate performance optimizations.

MySQL/MariaDB Benchmarking

Database performance testing is one of Sysbench’s most valuable capabilities, especially for systems running MySQL or MariaDB.

Setting Up Database for Benchmarking

Before testing, you need a configured MySQL/MariaDB server and a test database:

# Create test database
mysql -u root -p -e "CREATE DATABASE sysbench_test;"

# Create user with appropriate permissions
mysql -u root -p -e "CREATE USER 'sbtest'@'localhost' IDENTIFIED BY 'password';"
mysql -u root -p -e "GRANT ALL PRIVILEGES ON sysbench_test.* TO 'sbtest'@'localhost';"
mysql -u root -p -e "FLUSH PRIVILEGES;"

Preparing and Running Database Tests

The OLTP (Online Transaction Processing) benchmark simulates a realistic workload:

# Prepare the test tables
sysbench oltp_read_write --db-driver=mysql --mysql-db=sysbench_test --mysql-user=sbtest --mysql-password=password --tables=10 --table-size=1000000 prepare

# Run the benchmark
sysbench oltp_read_write --db-driver=mysql --mysql-db=sysbench_test --mysql-user=sbtest --mysql-password=password --tables=10 --table-size=1000000 --threads=4 --time=60 run

# Clean up when finished
sysbench oltp_read_write --db-driver=mysql --mysql-db=sysbench_test --mysql-user=sbtest --mysql-password=password --tables=10 cleanup

This test creates tables, populates them with data, and performs a mixture of SELECT, UPDATE, INSERT, and DELETE operations to simulate real application workloads.

Interpreting Database Benchmark Results

Database benchmark results include:

  • Transactions per second (higher is better)
  • Query execution statistics
  • Latency metrics for transactions
  • Thread fairness information

These metrics help identify configuration issues, validate tuning efforts, and compare different database setups or hardware configurations. Pay particular attention to the transactions per second and 95th percentile latency as key indicators of database performance.

Creating Automated Benchmark Scripts

For consistent benchmarking across systems or over time, automated scripts are invaluable. Here’s a simple shell script that runs a complete system benchmark:

#!/bin/bash

# System benchmark script
echo "Starting system benchmark at $(date)"

# Directory for results
RESULT_DIR="./benchmark_results_$(date +%Y%m%d_%H%M%S)"
mkdir -p $RESULT_DIR

# CPU benchmark
echo "Running CPU benchmark..."
sysbench cpu --cpu-max-prime=20000 run > $RESULT_DIR/cpu_result.txt

# Memory benchmark
echo "Running memory benchmark..."
sysbench memory --memory-block-size=1K --memory-total-size=100G run > $RESULT_DIR/memory_result.txt

# File I/O benchmark
echo "Running file I/O benchmark..."
sysbench fileio --file-total-size=5G prepare
sysbench fileio --file-total-size=5G --file-test-mode=rndrw run > $RESULT_DIR/fileio_result.txt
sysbench fileio --file-total-size=5G cleanup

echo "Benchmark complete. Results saved to $RESULT_DIR"

Save this script as run_benchmark.sh, make it executable with chmod +x run_benchmark.sh, and run it to perform a complete system evaluation.

For regular monitoring, consider scheduling this script with cron:

# Add to crontab to run weekly
0 0 * * 0 /path/to/run_benchmark.sh

This automated approach ensures consistent testing methodology and makes tracking performance changes over time much easier.

Troubleshooting Common Sysbench Issues

Even with proper installation, you might encounter issues with Sysbench. Here are solutions to common problems:

Missing Libraries

If you see errors about missing libraries:

error while loading shared libraries: libmysqlclient.so.20: cannot open shared object file: No such file or directory

Install the required libraries:

sudo dnf install mysql-libs

For a temporary fix, you can also add the library path to your environment:

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/path/to/mysql/lib

Permission Issues

If you encounter permission errors during file I/O tests:

# Run Sysbench with a directory where you have write permissions
sysbench fileio --file-total-size=5G --file-path=/tmp/sysbench prepare

Repository Connection Problems

If you can’t connect to repositories during installation:

# Check network connectivity
ping -c 3 packagecloud.io

# Try an alternative repository
sudo dnf install -y epel-release
sudo dnf install -y sysbench

Inconsistent Benchmark Results

If benchmark results vary significantly between runs:

  1. Ensure no other intensive processes are running
  2. Disable CPU frequency scaling for consistent results:
    sudo cpupower frequency-set --governor performance
  3. Run benchmarks multiple times and average the results
  4. Consider system temperature—thermal throttling can affect performance

Database Connectivity Issues

For MySQL benchmark connection problems:

# Verify database connectivity
mysql -u sbtest -p -h localhost -e "SELECT 1;"

# Check permissions
mysql -u root -p -e "SHOW GRANTS FOR 'sbtest'@'localhost';"

Advanced Sysbench Usage and Custom Scripts

Sysbench’s flexibility extends beyond the built-in tests through custom Lua scripts that can create tailored benchmarks for specific workloads.

Using Custom Lua Scripts

Sysbench uses Lua for test definitions. Create a custom test by writing a Lua script:

-- mycustomtest.lua
function prepare()
  -- Preparation code
end

function cleanup()
  -- Cleanup code
end

function thread_init(thread_id)
  -- Per-thread initialization
end

function event()
  -- Actual benchmark code
  -- This function is called repeatedly during the test
  local start_time = sysbench.time.time()
  -- Your custom operations here
  local end_time = sysbench.time.time()
  
  -- Report latency
  sysbench.histogram.update(end_time - start_time)
end

function thread_done(thread_id)
  -- Per-thread cleanup
end

Run your custom benchmark:

sysbench --test=./mycustomtest.lua run

This extensibility makes Sysbench extremely powerful for specialized performance testing scenarios.

Congratulations! You have successfully installed Sysbench. Thanks for using this tutorial to install the latest version of the Sysbench benchmarking tool on Rocky Linux 9. For additional help or useful information, we recommend you check the official Sysbench website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is an experienced Linux enthusiast and technical writer with a passion for open-source software. With years of hands-on experience in various Linux distributions, r00t has developed a deep understanding of the Linux ecosystem and its powerful tools. He holds certifications in SCE and has contributed to several open-source projects. r00t is dedicated to sharing her knowledge and expertise through well-researched and informative articles, helping others navigate the world of Linux with confidence.
Back to top button