vmstat

vmstat

vmstat - Report virtual memory statistics

[root@node85 ~]# vmstat procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu----- r b swpd free buff cache si so bi bo in cs us sy id wa st 0 0 0 692804 32424 173028 0 0 8 3 29 16 1 0 98 0 0 1)procs: r:代表正在运行的进程数。最大值小于等于cpu核数为宜。r: The number of processes waiting for run time. b:代表处在不可屏蔽中断的进程数.等待的进程数,即阻塞的进程。最大值小于等于cpu核数为宜。The number of processes in uninterruptible sleep. 2)memory: swpd:    已使用swap的空间大小. 看swap的si和so,为0的话不用担心。swpd: the amount of virtual memory used. free:    空闲的内存. free: the amount of idle memory.(不包括buffer和cache) buff:    内存中buffer的大小.用于缓冲buff: the amount of memory used as buffers. cache:    内存中cache的大小. 用于缓存pagecache,访问频繁的文件cache: the amount of memory used as cache. inact:    the amount of inactive memory. (-a option) active:   the amount of active memory. (-a option) 3)swap si: 这个值是一个比率,即每秒读了多少KB.(内存不够,临时调入交换分区) Amount of memory swapped in from disk (/s). so: 置换到swap的内存,.这个值是一个比率,即每秒写了多少KB。Amount of memory swapped to disk (/s). 4)io bi: Blocks received from a block device (blocks/s). bo: Blocks sent to a block device (blocks/s). 5)system 内核消耗cpu in: 每秒中断的次数. in: The number of interrupts per second, including the clock. cs: 每秒转换上下文的次数. cs: The number of context switches per second. 每秒上下文切换次数,例如我们调用系统函数,就要进行上下文切换,线程的切换,也要进程上下文切换,这个值要越小越好,太大了,要考虑调低线程或者进程的数目
例如在apache和nginx这种web服务器中,我们一般做性能测试时会进行几千并发甚至几万并发的测试,选择web服务器的进程可以由进程或者线程的峰值一直下调,压测
直到cs到一个比较小的值这个进程和线程数就是比较合适的值了。
系统调用也是,每次调用系统函数,我们的代码就会进入内核空间,导致上下文切换,这个是很耗资源,也要尽量避免频繁调用系统函数。
上下文切换次数过多表示你的CPU大部分浪费在上下文切换,导致CPU干正经事的时间少了,CPU没有充分利用,是不可取的。

6)cpu us+sy长期大于80%,说明不足These are percentages of total CPU time. us: 用户态进程使用CPU的百分比. cpu资源利用程度us: Time spent running non-kernel code. (user time, including nice time) sy: 内核态进程使用CPU的百分比. sy: Time spent running kernel code. (system time) id: 处于空闲的CPU百分比. id: Time spent idle. Prior to Linux 2.5.41, this includes IO-wait time. wa:系统等待IO的CPU时间百分比. 超过20%,有磁盘io瓶颈。wa: Time spent waiting for IO. Prior to Linux 2.5.41, included in idle. st:来自于一个虚拟机偷取的CPU时间的百分比. st: Time stolen from a virtual machine. Prior to Linux 2.6.11, unknown.

 

vmstat也可以

-d prints disk statistics
-D prints disk table
-p prints disk partition statistics

[root@node85 ~]# vmstat -D
           26 disks 
            3 partitions 
         9488 total reads
         3530 merged reads
       351472 read sectors
        59175 milli reading
         3257 writes
        11638 merged writes
       119154 written sectors
        25696 milli writing
            0 inprogress IO
           54 milli spent IO
[root@node85 ~]# vmstat -p /dev/sda2
sda2          reads   read sectors  writes    requested writes
                8352     342178       3254     119136

 

posted @ 2017-05-01 02:21  黑色月牙  阅读(220)  评论(0编辑  收藏  举报