对于现在的计算机来讲,整个计算机的性能主要受磁盘IO速度的影响,内存、CPU包括主板总线的速度已经很快了。

基础检测方法

1、dd命令

dd命令功能很简单,就是从一个源读取数据以bit级的形式写到一个目标地址,通过这种方式我们就可以检测我们实际磁盘在linux系统中的读写性能,不需要经过任何检测软件而就是去读取数据,一般来讲用dd来检测磁盘的性能也被认为是最接近真实情况。

用法:dd if[数据从哪里读取,一般来讲从dev下的zero设备,这个设备不断返回0作为数据源]  of[把读取的文件写入哪个文件] bs[block size,每次读写基本快的大小] count[总共读写多少个bs] conv=fdatasync[在linux中有很强的内存缓存机制,为了提高系统性能,linux会大量使用内存作为硬盘读写缓存,所以这里用这个参数来保证数据是直接写入硬盘]

示例:

dd if=/dev/zero of=testfile bs=1M count= conv=fdatasync

在我的虚拟机上结果如下:

[root@localhost ~]# dd if=/dev/zero of=testfile bs=1M count= conv=fdatasync
+ records in
+ records out
bytes ( MB) copied, 19.6677 s, 27.3 MB/s

一般建议多次运行这个命令取平均值,在每次执行上面的命令前,建议用下面的命令来清除缓存:

echo  > /proc/sys/vm/drop_caches

通过dd命令测试往往不是很严谨也不是很科学,因为可能会受cpu使用率和后台服务影响。

2、hdparm命令

hdparm命令专门用来去获取修改测试磁盘信息。hdparm必须在管理员权限下运行。

用法:hdparm -t 要测试的磁盘

示例:

# hdparm -t /dev/sda

结果:

[root@localhost ~]# hdparm -t /dev/sda

/dev/sda:
Timing buffered disk reads: MB in 3.01 seconds = 147.35 MB/sec
[root@localhost ~]# hdparm -t /dev/sda /dev/sda:
Timing buffered disk reads: MB in 3.00 seconds = 269.21 MB/sec

可以看到两次运行结果差距比较大,所以建议多次运行取平均值。

用这两种方式测试出来的结果是非常简单,专业测试磁盘性能时,不仅需要知道读写性能,还要区分读写数据大小(4k/16k/32k),还要测试是顺序读写还是随机读写,如果是机械硬盘还要测试内磁道和外磁道的速率差距等等。

高级检测方法

1、bonnie++

可通过yum安装(不包含在linux默认的yum源中,建议安装repoforge源):

yum install -y bonnie++

用法:bonnie++ -u 用户名 -s 测试读写文件大小

示例:

bonnie++ -u root -s 2g

默认情况下,会写一个4G大小的文件,分为4份,会通过读写随机操作对系统IO进行全面测试,由于写的文件比较大,所以时间会比较长。

结果:

[root@localhost ~]# bonnie++ -u root -s 2g
Using uid:, gid:.
Writing a byte at a time...done
Writing intelligently...done
Rewriting...done
Reading a byte at a time...done
Reading intelligently...done
start 'em...done...done...done...done...done...
Create files in sequential order...done.
Stat files in sequential order...done.
Delete files in sequential order...done.
Create files in random order...done.
Stat files in random order...done.
Delete files in random order...done.
Version 1.96 ------Sequential Output------ --Sequential Input- --Random-
Concurrency -Per Chr- --Block-- -Rewrite- -Per Chr- --Block-- --Seeks--
Machine Size K/sec %CP K/sec %CP K/sec %CP K/sec %CP K/sec %CP /sec %CP
localhost.locald 2G
Latency 42230us 2804ms 284ms 8198us 5820us 4819us
Version 1.96 ------Sequential Create------ --------Random Create--------
localhost.localdoma -Create-- --Read--- -Delete-- -Create-- --Read--- -Delete--
files /sec %CP /sec %CP /sec %CP /sec %CP /sec %CP /sec %CP
+++++ +++ +++++ +++ +++++ +++ +++++ +++
Latency 2539us 853us 993us 1675us 284us 1234us
1.96,1.96,localhost.localdomain,,,2G,,,,,,,,,,,,,,,,,,,,,+++++,+++,+++++,+++,,,+++++,+++,+++++,+++,42230us,2804ms,284ms,8198us,5820us,4819us,2539us,853us,993us,1675us,284us,1234us

这个格式实在有点乱,不过好在这个软件还提供了把结果转换成html表格的工具(用最后一行转换):

echo 1.96,1.96,localhost.localdomain,,,2G,,,,,,,,,,,,,,,,,,,,,+++++,+++,+++++,+++,,,+++++,+++,+++++,+++,42230us,2804ms,284ms,8198us,5820us,4819us,2539us,853us,993us,1675us,284us,1234us | bon_csv2html >> bon_result.html

