一、sysbench压力测试工具简介:
sysbench是一个开源的、模块化的、跨平台的多线程性能测试工具,可以用来进行CPU、内存、磁盘I/O、线程、数据库的性能测试。目前支持的数据库有MySQL、Oracle和PostgreSQL。以下操作都将以支持MySQL数据库为例进行
1. sysbench工具安装:
默认支持MySQL,如果需要测试Oracle/PostgreSQL,则在configure时需要加上-with-oracle或者-with-pgsql参数.
编译安装
tar -zxvf sysbench-1.0.tar.gz
cd sysbench-1.0
./autogen.sh
关键的三步:configure && make && make install
首先是./configure命令,sysbench默认是支持MySQL的benchmarking的,如果不加任何选项则要求保证MySQL的安装路径都是默认的标准路径,headfile位于/usr/include目录下,libraries位于/usr/lib/目录下。因为我的MySQL是源码编译安装的,安装路径是放在/usr/local/mysql下,所以这里要添加相应的选项命令:
# ./configure --prefix=/usr/local/sysbench --with-mysql=/usr/local/mysql \
--with-mysql-includes=/usr/local/mysql/include/mysql/ \
--with-mysql-libs=/usr/local/mysql/lib/mysql/
2.Sysbench的测试主要包括以下几个方面:
1、磁盘io性能
2、cpu性能
3、内存分配及传输速度
4、POSIX线程性能
5、调度程序性能
6、数据库性能(OLTP基准测试).
例子:
2.1 对磁盘IO性能的测试
2.2.1 创建fileio文件
创建初始化fileio文件:
sysbench --test=fileio --file-num=16 --file-total-size=2G cleanup
测试不同的方式的shell脚本--file-test-mode=STRING 文件测试模式,包含:seqwr(顺序写), seqrewr(顺序读写), seqrd(顺序读), rndrd(随机读), rndwr(随机写), rndrw(随机读写)
#!/bin/bash
for size in {8G,64G}
do
for mode in {seqwr,seqrewr,seqrd,rndrd,rndwr,rndrw}
do
for blksize in {4096,16384}
do
sysbench --test=fileio --file-num=64 --file-total-size=$size prepare
for threads in {1,4,8,16,32}
do
echo "============testing $blksize in $threads threads"
echo PARAS $size $mode $threads $blksize > sysbench-size-$size-mode-$mode-threads-$threads-blksz-$blksize
for i in {1,2,3}
do
sysbench --test=fileio --file-total-size=$size --file-test-mode=$mode --max-time=180 --max-requests=100000 --num-threads=$threads --init-rng=on --file-num=64 --file-extra-flags=direct --file-fsync-freq=0 --file-block-size=$blksize run|tee -a sysbench-size-$size-mode-$mode-threads-$threads-blksz-$blksize 2>&1
done
done
sysbench --test=fileio --file-total-size=$size cleanup
done
done
done
2.2 测试cpu 测试计算素数的时间
sysbench --test=cpu --cpu-max-prime=20000 run
2.3 OLTP的基准测试
2.3.1 生成测试的表
sysbench --test=oltp --oltp-table-size=1000000 --mysql-db=test --mysql-user=root --mysql-password='12345' prepare
2.3.2 测试
sysbenh --test=oltp --oltp-table-size=1000000 -mysql-db=test --mysql-user=root --mysql-password='12345' --max-time=60 --oltp-read-only=on --max-requests=0 --num-threads=8 run
8个并发线程只读模式,时长60s
注意,sysbench测试不一定代表真实环境的测试,这个工具只是一个”基准测试“。
sysbench是一个开源的、模块化的、跨平台的多线程性能测试工具,可以用来进行CPU、内存、磁盘I/O、线程、数据库的性能测试。目前支持的数据库有MySQL、Oracle和PostgreSQL。以下操作都将以支持MySQL数据库为例进行
1. sysbench工具安装:
默认支持MySQL,如果需要测试Oracle/PostgreSQL,则在configure时需要加上-with-oracle或者-with-pgsql参数.
编译安装
tar -zxvf sysbench-1.0.tar.gz
cd sysbench-1.0
./autogen.sh
关键的三步:configure && make && make install
首先是./configure命令,sysbench默认是支持MySQL的benchmarking的,如果不加任何选项则要求保证MySQL的安装路径都是默认的标准路径,headfile位于/usr/include目录下,libraries位于/usr/lib/目录下。因为我的MySQL是源码编译安装的,安装路径是放在/usr/local/mysql下,所以这里要添加相应的选项命令:
# ./configure --prefix=/usr/local/sysbench --with-mysql=/usr/local/mysql \
--with-mysql-includes=/usr/local/mysql/include/mysql/ \
--with-mysql-libs=/usr/local/mysql/lib/mysql/
2.Sysbench的测试主要包括以下几个方面:
1、磁盘io性能
2、cpu性能
3、内存分配及传输速度
4、POSIX线程性能
5、调度程序性能
6、数据库性能(OLTP基准测试).
例子:
2.1 对磁盘IO性能的测试
2.2.1 创建fileio文件
创建初始化fileio文件:
sysbench --test=fileio --file-num=16 --file-total-size=2G prepare
sysbench --test=fileio --file-total-size=2G --file-test-mode=rndrd --max-time=180 --max-requests=100000000 --num-threads=16 --init-rng=on --file-num=16 --file-extra-flags=direct --file-fsync-freq=0 --file-block-size=16384 run
sysbench --test=fileio --file-num=16 --file-total-size=2G cleanup
测试不同的方式的shell脚本--file-test-mode=STRING 文件测试模式,包含:seqwr(顺序写), seqrewr(顺序读写), seqrd(顺序读), rndrd(随机读), rndwr(随机写), rndrw(随机读写)
#!/bin/bash
for size in {8G,64G}
do
for mode in {seqwr,seqrewr,seqrd,rndrd,rndwr,rndrw}
do
for blksize in {4096,16384}
do
sysbench --test=fileio --file-num=64 --file-total-size=$size prepare
for threads in {1,4,8,16,32}
do
echo "============testing $blksize in $threads threads"
echo PARAS $size $mode $threads $blksize > sysbench-size-$size-mode-$mode-threads-$threads-blksz-$blksize
for i in {1,2,3}
do
sysbench --test=fileio --file-total-size=$size --file-test-mode=$mode --max-time=180 --max-requests=100000 --num-threads=$threads --init-rng=on --file-num=64 --file-extra-flags=direct --file-fsync-freq=0 --file-block-size=$blksize run|tee -a sysbench-size-$size-mode-$mode-threads-$threads-blksz-$blksize 2>&1
done
done
sysbench --test=fileio --file-total-size=$size cleanup
done
done
done
2.2 测试cpu 测试计算素数的时间
sysbench --test=cpu --cpu-max-prime=20000 run
2.3 OLTP的基准测试
2.3.1 生成测试的表
sysbench --test=oltp --oltp-table-size=1000000 --mysql-db=test --mysql-user=root --mysql-password='12345' prepare
2.3.2 测试
sysbenh --test=oltp --oltp-table-size=1000000 -mysql-db=test --mysql-user=root --mysql-password='12345' --max-time=60 --oltp-read-only=on --max-requests=0 --num-threads=8 run
8个并发线程只读模式,时长60s
注意,sysbench测试不一定代表真实环境的测试,这个工具只是一个”基准测试“。