Sysbench is a free & open source benchmarking tool that is used to benchmark Linux. It evaluates OS parameters like CPU usage, memory usage, Disk IO & MySQL performance. Especially it becomes extremely important to benchmark these parameters when running load intensive database.
In this tutorial, we will install Sysbench to benchmark Linux & will also learn how to use it with the help of some examples.
(Recommended Read: Monitoring network bandwidth with iftop command)
(Also read: Monitoring system resources using SAR (System Activity Report) )
Sysbench Installation
Sysbench is available with default repositories of RHEL & CentOS, so we can install it using the following command,
$ sudo yum install sysbench
For installing on Ubuntu, use
$ sudo apt-get install sysbench
For installation on Fedora, use
$ dnf install sysbench
Default repositories for both Ubuntu, fedora & CentOS might have older versions, If you wish to get the latest version of sysbench, use the following method.
Open terminal & execute the following command,
CentOS/RHEL
$ curl -s https://packagecloud.io/install/repositories/akopytov/sysbench/script.rpm.sh | sudo bash
$ sudo yum -y install sysbench
Ubuntu
$ curl -s https://packagecloud.io/install/repositories/akopytov/sysbench/script.deb.sh | sudo bash
$ sudo apt -y install sysbench
Fedora
$ curl -s https://packagecloud.io/install/repositories/akopytov/sysbench/script.rpm.sh | sudo bash
$ sudo dnf -y install sysbench
This will install the latest version of sysbench available (which at the time of writing this tutorial is 1.0.10 )
Sysbench Usage
CPU Benchmark
To perform the CPU benchmark on Linux, use the following command,
$ sysbench cpu --cpu-max-prime=2000 run
This will generate the following output,
sysbench 1.0.10 (using bundled LuaJIT 2.1.0-beta2)
Running the test with following options:
Number of threads: 1
Initializing random number generator from current time
Prime numbers limit: 2000
Initializing worker threads...
Threads started!
CPU speed:
events per second: 9464.46
General statistics:
total time: 10.0001s
total number of events: 94667
Latency (ms):
min: 0.10
avg: 0.10
max: 2.01
95th percentile: 0.11
sum: 9895.49
Threads fairness:
events (avg/stddev): 94667.0000/0.00
execution time (avg/stddev): 9.8955/0.00
Though it generates report with lots of statistics, main thing to check on CPU benchmarking is 'total time' under 'General Statistics'
total time: 10.0001s
Memory Benchmarking
To benchmark Linux system's memory (RAM), execute the following command,
$ sysbench memory --threads=2 run
This will produce the following output,
sysbench 1.0.10 (using bundled LuaJIT 2.1.0-beta2)
Running the test with following options:
Number of threads: 2
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: 7074390 (707274.30 per second)
6908.58 MiB transferred (690.70 MiB/sec)
General statistics:
total time: 10.0000s
total number of events: 7074390
Latency (ms):
min: 0.00
avg: 0.00
max: 10.02
95th percentile: 0.00
sum: 6729.58
Threads fairness:
events (avg/stddev): 3537195.0000/1640.00
execution time (avg/stddev): 3.3648/0.01
Here two things that are to be considered are 'Total Operations' & amount transferred, i.e.
Total operations: 7074390 (707274.30 per second)
6908.58 MiB transferred (690.70 MiB/sec)
IO Benchmarking
While performing IO benchamark on Linux systems, we will have to first create some test file. To create test files, use the following command,
$ sysbench --test=fileio --file-total-size=50G prepare
Please make sure that you should select size of test file to be more than your amount of RAM, so that the IO process does not get affected duet RAM operation. Test file creation will take some time based on amount you have selected. Once test files have been created, run the following command to start the benchmarking,
$ sysbench --test=fileio --file-total-size=150G --file-test-mode=rndrw --max-time=300 --max-requests=0 run
this will produce the following report,
time=300 --max-requests=0 run
sysbench: /usr/lib/libmysqlclient.so.18: no version information available (required by sysbench)
sysbench 0.4.12: multi-threaded system evaluation benchmark
Running the test with following options:
Number of threads: 1
Initializing random number generator from timer.
Extra file open flags: 0
128 files, 1.1719Gb each
150Gb total file size
Block size 16Kb
Number of random requests for random IO: 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
Threads started!
Time limit exceeded, exiting...
Done.
Operations performed:
600 Read, 400
Write, 1186 Other = 2186 Total
Read 9.375Mb
Written 6.25Mb
Total transferred 15.625Mb (53.316Kb/sec)
3.33 Requests/sec executed
Test execution summary:
total time: 300.0975s
total number of events: 1000
total time taken by event execution: 158.7611
per-request statistics:
min: 0.01ms
avg: 158.76ms
max: 2596.96ms
approx. 95 percentile: 482.29ms
Threads fairness:
events (avg/stddev): 1000.0000/0.00
execution time (avg/stddev): 158.7611/0.00
Main thing to check here are,
Read 9.375Mb
Written 6.25Mb
To cleanup the test data after becnhmarking, use
$ sysbench --test=fileio --file-total-size=150G cleanup
Mysql Benchmarking
To benchmark mysql, we will first create a table with 50000 rows in database named 'test', using the following command
$ sysbench --test=oltp –oltp-table-size=50000 --mysql-db=test --mysql-user=root --mysql-password=passwd prepare
Once the operation has been completed, execute the following command to start the Mysql Bechmarking,
$ sysbench --test=oltp --oltp-table-size=500000 --mysql-db=test --mysql-user=root --mysql-password=yourrootsqlpassword --max-time=60 --oltp-read-only=on --max-requests=0 --num-threads=8 run
This will produce the following result,
No DB drivers specified, using mysql
Running the test with following options:
Number of threads: 8
Doing OLTP test.
Running mixed OLTP test
Doing read-only test
Using Special distribution (12 iterations, 1 pct of values are returned in 75 pct cases)
Using "BEGIN" for starting transactions
Using auto_inc on the id column
Threads started!
Time limit exceeded, exiting...
(last message repeated 7 times)
Done.
OLTP test statistics:
queries performed:
read: 2253860
write: 0
other: 321980
total: 2575840
transactions: 160990 (2683.06 per sec.)
deadlocks: 0 (0.00 per sec.)
read/write requests: 2253860 (37562.81 per sec.)
other operations: 321980 (5366.12 per sec.)
Test execution summary:
total time: 60.0024s
total number of events: 160990
total time taken by event execution: 479.3419
per-request statistics:
min: 0.81ms
avg: 2.98ms
max: 3283.40ms
approx. 95 percentile: 4.62ms
Threads fairness:
events (avg/stddev): 20123.7500/63.52
execution time (avg/stddev): 59.9177/0.00
Main parameter to check here is 'transactions per second'
transactions: 160990 (2683.06 per sec.)
To cleanup the test data, run
$ sysbench --test=oltp --mysql-db=test --mysql-user=root --mysql-password=yourrootsqlpassword cleanup
This was our tutorial on how to install Sysbench to benchmark Linux. If you have any query or questions regarding this tutorial, please share it with us using the comment box below.
If you think we have helped you or just want to support us, please consider these :-
Connect to us: Facebook | Twitter | Google Plus
Donate us some of you hard earned money: [paypal-donation]
Linux TechLab is thankful for your continued support.
I don have sysbench available on my default repositories (RHEL 7.6), please specify with repository you use that contains sysbench
Hi,
This is a but outdated content. Running for example this on my system outputs:
WARNING: the –test option is deprecated. You can pass a script name or path on the command line without any options.
sysbench 1.0.11 (using system LuaJIT 2.1.0-beta3)
FATAL: Cannot find benchmark ‘oltp’: no such built-in test, file or module
~$ sysbench cpu –cpu-max-prime=2000 run
Unrecognized command line argument: run
Are you instructions up to date?
its sysbench cpu –cpu-max-prime=2000. WordPress added both – to single -.