vmstat的分析

Linux系统性能分析工具vmstat

vmstat是一个相当全面的性能分析工具,可以观察到系统的进程状态、内存使用、虚拟内存使用、磁盘的IO、中断、上下问切换、CPU使用等性能信息。在系统性能分析工具中,还有功能强大的Sysstat工具包,free,top,ps等,本人使用最多的是这个。
     掌握Linux 的性能分析,理解vmstat 输出内容的各项含义,那么我认为系统性能分析的能力就基本具备了。

以Linux2.4内核版本,输出如下信息,例如Redhat9

引用   procs                       memory       swap           io     system       cpu
r   b   w   swpd   free   buff   cache   si   so     bi     bo   in     cs us sy id
0   0   0       0   21516 162240 253120     0     0     0     0 1364   544   2   1 97
0   0   0       0   21524 162236 253128     0     0     0     0 1774   720   1   2 97
0   0   0       0   21532 162236 253128     0     0     0     0 1718   713   0   2 98
0   0   0       0   21540 162204 253164     0     0     0   232 1904   867   1   2 97
0   0   0       0   21548 162204 253168     0     0     0     0 1668   810   1   1 98

而对Linux2.6内核版本,稍微有一点点不同,以RHEL4为例,输出以下信息


引用procs -----------memory---------- ---swap-- -----io---- --system-- ----cpu----
r   b   swpd   free   buff   cache   si   so     bi     bo   in     cs us sy id wa
0   0     208 508684   95980 770080     0     0     0     0 2252   1064 27   3 70   0
2   0     208 506956   95980 770080     0     0     0     32 2413   1081 11   2 88   0
2   0     208 494348   95980 770080     0     0     0     0 3198   1651 28   4 68   0
0   0     208 493708   95980 770080     0     0     0     0 2569   1072 21   3 77   0
1   0     208 508676   95992 770068     0     0     0   520 2943   1275 11   2 85   1
1   0     208 505988   95996 770324     0     0   160     0 3025   1422 13   3 83   0

相信现在大家都用linux2.6内核了,所以本文以linux2.6内核版本为例来加以说明。


vmstat的用法如下:
引用usage: vmstat [-V] [-n] [delay [count]]
               -V prints version.           
               -n causes the headers not to be reprinted regularly.
               -a print inactive/active page stats.
               -d prints disk statistics
               -D prints disk table
               -p prints disk partition statistics
               -s prints vm table
               -m prints slabinfo
               -S unit size
               delay is the delay between updates in seconds.
               unit size k:1000 K:1024 m:1000000 M:1048576 (default is K)
               count is the number of updates.-V表示打印出版本信息;
-n表示在周期性循环输出时,输出的头部信息仅显示一次;
delay是两次输出之间的延迟时间;如1表示每隔1s输出一次信息。
count是指按照这个时间间隔统计的次数。如4则表示输出总共统计4次,输出结束。
对于vmstat输出各字段的含义,可以man一下

引用Procs
       r: The number of processes waiting for run time.
       b: The number of processes in uninterruptible sleep.

   Memory
       swpd: the amount of virtual memory used.
       free: the amount of idle memory.
       buff: the amount of memory used as buffers.
       cache: the amount of memory used as cache.
       inact: the amount of inactive memory. (-a option)
       active: the amount of active memory. (-a option)

   Swap
       si: Amount of memory swapped in from disk (/s).
       so: Amount of memory swapped to disk (/s).

   IO
       bi: Blocks received from a block device (blocks/s).
       bo: Blocks sent to a block device (blocks/s).

   System
       in: The number of interrupts per second, including the clock.
       cs: The number of context switches per second.

   CPU
       These are percentages of total CPU time.
       us: Time spent running non-kernel code. (user time, including nice time)
       sy: Time spent running kernel code. (system time)
       id: Time spent idle. Prior to Linux 2.5.41, this includes IO-wait time.
       wa: Time spent waiting for IO. Prior to Linux 2.5.41, shown as zero.
英文对于某些同志理解有困难,用中文比较容易让人理解,下面逐个解释其含义


r 运行的和等待(CPU时间片)运行的进程数,这个值也可以判断是否需要增加CPU(长期大于1)

b 处于不可中断状态的进程数,常见的情况是由IO引起的
w 可以进入运行队列但被替换的进程

memoy
swap 现时可用的交换内存(k表示)
free 空闲的内存(k表示)

pages
re 回收的页面
mf 非严重错误的页面
pi 进入页面数(k表示)
po 出页面数(k表示)
fr 空余的页面数(k表示)
de 提前读入的页面中的未命中数
sr 通过时钟算法扫描的页面
disk 显示每秒的磁盘操作。
fault 显示每秒的中断数
in设备中断
sy系统中断
cycpu交换
cpu 表示cpu的使用状态
cs用户进程使用的时间
sy系统进程使用的时间
idcpu空闲的时间


案例分析
假设输出的信息中 

r经常大于 3-4 ,且id经常少于50,表cpu的负荷很重。
pi,po 长期不等于0,表示内存不足。
disk 经常不等于0, 且在 b中的队列大于2-3, 表示 io性能不好。
Procs r: 运行的进程比较多,系统很繁忙
Io bo: 磁盘写的数据量稍大
Cpu us: 持续大于50-60,服务高峰期可以接受
Cpu wa: 稍微有些高
Cpu id:持续小于50,服务高峰期可以接受

   有些参数具体怎么理解,还得依靠自己去掌握,我认为掌握一些常用的参数含义就行了
                                       --EOF--
 


中断和context switch都是内核的一种机制,这些数字过高表明内核把大量CPU时间都浪费在这些个机制上,至于为什么会这样,还是应该从你的应用特点下手,我个人认为这种现象应该是你程序的进程或线程数量过多导致。
所以如果是你的应用确实需要如此多的进程or线程并发运行的话,那说明你硬件不够满足你的应用了,如果这些进程or线程是滥用的话,说明你的应用设计有问题。

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值