How to Use Sysbench to Test Database Performance on a Linux Machine

How to Use Sysbench to Test Database Performance

Database performance is a critical aspect of ensuring smooth and efficient operations for any application. Whether you’re running a small blog or a large e-commerce platform, the speed and reliability of your database can significantly impact user experience. One of the tools that can help you assess the efficiency of database operations and evaluate query performance and latency is Sysbench.

Sysbench is a versatile, open-source benchmarking tool designed to evaluate and test various system parameters, including CPU performance, memory operations, and, most importantly for our purposes, database performance.

In this guide, we will focus on using Sysbench to test the performance of databases on a Linux machine. By the end of this tutorial, you’ll have a clear understanding of how to set up and run Sysbench tests on your database, be it MySQL, PostgreSQL, or any other supported database system.

Let’s get started.


  • A Linux machine, preferably a dedicated server or a VPS server.
  • Root or sudo access to the server.
  • A database system installed, such as MySQL or PostgreSQL.
  • Basic knowledge of Linux command line operations.

Step 1: Installing Sysbench

Update your system’s package list:

sudo apt update

Install Sysbench:

sudo apt install sysbench

Verify the installation:

sysbench --version

Step 2: Preparing the Database for Testing

Before running tests, you need to create a test database and user:

Log in to your database:

mysql -u root -p

Create a test database:

CREATE DATABASE sysbench_test;

Create a user for testing:

CREATE USER 'sysbench_user'@'localhost' IDENTIFIED BY 'password';

Grant all privileges to the user on the test database:

GRANT ALL PRIVILEGES ON sysbench_test.* TO 'sysbench_user'@'localhost';

Exit the database:


Step 3: Running the Sysbench Test

Prepare the test environment:

sysbench oltp_read_write --db-driver=mysql --mysql-db=sysbench_test --mysql-user=sysbench_user --mysql-password=password prepare

Run the test:

sysbench oltp_read_write --db-driver=mysql --mysql-db=sysbench_test --mysql-user=sysbench_user --mysql-password=password run

For example:

Running the test with following options:
Number of threads: 1
Initializing random number generator from current time

Initializing worker threads...

Threads started!

[ 10s ] thds: 1 tps: 58.90 qps: 1181.81 (r/w/o: 827.86/236.95/117.00) lat (ms,95%): 27.88 err/s: 0.00 reconn/s: 0.00
[ 20s ] thds: 1 tps: 60.10 qps: 1202.09 (r/w/o: 841.06/240.02/121.01) lat (ms,95%): 26.66 err/s: 0.00 reconn/s: 0.00
[ 30s ] thds: 1 tps: 59.90 qps: 1197.91 (r/w/o: 838.94/239.97/119.00) lat (ms,95%): 26.66 err/s: 0.00 reconn/s: 0.00

SQL statistics:
    queries performed:
        read:                            25083
        write:                           7167
        other:                           3583
        total:                           35833
    transactions:                        1791   (59.70 per sec.)
    queries:                             35833  (1194.43 per sec.)
    ignored errors:                      0      (0.00 per sec.)
    reconnects:                          0      (0.00 per sec.)

General statistics:
    total time:                          30.0143s
    total number of events:              1791

Latency (ms):
         min:                                    4.38
         avg:                                   16.77
         max:                                   38.92
         95th percentile:                       26.66
         sum:                                30041.58

Threads fairness:
    events (avg/stddev):           1791.0000/0.00
    execution time (avg/stddev):   30.0416/0.00

Once the test is complete, you can clean up the test data:

sysbench oltp_read_write --db-driver=mysql --mysql-db=sysbench_test --mysql-user=sysbench_user --mysql-password=password cleanup

Step 4: Interpreting the Results

The Sysbench output provides a wealth of information about the performance of your database under the oltp_read_write test. Let’s break down the key metrics and understand what they signify:

See also  How to Use TPC-C to Test Database Performance on a Linux Machine

