服务器性能测试
目录
一.磁盘性能... 1
1.Iozone的安装和使用... 1
2. fio的安装与使用... 2
二.CPU稳定性测试... 3
三.基准测试工具sysbench. 3
四.网络性能测试... 10
1. iperf的安装与使用... 10
一.磁盘性能
软件:Iozone (测试磁盘吞吐量)
FIO(测试磁盘IOPS)
1.Iozone的安装和使用
(1)安装
wget http://www.iozone.org/src/current/iozone-3-434.i386.rpm
yum -y install glibc nss-softokn-freebl
rpm -ivh iozone-3-434.i386.rpm
(2)使用。
/opt/iozone/bin/iozone -i 0 -i 1 -i 2 -f /mnt/iozone.txt -s 512m -Rb /opt/iozone/report/iozone-512.xls
注:建议测试文件大小为swap的两倍。
(3)参数说明
测试参数: -i # 用来指定测试内容.
0=write/rewrite
1=read/re-read
2=random-read/write
3=Read-backwards
4=Re-write-record
5=stride-read
6=fwrite/re-fwrite
7=fread/Re-fread,
8=random mix
9=pwrite/Re-pwrite
10=pread/Re-pread
11=pwritev/Re-pwritev,
12=preadv/Re-preadv
-R 产生execl格式的输出日志。
-b 将产生二进制的execl的日志文件名。
-s 测试的文件大小。
-r 文件块大小。
-a 在希望的文件系统上测试,不过只有-a的话会进行全面测试,要花费很长时间,最好用-i指定测试范围。
-g 指定最大测试文件大小。
-n 指定最小测试文件大小。
-f 指定测试文件。
-C 显示每个节点的吞吐量。
-c 测试包括文件的关闭时间
-t # 线程数
-F filename filename filename 指定临时文件组
2. fio的安装与使用
(1) 安装
wget http://freecode.com/urls/3aa21b8c106cab742bf1f20d60629e3f
yum install libaio-devel gcc
tar -zxvf fio-2.1.10.tar.gz
cd fio-2.1.10
make
make install
(2) 使用
fio -filename=/dev/sdb1 -direct=1 -iodepth 1 -thread -rw=randread -ioengine=libaio -bs=16k -size=200G -numjobs=10 -runtime=1000 -group_reporting -name=mytest
注:-rw指定读写模式,支持read,randread,write,randwrite,randrw
(3) 参数说明
filename:待测试的设备名或挂载文件名
direct:绕过OS的文件系统缓冲区测试
rw:指定读写模式,这里是测随机读性能
bs:每次请求的IO大小
size:测试的目标区域大小
name:本次测试任务的名字,随便取
rwmixwrite=30 在混合读写的模式下,写占30%
rwmixread=30 在混合读写的模式下,读占30%
二.CPU稳定性测试
软件:cpu-burn
(1)安装;
wget http://cpuburnin.com/downloads/cpuburn-in.tar.gz
tar -zxvf cpuburn-in.tar.gz
./cpuburn-in 60 (60为测试时间,单位是分)
三.基准测试工具sysbench
(1)安装。
yum -y install libtool gcc
wget http://imysql.com/wp-content/uploads/2014/09/sysbench-0.4.12-1.1.tgz
tar -zxvf sysbench-0.4.12-1.1.tgz -C /usr/local/src/
cd /usr/local/src/sysbench-0.4.12-1.1/
./autogen.sh
./configure --with-mysql-includes=/usr/local/mysql/include --with-mysql-libs=/usr/local/mysql/lib
如果mysql是默认安装直接./configure
make && make install
运行sysbench时报错找不到libmysqlclient.so.18创建以下链接
ln -s /opt/mysql-advanced-5.6.13-linux-glibc2.5-x86_64/lib/libmysqlclient.so.18 /usr/lib/
(2)使用
a).cpu性能测试
sysbench --test=cpu --cpu-max-prime=20000 run
cpu测试主要是进行素数的加法运算,在上面的例子中,指定了最大的素数为 20000,自己可以根据机器cpu的性能来适当调整数值,查看执行时间。
[root@CentOS-01 bin]# sysbench --test=cpu --cpu-max-prime=20000 run
sysbench 0.5: multi-threaded system evaluation benchmark
Running the test with following options:
Number of threads: 1
Random number generator seed is 0 and will be ignored
Primer numbers limit: 20000
Threads started!
General statistics:
total time: 34.5993s
total number of events: 10000
total time taken by event execution: 34.5608s
response time:
min: 2.94ms
avg: 3.46ms
max: 20.15ms
approx. 95 percentile: 4.26ms
Threads fairness:
events (avg/stddev): 10000.0000/0.00
execution time (avg/stddev): 34.5608/0.00
b). 磁盘IO性能测试
sysbench --test=fileio --num-threads=16 --file-total-size=3G --file-test-mode=rndrw prepare
sysbench --test=fileio --num-threads=16 --file-total-size=3G --file-test-mode=rndrw run
sysbench --test=fileio --num-threads=16 --file-total-size=3G --file-test-mode=rndrw cleanup
Extra file open flags: 0
128 files, 8Mb each
1Gb total file size
Block size 16Kb
Number of IO requests: 10000
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!
Operations performed: 6006 reads, 3994 writes, 12800 Other = 22800 Total
Read 93.844Mb Written 62.406Mb Total transferred 156.25Mb (4.7421Mb/sec)
303.49 Requests/sec executed
General statistics:
total time: 32.9499s
total number of events: 10000
total time taken by event execution: 445.0669s
response time:
min: 0.00ms
avg: 44.51ms
max: 864.01ms
approx. 95 percentile: 292.90ms
Threads fairness:
events (avg/stddev): 625.0000/54.95
execution time (avg/stddev): 27.8167/0.57
上述参数指定了最大创建16个线程,创建的文件总大小为3G,文件读写模式为随机读写。随机读写的性能为4.7m/s ,IOPS为303
--file-test-mode的6种模式
seqwr(顺序写), seqrewr(顺序读写), seqrd(顺序读), rndrd(随机读), rndwr(随机写), rndrw(随机读写)
c). 内存测试
sysbench --test=memory --memory-block-size=8k --memory-total-size=4G run
上述参数指定了本次测试整个过程是在内存中传输 4G 的数据量,每个 block 大小为 8K
d). OLTP测试
准备数据(数据库mytest要先创建好):
/usr/local/src/sysbench-0.4.12-1.1/sysbench/sysbench --mysql-host=10.1.10.108 --mysql-port=3306 --mysql-user=用户 --mysql-password=密码 --test=/usr/local/src/sysbench-0.4.12-1.1/sysbench/tests/db/oltp.lua --oltp_tables_count=32 --oltp-table-size=100000 --mysql-table-engine=InnoDB --mysql-db=mytest prepare
测试数据:
/usr/local/src/sysbench-0.4.12-1.1/sysbench/sysbench --mysql-host=10.1.10.108 --mysql-port=3306 --mysql-user=用户 --mysql-password=密码 --test=/usr/local/src/sysbench-0.4.12-1.1/sysbench/tests/db/oltp.lua --oltp_tables_count=32 --oltp-table-size=100000 --num-threads=16 --rand-init=on --mysql-table-engine=InnoDB --mysql-db=mytest run
sysbench 0.5: multi-threaded system evaluation benchmark
Running the test with following options:
Number of threads: 16
Random number generator seed is 0 and will be ignored
Threads started!
OLTP test statistics:
queries performed:
read: 327040
write: 80893
other: 41984
total: 449917
transactions: 18624 (155.16 per sec.)
deadlocks: 4736 (39.46 per sec.)
read/write requests: 407933 (3398.48 per sec.)
other operations: 41984 (349.77 per sec.)
General statistics:
total time: 120.0341s
total number of events: 18624
total time taken by event execution: 1917.8749s
response time:
min: 4.76ms
avg: 102.98ms
max: 1230.99ms
approx. 95 percentile: 224.80ms
Threads fairness:
events (avg/stddev): 1164.0000/18.72
execution time (avg/stddev): 119.8672/0.05
transactions代表测试结果的评判标准即TPS,上述测试结果是 155.16 per sec
清除数据:
/usr/local/src/sysbench-0.4.12-1.1/sysbench/sysbench --mysql-host=10.1.10.108 --mysql-port=3306 --mysql-user=用户 --mysql-password=密码 --test=/usr/local/src/sysbench-0.4.12-1.1/sysbench/tests/db/oltp.lua --oltp_tables_count=32 --oltp-table-size=100000 --mysql-table-engine=InnoDB --mysql-db=mytest cleanup
OLTP测试常用参数
--oltp-test-mode=STRING
test type to use {simple,complex,nontrx,sp} [complex]//采用得测试模式
--oltp-reconnect-mode=STRING reconnect mode
{session,transaction,query,random} [session]//重新连接模式{session(不使用重新连接。每个线程断开只在测试结束),transaction(在每次事务结束后重新连接),query(在每个SQL语句执行完重新连接),random(对于每个事务随机选择以上重新连接模式)}。默认是session
--oltp-sp-name=STRING
name of store procedure to call in SP test mode []//跟上面的测试对应,采用自定义存储过程
--oltp-read-only=[on|off] generate only
'read' queries (do not modify database) [off]//产生只读查询
--oltp-skip-trx=[on|off] skip
BEGIN/COMMIT statements [off]//感觉相当于事务没用
--oltp-range-size=N
range size for range queries [100]//查询的范围1-100行,可定小于--oltp-table-size
--oltp-point-selects=N
number of point selects [10]//一个事物中点(点指的是测试模式语句中的id=N)查询十次
--oltp-simple-ranges=N
number of simple ranges [1]//一个事务中的范围查询的次数(范围指的是between
N and M)
--oltp-sum-ranges=N
number of sum ranges [1]
--oltp-order-ranges=N
number of ordered ranges [1]
--oltp-distinct-ranges=N number of
distinct ranges [1]
--oltp-index-updates=N
number of index update [1]
--oltp-non-index-updates=N number of non-index
updates [1]
--oltp-nontrx-mode=STRING mode for
non-transactional test {select, update_key, update_nokey, insert, delete}
[select]//nontrx模式只用select语句
--oltp-auto-inc=[on|off] whether
AUTO_INCREMENT (or equivalent) should be used on id column [on]//AUTO_INCREMENT开启
--oltp-connect-delay=N
time in microseconds to sleep after connection to database [10000]//什么含义?
--oltp-user-delay-min=N minimum
time in microseconds to sleep after each request [0]
--oltp-user-delay-max=N maximum
time in microseconds to sleep after each request [0]
--oltp-table-name=STRING name of test
table [sbtest]//测试的表,默认sbtest
--oltp-table-size=N
number of records in test table [10000]//表的行数
--oltp-dist-type=STRING random
numbers distribution {uniform,gaussian,special} [special]----参考全局参数
--oltp-dist-iter=N
number of iterations used for numbers generation [12]
--oltp-dist-pct=N
percentage of values to be treated as 'special' (for special distribution) [1]
--oltp-dist-res=N
percentage of 'special' values to use (for special distribution) [75]
--oltp-tables-count=N 表示生成几个测试表
--mysql-table-engine=innodb 指定表类型
四.网络性能测试
1. iperf的安装与使用
(1).iperf安装
wget https://iperf.fr/download/iperf_3.1/iperf-3.1-source.tar.gz
yum –y intall gcc
tar –zxvf iperf-3.1-source.tar.gz
cd iperf-3.1
./configure
make && make install
(2)使用
服务端
iperf3 -s -D
客户端
iperf3 -c X.X.X.X -t 10 –b 1000M –P 10
X.X.X.X替换为服务器端IP
[ ID] Interval Transfer Bandwidth Retr
[ 4] 0.00-10.00 sec 3.45 GBytes 2.96 Gbits/sec 0 sender
[ 4] 0.00-10.00 sec 3.44 GBytes 2.96 Gbits/sec receiver
Transfer 10s内发送的总数据,Bandwidth传输带宽
(3) 常用参数
-s 服务端运行
-D 服务端己daemon方式运行
-c 客户端模式运行
-P 设定并发连接数
-R reverse模式(服务端发送,客户端接收)
-u 以UDP协议发送
-t 测试时间多少秒,默认10s
五.附
Sysbench 测试IO的脚本
如果需要测试seqwr(顺序写), seqrewr(顺序读写), seqrd(顺序读), rndrd(随机读), rndwr(随机写), rndrw(随机读写)等6种模式,并且还可能需要测试不同的线程和不同的文件块下磁盘的性能表现,这时,可以使用如下脚本达到测试目的
#!/bin/bash
#==============================================================================
#
# FILE: sysbench_auto.sh
#
# USAGE: ./sysbench_auto.sh
#
# DESCRIPTION: This file is sysbench_auto.sh
# AUTHOR: Kevin Lu (kevin), kevin@gmail.com
# ORGANIZATION: cmcc
# CREATED: 02/26/2014 17:35
# REVISION: v1.0.1
#==============================================================================
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-mo
de-$mode-threads-$threads-blksz-$blksize 2>&1
done
done
sysbench --test=fileio --file-total-size=$size cleanup
done
done
done