SysBench- Benchmark CPU, File I/O and Memory in CentOS

SysBench is a modular, cross-platform and multi-threaded benchmark tool for evaluating OS parameters that are important for a system running a database under intensive load. Benchmark CPU, File I/O and Memory in CentOS Server.

Current features allow to test the following system parameters:

  • file I/O performance
  • scheduler performance
  • memory allocation and transfer speed
  • POSIX threads implementation performance
  • database server performance

Install SysBench on CentOS 7

# yum install epel-release -y
# yum install sysbench -y
sysbench-options

sysbench-options

General syntax
The general syntax for SysBench is as follows:

sysbench [common-options] --test=name [test-options] command

CPU workload

You can benchmark your CPU performance as follows, The benchmark can be configured with the number of simultaneous threads and the maximum number to verify if it is a prime.

# sysbench --test=cpu --cpu-max-prime=20000 run
sysbench 1.0.6 (using system LuaJIT 2.0.4)

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!



General statistics:
total time: 10.0018s
total number of events: 3652

Latency (ms):
min: 2.67
avg: 2.74
max: 13.85
95th percentile: 2.81
sum: 10000.00

Threads fairness:
events (avg/stddev): 3652.0000/0.00
execution time (avg/stddev): 10.0000/0.00

Verify the the Total time statistics.

 

File IO workload

Before you do the file IO benchmark, you should confirm your drive and mount it if it is additional drive. Here using fileio, you will need to create a set of test files to work on. It is recommended that the size is larger than the available memory to ensure that file caching does not influence the workload too much.

# time sysbench --test=fileio --file-total-size=48G --file-num=24 prepare
sysbench 1.0.6 (using system LuaJIT 2.0.4)

24 files, 2097152Kb each, 49152Mb total
Creating files for the test...
Extra file open flags: 0
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
Creating file test_file.15
Creating file test_file.16
Creating file test_file.17
Creating file test_file.18
Creating file test_file.19
Creating file test_file.20
Creating file test_file.21
Creating file test_file.22
Creating file test_file.23
51539607552 bytes written in 594.02 seconds (82.74 MiB/sec).

real 9m54.175s
user 0m0.162s
sys 0m51.073s

 

You can tell the sysbench which kind of workload you want to run: sequential reads, writes or random reads, writes, or a combination.

We are going to use random read/write is used (rndrw) for example testing. Once you generated the files using above command, try to run the following commands.

# sysbench fileio --file-total-size=48G --file-num=24 --file-test-mode=rndrw --time=1800 --file-rw-ratio=1 --threads=16 --max-requests=0 run
sysbench 1.0.6 (using system LuaJIT 2.0.4)

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



Extra file open flags: 0
24 files, 2GiB each
48GiB total file size
Block size 16KiB
Number of IO requests: 0
Read/Write ratio for combined random IO test: 1.00
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
Initializing worker threads...

Threads started!



File operations:
reads/s: 233.63
writes/s: 233.63
fsyncs/s: 112.14

Throughput:
read, MiB/s: 3.65
written, MiB/s: 3.65

General statistics:
total time: 1800.0621s
total number of events: 1042957

Latency (ms):
min: 0.00
avg: 27.61
max: 300.08
95th percentile: 101.13
sum: 28798434.80

Threads fairness:
events (avg/stddev): 65184.8125/349.16
execution time (avg/stddev): 1799.9022/0.02

 

Once completed, you can check the “Throughput” and “File operations” result to get the details.

After the benchmark, you can delete the 50GB test file from the server using the below command.

#sysbench --test=fileio --file-total-size=50G cleanup

You can also do some workload using sysbench.

the memory workload
the mutex workload
the threads workload

 

 

libguestfs – Manage virtual machine disk images

libguestfs is a C library tool for creating, accessing and modifying virtual machine disk images. You can look inside the disk images, modify the files they contain, create them from scratch, resize them, and much more.

The easy way to modify files in a VM’s disk image without powering on the VM, you could “mount” the disk image. You then would be able to modify the content of the disk image before unmounting it. libguestfs works with any disk image, including ones created in VMware, KVM, qemu, VirtualBox, Xen, and many other hypervisors, and ones which you have created from scratch.

Manage virtual machine disk images

Overview of libguestfs

There are many tools which use libguestfs:

guestfish – Interactive and scriptable shell.

guestmount – Mount filesystems from any guest or disk image on the host.

guestunmount – unmount guest filesystem

virt-alignment – scan Check alignment of partitions in guests.

virt-builder – quick image builder

virt-cat – Display a file from a guest.

virt-copy-in – Copy files and directories into a guest.

virt-copy-out – Copies files and directories out of a virtual machine disk image or named libvirt domain.

virt-customize – customize virtual machines

virtdf Display – disk usage of a guest.

virt-diff – Differences between files in two virtual machines

virt-edit – Edit a file in a guest.

virtfilesystems – Display the partitions, filesystems, logical volumes etc. in a guest.

virt-inspector – Inspect a guest and produce a report detailing the operating system, version, applications installed and more.

virt-format – erase and make blank disks

virt-ls – List files and directories in a guest.

virt-log – display log files

virt-make-fs – Make a new filesystem.

virt-rescue – Rescue mode for guests.

virt-resize – Resize a guest.

virt-sparsify – Make a disk sparse.

virtsysprep – Reset a guest to “factory configuration”.

virt-tar-in – Copy files from a tarball into a guest.

virt-tar-out – Copy files out of a guest into a tarball.

virt-win-reg – Export and merge Windows Registry entries from a Windows guest

libguestfs-test-tool — test libguestfs

libguestfs-make-fixed-appliance — make libguestfs fixed appliance

BoxGrinder & Oz Projects that can create guests from scratch.

OpenStack Uses libguestfs to inject files into guests.

virt-manager Uses libguestfs to display icons and applications in guests.

virt-v2v & virt-p2v Migrate between physical machines and different hypervisors

 

How to install libguestfs toolset on Linux

On Debian-based system:

# sudo apt-get install libguestfs-tools

On Red Hat-based system:

# sudo yum install libguestfs-tools

 

Example:

To mount qcow2 image volume at localfolder.

guestmount -a /path/to/qcow2/image -m <device> /local_path

The “-m <device>” option is used to specify a partition within the disk image.

run the following command.

#guestmount -a /images/testcentos.qcow2 -m /dev/sda1 /mnt

By default, the disk image is mounted in “read-write” mode. So you can modify any file in /mnt after mounting it.