1. SQL Statistics:

  • Queries performed: This section breaks down the number of different types of queries executed during the test.
    • Read: 25,083 – The number of read operations performed.
    • Write: 7,167 – The number of write operations performed.
    • Other: 3,583 – Other types of operations, which could include updates or deletes.
    • Total: 35,833 – The total number of all types of queries executed.
  • Transactions: 1,791 (59.70 per sec.) – This represents the number of database transactions executed during the test. A higher number indicates better performance.
  • Queries: 35,833 (1,194.43 per sec.) – Total queries executed per second. This metric is crucial for understanding the database’s throughput.
  • Ignored errors: 0 (0.00 per sec.) – Indicates the number of errors that were ignored during the test.
  • Reconnects: 0 (0.00 per sec.) – The number of times Sysbench had to reconnect to the database. Ideally, this should be zero, indicating stable connectivity.

2. General Statistics:

  • Total time: 30.0143s – The total duration of the test.
  • Total number of events: 1,791 – The total number of operations or events executed during the test.
See also  How to Setup Sysbench for CPU and Memory Benchmarking on a Linux Machine

3. Latency (ms):

Latency represents the delay between a request and a response. Lower latency indicates faster response times.

  • Min: 4.38ms – The fastest response time recorded during the test.
  • Avg: 16.77ms – The average response time. This gives a general idea of the database’s responsiveness.
  • Max: 38.92ms – The slowest response time recorded. It’s essential to monitor this to ensure no queries are excessively slow.
  • 95th percentile: 26.66ms – 95% of the queries had a response time faster than this value. It helps identify the upper limit of typical query performance.

4. Threads Fairness:

This section provides insights into the distribution of events and execution time across threads.

  • Events (avg/stddev): 1,791.0000/0.00 – Indicates the average number of events per thread and the standard deviation. A lower standard deviation suggests more consistent performance across threads.
  • Execution time (avg/stddev): 30.0416/0.00 – Represents the average execution time per thread and its standard deviation. Again, a lower standard deviation indicates consistent performance.

In this example, the database showcased a good number of transactions per second and a decent average latency, indicating satisfactory performance. The absence of ignored errors and reconnects suggests stability during the test.

Commands Mentioned

  • sudo apt update – Updates the package list.
  • sudo apt install sysbench – Installs Sysbench.
  • sysbench –version – Checks the installed version of Sysbench.
  • mysql -u root -p – Logs into the MySQL database.


  1. What is Sysbench?

    Sysbench is an open-source benchmarking tool designed to evaluate and test various system parameters, including CPU performance, memory operations, and database performance.

  2. Why is database performance testing important?

    Database performance testing ensures that the database delivers efficient and consistent performance under varying loads, ensuring a smooth user experience and optimal application functionality.

  3. Can Sysbench test other databases besides MySQL?

    Yes, Sysbench supports multiple database drivers, allowing it to test various databases such as PostgreSQL, MariaDB, and others.

  4. How long should a Sysbench test run?

    The duration of a Sysbench test can vary based on the specific test parameters and the system’s performance. However, a typical test might run for several minutes to get comprehensive results.

  5. Is Sysbench suitable for production environments?

    While Sysbench is a powerful tool, it’s recommended to use it with caution in production environments. Running intensive tests on a live database can impact its performance and the applications relying on it.

See also  How to Test a Web Server with the dd Command


Testing and optimizing database performance is crucial for maintaining a responsive and reliable application. With tools like Sysbench, webmasters and database administrators can gain valuable insights into their database’s efficiency and areas of potential improvement. By simulating various workloads and scenarios, Sysbench provides a comprehensive view of how a database might perform under different conditions.

Regularly benchmarking your database can help in identifying bottlenecks, ensuring that the database is tuned for the specific needs of your applications. Whether you’re using a LiteSpeed server, an Nginx setup, or any other server configuration, understanding the underlying database performance is crucial.

Furthermore, as your website or application grows, it might transition from a shared hosting environment to a cloud hosting setup or even a dedicated server. In such scenarios, having a benchmarking tool like Sysbench can assist in making informed decisions about hardware and software upgrades.

In conclusion, while there are many factors that contribute to the overall performance of a website or application, the database remains a cornerstone. Regular testing, monitoring, and optimization using tools like Sysbench ensure that this critical component remains efficient, leading to better user experiences, higher retention rates, and overall success in the digital realm. Whether you’re a seasoned database administrator or a webmaster looking to optimize your site’s backend, integrating Sysbench into your toolkit can provide invaluable insights and data-driven results.


Leave a Reply

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