系统管理必须知道怎样去评判当前系统的性能,性能涉及cpu、内存、存储、网络等,使用工具统计分析并从中总结一些相关调节优化经验

工具程序的安装
+-------iostat vmstat iftop dstat --------+
yum -y install sysstat procps  iftop dstat

 ----------------------iostat-------------------------

作用:iostat是I/O statistics(输入/输出统计)的缩写,iostat工具将对系统的磁盘操作活动进行监视。它的特点是汇报磁盘活动统计情况,同时也会汇报出CPU使用情况。

用法:iostat [ -c | -d ] [ -k ] [ -t ] [ -V ] [ -x [ device ] ] [ interval [ count ] ]
主要选项如下
-c:显示CPU的使用情况。
-d:显示磁盘的使用情况。
-k:表示按千字节每秒显示数据。
-t:打印汇报的时间。
-v:表示打印出版本信息和用法。
-x device:指定要统计的设备名称,默认为所有的设备。
interval:指每次统计间隔的时间,count指按照这个时间间隔统计的次数。

示例及说明

 iostat -k -x /dev/sda 1 3

 

%iowait
    Show the percentage of time that the CPU or CPUs were idle during which the system had an outstanding disk I/O request.
%idle
    Show the percentage of time that the CPU or CPUs were idle and the system did not have an outstanding disk I/O request.
avgrq-sz
    The average size (in sectors) of the requests that were issued to the device.
avgqu-sz
    The average queue length of the requests that were issued to the device.
await
    The  average time (in milliseconds) for I/O requests issued to the device to be served. This includes the time spent by  the requests in queue and the time spent servicing them...(形象点比喻为:某超市收款台5分钟内有3哥人需要结账,每个人的等待时间(0ms、1ms,3ms),对应的结账花费(1ms、2ms、1ms),该值为[(0+1+3)+(1+2+1)]/3 -> 2.6)
svctm
    The average service time (in milliseconds) for I/O requests that were issued to the device..(形象点比喻为:某超市收款台5分钟内有3个人需要结账,该值为收银员在每个人身上结账花(1ms、2ms、1ms)的平均时间,(1+2+1)/3 -> 1.3ms,收银员的速度)
%util
    Percentage of CPU time during which I/O requests were issued to the device  (bandwidth  utilization  for  the  device).Device saturation occurs when this value is close to 100%
.(形象点比喻为:某超市收款台5分钟内有3分钟时间在排队,3/5 -> 60%,上图中的最后一次统计值为0.8%)

----------vmstat  --------
参考文章:
http://linux.ccidnet.com/art/9513/20070730/1160333_1.html
http://hi.baidu.com/loveastyy/blog/item/29bdb2fa117f1e2b4f4aeade.html

----------iftop--------------
参考文章:
http://gaoxingf.blog.51cto.com/612518/188966

---------dstat---------------

---------说一下iops---------------------------
参考文章:
http://baike.baidu.com/view/2302083.htm?fr=ala0_1

重点摘录:

1.吞吐量
不同的硬盘所能支撑的流量大小

10 K rpm15 K rpmATA
10MB/s13MB/s8MB/s

4块“10K rpm”磁盘最大可支撑的流量=10*13MB/s=130M/s;一块千兆网卡的实际速率=1024Mb/s / 8=128MB/s

2.IOPS
决定IOPS的主要取决与阵列的算法,cache命中率,以及磁盘个数。阵列的算法因为不同的阵列不同而不同

每个物理硬盘能处理的IOPS是有限制的

10 K rpm15 K rpmATA
10015050

4块“15 K rpm”硬盘,它能支撑的最大IOPS为150*4=600;在raid5与raid10上,读iops没有差别,但是相同的业务,写iops最终落在每块磁盘上是有差别的,如果达到了每块磁盘的写的i0ps限制,性能会受到影响。

举例,iops算法,假定有业务的iops为10000,读cache命中率为30%,读iops为60%,写iops为40%,磁盘个数为120,那么分别计算在raid5与raid10的情况下,每块磁盘的iops为多少

raid5

单块盘的iops = (10000*(1-0.3)*0.6 + 2 * (10000*0.4)*(1-0.3) + 2 * (10000*0.4))/120
 
  = (4200 + 5600 + 8000)/120
 
  = 148
 
计算出来单个盘的iops为148个,基本达到磁盘极限

这里的10000*(1-0.3)*0.6表示是读的iops,4 * (10000*0.4) 表示写的iops,因为每一个写,在raid5中,实际发生了4个io,raid5在写操作的时候,那2个读操作也可能发生命中

raid10

单块盘的iops = (10000*(1-0.3)*0.6 + 2 * (10000*0.4))/120
 
  = (4200 + 8000)/120
 

  = 102

可以看到,因为raid10对于一个写操作,只发生2次io,所以,同样的压力,同样的磁盘,每个盘的iops只有102个,还远远低于磁盘的极限iops。

从上述描述中你会有什么启示呢?我的启示如下(如有不同意见,请指正)

1.如果我想充分利用一块千兆网卡,那么我的系统必须用4块磁盘做个raid0

2.假设我实际的业务(case)的IOPS为10000(这个值是怎么来的呢,呵呵,业务运作后可通过相关监控统计来大概计算或者凭经验),那么我需要多少块硬盘呢?上面有计算公式

3.根据业务来选择相应的阵列类型,当我单块磁盘的IOPS达到极限时,就需要增加硬盘了。