bon_result.html的显示如下:

这个就好看多了,简单解释一下:

Sequential Output(顺序输出,实际是写操作)下的 Per Char是值用putc方式写,毫无疑问,因为cache的line总是大于1字节的,所以不停的骚扰CPU执行putc,看到cpu使用率是99%.写的速度是0.3MB/s,非常慢了。

Sequential Output下的block是按照block去写的,明显CPU使用率就下来了,速度也上去了,是31MB/s,跟上面用dd测试的差不多。

Sequential Input(顺序输入,实际是读操作)下的Per Char是指用getc的方式读文件,速度是2.5MB/s,CPU使用率是99%。

Sequential Input下的block是指按照block去读文件,速度是50MB/s,CPU使用率是64%。

Random Seeks是随机寻址,每秒寻址9000多次还算可以的。

Sequential Create(顺序创建文件)

Random Create(随机创建文件)

有的结果是很多+号,这表示bonner++认为值不可靠,于是不输出。一般来说是因为执行的很快,一般来说不是系统瓶颈,所以不用担心。

2、iozone

iozone提供的信息更全面和精确,所以iozone是系统性能测试中用的最多的工具之一。

iozone使用略复杂,这里只用最常用的一些参数:

-l:最小的进程数量,用于并发测试,不想测多进程可以设置为1。

-u:最大的进程数量,用于并发测试,不想测多进程可以设置为1。

-r:默认读写基本单位,如16k,这个值一般跟测试的应用有关,如要测试数据库,这个值就跟数据库的块大小一致。

-s:默认读写的大小,建议这个值大一些(一般为2倍内存大小),因为iozone并不会规避低层的缓存,所以如果值比较小,可能直接在内存中就完成了。

-F:指定缓存文件

示例:

iozone -l  -u  -r 16k -s 2g -F tempfile

结果:

Children see throughput for   initial writers  =   31884.46 kB/sec
Parent sees throughput for initial writers = 30305.05 kB/sec
Min throughput per process = 31884.46 kB/sec
Max throughput per process = 31884.46 kB/sec
Avg throughput per process = 31884.46 kB/sec
Min xfer = 2097152.00 kB Children see throughput for rewriters = 102810.49 kB/sec
Parent sees throughput for rewriters = 95660.98 kB/sec
Min throughput per process = 102810.49 kB/sec
Max throughput per process = 102810.49 kB/sec
Avg throughput per process = 102810.49 kB/sec
Min xfer = 2097152.00 kB Children see throughput for readers = 450193.59 kB/sec
Parent sees throughput for readers = 450076.28 kB/sec
Min throughput per process = 450193.59 kB/sec
Max throughput per process = 450193.59 kB/sec
Avg throughput per process = 450193.59 kB/sec
Min xfer = 2097152.00 kB Children see throughput for re-readers = 451833.53 kB/sec
Parent sees throughput for re-readers = 451756.47 kB/sec
Min throughput per process = 451833.53 kB/sec
Max throughput per process = 451833.53 kB/sec
Avg throughput per process = 451833.53 kB/sec
Min xfer = 2097152.00 kB Children see throughput for reverse readers = 61854.02 kB/sec
Parent sees throughput for reverse readers = 61851.88 kB/sec
Min throughput per process = 61854.02 kB/sec
Max throughput per process = 61854.02 kB/sec
Avg throughput per process = 61854.02 kB/sec
Min xfer = 2097152.00 kB Children see throughput for stride readers = 43441.66 kB/sec
Parent sees throughput for stride readers = 43439.83 kB/sec
Min throughput per process = 43441.66 kB/sec
Max throughput per process = 43441.66 kB/sec
Avg throughput per process = 43441.66 kB/sec
Min xfer = 2097152.00 kB Children see throughput for random readers = 47707.72 kB/sec
Parent sees throughput for random readers = 47705.00 kB/sec
Min throughput per process = 47707.72 kB/sec
Max throughput per process = 47707.72 kB/sec
Avg throughput per process = 47707.72 kB/sec
Min xfer = 2097152.00 kB Children see throughput for mixed workload = 50807.69 kB/sec
Parent sees throughput for mixed workload = 50806.24 kB/sec
Min throughput per process = 50807.69 kB/sec
Max throughput per process = 50807.69 kB/sec
Avg throughput per process = 50807.69 kB/sec
Min xfer = 2097152.00 kB Children see throughput for random writers = 45131.93 kB/sec
Parent sees throughput for random writers = 43955.32 kB/sec
Min throughput per process = 45131.93 kB/sec
Max throughput per process = 45131.93 kB/sec
Avg throughput per process = 45131.93 kB/sec
Min xfer = 2097152.00 kB

从上面的结果中可以看到各种方式下系统磁盘的读写性能。

