最近新到一批数据库服务器,需要测试下服务器的性能,在此列出sysbench测试数据库服务器性能的过程。
1.简易安装(也可以在github上下载结合文档安装)
[root@localhost ~]#yum install epel-release -y
[root@localhost ~]#yum install sysbench -y
[root@localhost ~]# which sysbench
/usr/bin/sysbench
[root@localhost ~]# sysbench --version
sysbench 1.0.9
2.Sysbench的测试主要包括以下几个方面
2.1 磁盘io性能
参数解释:
--file-num=N 代表生成测试文件的数量,默认为128。
--file-block-size=N 测试时所使用文件块的大小,如果想磁盘针对innodb存储引擎进行测试,可以将其设置为16384,即innodb存储引擎页的大小。默认为16384。
--file-total-size=SIZE 创建测试文件的总大小,默认为2G大小。
--file-test-mode=STRING 文件测试模式,包含:seqwr(顺序写),seqrewr(顺序读写),seqrd(顺序读),rndrd(随机读),rndwr(随机写),rndrw(随机读写)。
--file-io-mode=STRING 文件操作的模式,sync(同步),async(异步),fastmmap(快速mmap),slowmmap(慢速mmap),默认为sync同步模式。
--file-async-backlog=N 对应每个线程队列的异步操作数,默认为128。
--file-extra-flags=STRING 打开文件时的选项,这是与API相关的参数。
--file-fsync-freq=N 执行fsync()函数的频率。fsync主要是同步磁盘文件,因为可能有系统和磁盘缓冲的关系。0代表不使用fsync函数。默认值为100。
--file-fsync-all=[on|off] 每执行完一次写操作,就执行一次fsync。默认为off。
--file-fsync-end=[on|off] 在测试结束时执行fsync函数。默认为on。
--file-fsync-mode=STRING 文件同步函数的选择,同样是和API相关的参数,由于多个操作系统对于fdatasync支持不同,因此不建议使用fdatasync。默认为fsync。
--file-merged-requests=N 大多情况下,合并可能的IO的请求数,默认为0。
--file-rw-ratio=N 测试时的读写比例,默认时为1.5,即3:2。
2.2 cpu性能
参数解释:
--cpu-max-prime=N 用来选项指定最大的素数,具体参数可以根据CPU的性能来设置,默认为10000
2.3 内存分配及传输速度
参数解释:
--memory-block-size=SIZE 测试内存块的大小,默认为1K
--memory-total-size=SIZE 数据传输的总大小,默认为100G
--memory-scope=STRING 内存访问的范围,包括全局和本地范围,默认为global
--memory-hugetlb=[on|off] 是否从HugeTLB池分配内存的开关,默认为off
--memory-oper=STRING 内存操作的类型,包括read, write, none,默认为write
--memory-access-mode=STRING 内存访问模式,包括seq,rnd两种模式,默认为seq
2.4 POSIX线程性能
参数解释:
--thread-yields=N 指定每个请求的压力,默认为1000
--thread-locks=N 指定每个线程的锁数量,默认为8
2.5 调度程序性能
参数解释:
--mutex-num=N 数组互斥的总大小。默认是4096
--mutex-locks=N 每个线程互斥锁的数量。默认是50000
--mutex-loops=N 内部互斥锁的空循环数量。默认是10000
2.6 数据库性能(OLTP基准测试)
这个需要特殊配置,这里先不配置
3.开始测试
3.1对磁盘IO性能测试
sysbench测试会分为三个阶段:
prepare阶段:测试文件准备
run阶段:正式运行测试
cleanup阶段:测试文件清除
3.1.1顺序读
sysbench fileio --threads=24 --file-num=16 --file-total-size=3G --file-block-size=8k --file-test-mode=seqrd prepare
sysbench fileio --threads=24 --file-num=16 --file-total-size=3G --file-block-size=8K --file-test-mode=seqrd --time=180 --events=100000000 run
sysbench fileio --threads=24 --file-num=16 --file-total-size=3G --file-block-size=8K --file-test-mode=seqrd cleanup
3.1.2顺序写
sysbench fileio --threads=24 --file-num=16 --file-total-size=3G --file-block-size=8K --file-test-mode=seqwr prepare
sysbench fileio --threads=24 --file-num=16 --file-total-size=3G --file-block-size=8K --file-test-mode=seqwr --time=180 --events=100000000 run
sysbench fileio --threads=24 --file-num=16 --file-total-size=3G --file-block-size=8K --file-test-mode=seqwr cleanup
3.1.3随机写
sysbench fileio --threads=24 --file-num=16 --file-total-size=3G --file-block-size=8k --file-test-mode=rndwr prepare
sysbench fileio --threads=24 --file-num=16 --file-total-size=3G --file-block-size=8K --file-test-mode=rndwr --time=180 --events=100000000 run
sysbench fileio --threads=24 --file-num=16 --file-total-size=3G --file-block-size=8K --file-test-mode=rndwr cleanup
3.1.4随机读
sysbench fileio --threads=24 --file-num=16 --file-total-size=3G --file-block-size=8k --file-test-mode=rndrd prepare
sysbench fileio --threads=24 --file-num=16 --file-total-size=3G --file-block-size=8K --file-test-mode=rndrd --time=180 --events=100000000 run
sysbench fileio --threads=24 --file-num=16 --file-total-size=3G --file-block-size=8K --file-test-mode=rndrd cleanup
3.1.5顺序读写
sysbench fileio --threads=24 --file-num=16 --file-total-size=3G --file-block-size=8k --file-test-mode=seqrewr prepare
sysbench fileio --threads=24 --file-num=16 --file-total-size=3G --file-block-size=8K --file-test-mode=seqrewr --time=180 --events=100000000 run
sysbench fileio --threads=24 --file-num=16 --file-total-size=3G --file-block-size=8K --file-test-mode=seqrewr cleanup
3.1.6随机读写
sysbench fileio --threads=24 --file-num=16 --file-total-size=3G --file-block-size=8k --file-test-mode=rndrw prepare
sysbench fileio --threads=24 --file-num=16 --file-total-size=3G --file-block-size=8K --file-test-mode=rndrw --time=180 --events=100000000 run
sysbench fileio --threads=24 --file-num=16 --file-total-size=3G --file-block-size=8K --file-test-mode=rndrw cleanup
3.2cpu性能测试
sysbench cpu --threads=6 --cpu-max-prime=20000 run
threads:默认为1,一般设置为CPU核数(线程数)即可,设置过大也不会对性能带来影响
3.3内存分配及传输速度
sysbench memory --threads=6 --memory-block-size=8192 --memory-total-size=64G run
在测试的过程中,可以结合各个参数互相配合着来进行测试,如测试cpu和内存也可以配合参数file-test-mode来进行测试。