PS:其实下面还有结果,只是我的虚拟机磁盘满了,崩溃了。

参考文档

1、Linux硬盘性能检测

2、了解你的磁盘之使用bonnie++测试磁盘性能

Linux硬盘性能检测的更多相关文章

  1. 第三十六章 Linux常用性能检测的指令

    作为一个Linux运维人员,介绍下常用的性能检测指令! 一.uptime 命令返回的信息: 19:08:17              //系统当前时间 up 127 days,  3:00     ...

  2. linux服务器性能检测工具nmon使用

    今天介绍一款linux系统服务器性能检测的工具-nmon及nmon_analyser (生成性能报告的免费工具),亲测可用. 一.介绍 nmon 工具可以帮助在一个屏幕上显示所有重要的性能优化信息,并 ...

  3. (转)Linux常用性能检测命令

    一.uptime     Uptime命令的显示结果包括服务器已经运行了多长时间,有多少登陆用户和对服务器性能的总体评估(load average).load average值分别记录了上个1分钟,5 ...

  4. Linux硬盘的检测(原创)

    http://czmmiao.iteye.com/blog/1058215 概述 随着硬盘容量.速度的快速发展,硬盘的可靠性问题越来越重要,今天的单块硬盘存储容量可轻松达到1TB,硬盘损坏带来的影响非 ...

  5. Linux服务器性能检测命令集锦

    uptime $ uptime 23:51:26 up 21:31, 1 user, load average: 30.02, 26.43, 19.02 这个命令可以快速查看机器的负载情况.在Linu ...

  6. Linux硬盘的检测--smartctl详细介绍

    概述  随着硬盘容量.速度的快速发展,硬盘的可靠性问题越来越重要,今天的单块硬盘存储容量可轻松达到1TB,硬盘损坏带来的影响非常巨大.不同的文件系统(xfs,reiserfs,ext3)都有自己的检测 ...

  7. Linux常用性能检测命令解释

    1.uptime [root@smgsim02 ~]# uptime 15:08:15 up 98 days, 4:19, 2 users, load average: 0.07, 0.29, 0.1 ...

  8. 性能检测工具介绍-Linux系统命令行

    本文介绍的关于Linux自带命令进行性能检测的介绍,详细介绍这些linux自带的工具的使用. 一.uptime uptime命令的显示结果包括服务器已经运行了多长时间,有多少登陆用户和对服务器性能的总 ...

  9. Centos硬盘IO性能检测命令iostat[转]

    Centos硬盘IO性能检测命令iostat[转] 在Linux下频繁存取文件后,物理内存会很快被用光,当程序结束后,内存不会被正常释放,而是一直作为caching.这个问题,貌似有不少人在问,不过都 ...

随机推荐

  1. Python:IPC-Pipe与IPC-Manger

    1,IPC-PIPE: 管道 pipe from multiprocessing import Process from multiprocessing import Pipe p1,p2 = Pip ...

  2. python:部分内置函数与匿名函数

    一.内置函数 1,数据类型:int,bool .......... 2,数据结构:dict,list,tuple,set,str 3,reversed--保留原列表,返回一个反序的迭代器 revers ...

  3. BZOJ4001:[TJOI2015]概率论(卡特兰数,概率期望)

    Description Input 输入一个正整数N,代表有根树的结点数 Output 输出这棵树期望的叶子节点数.要求误差小于1e-9 Sample Input 1 Sample Output 1. ...

  4. 课堂笔记:HTML----------图片热点

    HTML----------图片热点: 规划出图片上的一个区域,可以做出超链接,直接点击图片区域就可完成跳转的效果. 代码: <!DOCTYPE html PUBLIC "-//W3C ...

  5. POJ 2195 Going Home 【二分图最小权值匹配】

    传送门:http://poj.org/problem?id=2195 Going Home Time Limit: 1000MS   Memory Limit: 65536K Total Submis ...

  6. vue开发工具node.js及构建工具webpack

    1.概念 node.js:可以运行JavaScript的服务平台,可以把它当做一个后端程序,只是它的开发语言是JavaScript (通常情况下,JavaScript的运行环境都是浏览器,因此Java ...

  7. html基础用法(下)

    设计表格: <html> <head> <title>表格</title> <meta charset="utf-8" /&g ...

  8. Windows远程桌面连接命令mstsc

    常用的:1. mstsc /v: 192.168.0.1 连接数满了之后使用的:2. mstsc /v: 192.168.0.1 /console -admin Mstsc 命令参考Updated: ...

  9. GNS3的安装和配置

    一.为什么安装GNS3 简单说来它是dynamips的一个图形前端,相比直接使用dynamips这样的虚拟软件要更容易上手和更具有可操作性.更重要的一点是很多Cisco实验在cisco packet ...

  10. spring入门(八) spring mvc设置默认首页

    1.web.xml配置如下 <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3// ...