冰风雪雨 發表於 2017-3-10 17:16:19

CentOS服务程序性能评估文档详解

<p><strong><font color="#ff0000">1概述</font></strong></p>
<p><strong>1.1影响Linux服务程序性能的因素</strong> </p>
<p>CPU、内存、磁盘I/O带宽、网络I/O带宽</p>
<p><strong>1.2性能评判</strong> </p>
<p>CPU:user% + sys%&lt; 70%; 程序在用户态和内核态的执行时间百分比。</p>
<p>内存:Swap In(si)=0; Swap Out(so)=0; 以不使用交换分区为准,如果频繁用到交换分区,内存可能不够了。</p>
<p>硬盘:iowait % &lt; 20%;</p>
<p>网络:只要有足够带宽尽情的使用吧,达到网卡带宽linux系统表示毫无压力</p>
<p>其中: &nbsp;%user:表示CPU处在用户模式下的时间百分比。</p>
<p>&nbsp; &nbsp; &nbsp; %sys:表示CPU处在内核模式下的时间百分比。</p>
<p>&nbsp; &nbsp; &nbsp; %iowait:表示CPU等待输入输出完成时间的百分比。</p>
<p>&nbsp; &nbsp; &nbsp; swap in:即si,表示虚拟内存的页导入,即从SWAP DISK交换到RAM</p>
<p>&nbsp; &nbsp; &nbsp; swap out:即so,表示虚拟内存的页导出,即从RAM交换到SWAP DISK。</p>
<p><strong>1.3性能分析工具</strong> </p>
<p>常用系统命令:top、free、ps、uptime、iotop、vmstat、iostat 、dstat、sar。<br />使用方法:top命令把握全局,使用特定命令深入分析</p>
<p>常用组合方式:</p>
<p>(1)CPU瓶颈:top、vmstat、iostat、sar &ndash;u、sar -q</p>
<p>(2)内存瓶颈:free、vmstat、sar -B、sar &ndash;r、sar -W</p>
<p>(3)磁盘I/O瓶颈:iotop、iostat、sar -b、sar &ndash;u、sar -d</p>
<p>(4)网络瓶颈: dstat</p>
<p><strong><font color="#ff0000">2 top</font></strong></p>
<p><strong>2.1功能</strong> </p>
<p>提供了实时的对系统处理器、内存、任务等状态监视;该命令可以按CPU使用、内存使用对任务进行排序;TOP是一个动态显示过程,可以通过用户按键来不断刷新当前状态,也可以在启动时指定刷新间隔。</p>
<p><strong>2.2命令输出示意图</strong> </p>
<p>top - 10:16:29 up 38 days, 15:48, &nbsp;5 users, &nbsp;load average: 0.04, 0.10, 0.05</p>
<p>Tasks: 569 total, &nbsp; 2 running, 562 sleeping, &nbsp; 0 stopped, &nbsp; 5 zombie</p>
<p>Cpu(s): &nbsp;2.6%us, &nbsp;1.3%sy, &nbsp;0.4%ni, 95.7%id, &nbsp;0.0%wa, &nbsp;0.0%hi, &nbsp;0.0%si, &nbsp;0.0%st</p>
<p>Mem: &nbsp; 3839112k total, &nbsp;3151560k used, &nbsp; 687552k free, &nbsp; 302944k buffers</p>
<p>Swap: &nbsp;6078456k total, &nbsp; 631852k used, &nbsp;5446604k free, &nbsp; 348548k cached</p>
<p>&nbsp;PID USER &nbsp; &nbsp; &nbsp;PR &nbsp;NI &nbsp;VIRT &nbsp;RES &nbsp;SHR S %CPU %MEM &nbsp; &nbsp;TIME+ &nbsp;COMMAND &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</p>
<p>10603 zhixiang &nbsp;20 &nbsp; 0 1225m 284m &nbsp;30m S &nbsp;4.6 &nbsp;7.6 271:48.24 vs_exe &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</p>
<p>2473 xulun &nbsp; &nbsp; 20 &nbsp; 0 &nbsp;118m &nbsp;43m 6932 S &nbsp;3.0 &nbsp;1.2 964:14.99 Xvnc &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </p>
<p>1412 xulun &nbsp; &nbsp; 30 &nbsp;10 &nbsp;232m &nbsp;12m 5216 S &nbsp;2.3 &nbsp;0.3 &nbsp; 0:04.59 floaters &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</p>
<p>14823 chujie &nbsp; &nbsp;20 &nbsp; 0 1112m 247m &nbsp;17m S &nbsp;2.0 &nbsp;6.6 363:51.38 vs_exe &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </p>
<p>17772 sihao &nbsp; &nbsp; 20 &nbsp; 0 1101m 202m &nbsp;10m S &nbsp;1.7 &nbsp;5.4 631:21.17 vs_exe &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</p>
<p>11054 sihao &nbsp; &nbsp; 20 &nbsp; 0 &nbsp;906m &nbsp;65m 9412 S &nbsp;1.0 &nbsp;1.7 410:06.55 vs_exe &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</p>
<p>20782 yongtao &nbsp; 20 &nbsp; 0 1049m 173m 9996 S &nbsp;1.0 &nbsp;4.6 196:05.10 vs_exe &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</p>
<p>14637 chujie &nbsp; &nbsp;20 &nbsp; 0 1274m 132m 2388 S &nbsp;0.7 &nbsp;3.5 &nbsp;63:20.18 KugooPopMsgServ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </p>
<p>1439 yanyun &nbsp; &nbsp;20 &nbsp; 0 15428 1600 &nbsp;940 R &nbsp;0.3 &nbsp;0.0 &nbsp; 0:00.01 top &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </p>
<p>3491 zhixiang &nbsp;20 &nbsp; 0 &nbsp;129m &nbsp;55m &nbsp;17m S &nbsp;0.3 &nbsp;1.5 &nbsp;10:57.25 Xvnc &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</p>
<p>&nbsp; &nbsp;1 root &nbsp; &nbsp; &nbsp;20 &nbsp; 0 19344 1200 &nbsp;984 S &nbsp;0.0 &nbsp;0.0 &nbsp; 0:00.89 init &nbsp; &nbsp; </p>
<p><strong>2.3命令输出解析</strong> </p>
<p>Top输出的信息很多基本囊括了所有的性能指标,前五行是统计信息区,表示的是系统整体的统计信息,包括:系统负载、任务、CPU、内存等;后面的是每个进程相关信息。</p>
<p>第一行是任务队列信息,同uptime命令的执行结果是一样的</p>
<p>$ uptime</p>
<p>10:20:17 up 38 days, 15:52, &nbsp;5 users, &nbsp;load average: 0.00, 0.04, 0.03</p>
<p>其内容如下:10:20:17:当前时间</p>
<p>38 days, 15:52:系统运行时间</p>
<p>5 users:当前登录用户数</p>
<p>load average: 0.00, 0.04, 0.03:系统负载,即任务队列的平均长度。三个数值分别为 &nbsp;1分钟、5分钟、15分钟前到现在的平均值。</p>
<p>第二行为进程的信息</p>
<p>内容如下:569 total:进程总数</p>
<p>2 running,:正在运行的进程数</p>
<p>562 sleeping:睡眠的进程数</p>
<p>0 stopped:停止的进程数</p>
<p>5 zombie:僵尸进程数</p>
<p>第三行为CPU的信息</p>
<p>内容如下:2.6%us:用户空间占用CPU百分比</p>
<p>1.3%sy:内核空间占用CPU百分比</p>
<p>0.4%ni:用户进程空间内改变过优先级的进程占用CPU百分比</p>
<p>95.7%id:空闲CPU百分比</p>
<p>0.0%wa:等待输入输出的CPU时间百分比</p>
<p>第四、五行为内存信息;命令输出跟free相同</p>
<p>$ free</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; total &nbsp; &nbsp; &nbsp; used &nbsp; &nbsp; &nbsp; free &nbsp; &nbsp; shared &nbsp; &nbsp;buffers &nbsp; &nbsp; cached</p>
<p>Mem: &nbsp; &nbsp; &nbsp; 3839112 &nbsp; &nbsp;3256976 &nbsp; &nbsp; 582136 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0 &nbsp; &nbsp; 143664 &nbsp; &nbsp; 444992</p>
<p>-/+ buffers/cache: &nbsp; &nbsp;2668320 &nbsp; &nbsp;1170792</p>
<p>Swap: &nbsp; &nbsp; &nbsp;6078456 &nbsp; &nbsp; 574772 &nbsp; &nbsp;5503684</p>
<p>内容如下:Mem :3839112k total:物理内存总量</p>
<p>3151560k used:使用的物理内存总量</p>
<p>687552k free:空闲内存总量</p>
<p>302944k buffers:用作缓冲的内存量</p>
<p>Swap: 6078456k total:交换区总量</p>
<p>631852k used:使用的交换区总量</p>
<p>5446604k free:空闲交换区总量</p>
<p>348548k cached:缓存总量。</p>
<p>注:buffer:可以认为是写出磁盘的缓冲区;</p>
<p>Cache:读出磁盘的缓存。</p>
<p>Linux系统使用内存的原则是:不用白不用,用了也白用;尽可能的缓存东西,所以往往看空闲内存很小,但是cache很大;Linux系统会定时启动内核线程kswapd进行缓存回收。</p>
<p>后面的是显示每个进程相关信息</p>
<p>%CPU:上次更新到现在的CPU时间占用百分比</p>
<p>TIME+:进程使用的CPU时间总计</p>
<p>%MEM:进程使用的物理内存百分比</p>
<p>VIRT:进程使用的虚拟内存总量,单位kb</p>
<p>RES:进程使用的、未被换出的物理内存大小,单位kb。RES=CODE+DATA</p>
<p>SHR:共享内存大小,单位kb</p>
<p>S:进程状态。(D=不可中断的睡眠状态 &nbsp; &nbsp; &nbsp; R=运行 &nbsp;S=睡眠 &nbsp;T=跟踪/停止 &nbsp;Z=僵尸进程)</p>
<p><strong>2.4常用选项</strong> </p>
<p>top [-] </p>
<p>参数说明:</p>
<p>d:指定每两次屏幕信息刷新之间的时间间隔。(top &ndash;d 1:每秒刷新一次)</p>
<p>p:指定进程ID来仅监控某个进程。(top &ndash;d 1234:只查看pid为1234的进程信息)</p>
<p>k:终止一个进程。Top运行时参数,系统将提示用户输入需要终止的进程PID,以及需要发送给该进程什么样的信号。使用信号9强制结束该进程。</p>
<p>M:根据驻留内存大小进行排序。</p>
<p>P:根据CPU使用百分比大小进行排序。</p>
<p>注:在命令行执行过程中按下数字键&lsquo;1&rsquo;,可以查看到CPU每个核的相关信息。</p>
<p>Tasks: 564 total, &nbsp; 3 running, 556 sleeping, &nbsp; 0 stopped, &nbsp; 5 zombie</p>
<p>Cpu0 &nbsp;: &nbsp;2.9%us, &nbsp;2.9%sy, &nbsp;0.0%ni, 94.2%id, &nbsp;0.0%wa, &nbsp;0.0%hi, &nbsp;0.0%si, &nbsp;0.0%st</p>
<p>Cpu1 &nbsp;: &nbsp;2.0%us, &nbsp;2.0%sy, &nbsp;0.0%ni, 96.1%id, &nbsp;0.0%wa, &nbsp;0.0%hi, &nbsp;0.0%si, &nbsp;0.0%st</p>
<p>Cpu2 &nbsp;: &nbsp;0.0%us, &nbsp;0.0%sy, &nbsp;0.0%ni,100.0%id, &nbsp;0.0%wa, &nbsp;0.0%hi, &nbsp;0.0%si, &nbsp;0.0%st</p>
<p>Cpu3 &nbsp;: &nbsp;0.0%us, &nbsp;0.0%sy, &nbsp;0.0%ni,100.0%id, &nbsp;0.0%wa, &nbsp;0.0%hi, &nbsp;0.0%si, &nbsp;0.0%st</p>
<p>Mem: &nbsp; 3839112k total, &nbsp;3445296k used, &nbsp; 393816k free, &nbsp; &nbsp;48180k buffers</p>
<p>Swap: &nbsp;6078456k total, &nbsp; 553876k used, &nbsp;5524580k free, &nbsp; 976128k cached</p>
<p>&nbsp;PID USER &nbsp; &nbsp; &nbsp;PR &nbsp;NI &nbsp;VIRT &nbsp;RES &nbsp;SHR S %CPU %MEM &nbsp; &nbsp;TIME+ &nbsp;COMMAND &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </p>
<p>14823 chujie &nbsp; &nbsp;20 &nbsp; 0 1112m 245m &nbsp;16m R &nbsp;3.0 &nbsp;6.5 373:07.82 vs_exe &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</p>
<p>5589 sihao &nbsp; &nbsp; 20 &nbsp; 0 1019m 267m &nbsp;29m R &nbsp;2.0 &nbsp;7.1 &nbsp; 2:24.80 vs_exe &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</p>
<p>5674 zhixiang &nbsp;20 &nbsp; 0 1103m 253m &nbsp;37m S &nbsp;2.0 &nbsp;6.8 &nbsp; 4:17.89 vs_exe</p>
<p><strong><font color="#ff0000">3 iotop:</font></strong></p>
<p><strong>3.1功能</strong> </p>
<p>是一个用来监视每个线程的磁盘 I/O 使用状况的类top 工具,</p>
<p>注:此命令需要自行安装(yum install iotop)</p>
<p><strong>3.2命令输出示意图</strong> </p>
<p>Total DISK READ: 50.23 M/s | Total DISK WRITE: 34.25 K/s</p>
<p>&nbsp;TID &nbsp;PRIO &nbsp;USER &nbsp; &nbsp; DISK READ &nbsp;DISK WRITE &nbsp;SWAPIN &nbsp; &nbsp; IO&gt; &nbsp; &nbsp;COMMAND &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </p>
<p>61524 be/4 root &nbsp; &nbsp; &nbsp; 47.65 M/s &nbsp; &nbsp;0.00 B/s &nbsp;0.00 % 37.83 % ./relay_server</p>
<p>61539 be/4 root &nbsp; &nbsp; &nbsp;121.77 K/s &nbsp; &nbsp;0.00 B/s &nbsp;0.00 % 26.73 % ./relay_server</p>
<p>61544 be/4 root &nbsp; &nbsp; &nbsp;700.15 K/s &nbsp; &nbsp;0.00 B/s &nbsp;0.00 % 24.89 % ./relay_server</p>
<p>61543 be/4 root &nbsp; &nbsp; &nbsp;528.92 K/s &nbsp; &nbsp;0.00 B/s &nbsp;0.00 % 21.29 % ./relay_server</p>
<p>61541 be/4 root &nbsp; &nbsp; &nbsp;494.67 K/s &nbsp; &nbsp;0.00 B/s &nbsp;0.00 % 21.22 % ./relay_server</p>
<p>61540 be/4 root &nbsp; &nbsp; &nbsp;323.44 K/s &nbsp; &nbsp;0.00 B/s &nbsp;0.00 % &nbsp;8.62 % ./relay_server</p>
<p>61542 be/4 root &nbsp; &nbsp; &nbsp;468.04 K/s &nbsp; &nbsp;0.00 B/s &nbsp;0.00 % &nbsp;8.13 % ./relay_server</p>
<p>&nbsp;480 be/3 root &nbsp; &nbsp; &nbsp; &nbsp;0.00 B/s &nbsp; &nbsp;0.00 B/s &nbsp;0.00 % &nbsp;0.02 % </p>
<p>&nbsp; &nbsp;1 be/4 root &nbsp; &nbsp; &nbsp; &nbsp;0.00 B/s &nbsp; &nbsp;0.00 B/s &nbsp;0.00 % &nbsp;0.00 % init</p>
<p>&nbsp; &nbsp;2 be/4 root &nbsp; &nbsp; &nbsp; &nbsp;0.00 B/s &nbsp; &nbsp;0.00 B/s &nbsp;0.00 % &nbsp;0.00 % </p>
<p>3 rt/4 root &nbsp; &nbsp; &nbsp; &nbsp;0.00 B/s &nbsp; &nbsp;0.00 B/s &nbsp;0.00 % &nbsp;0.00 % </p>
<p><strong>3.3命令输出解析</strong> </p>
<p>第一行:</p>
<p>Total DISK READ: 50.23 M/s :磁盘每秒读出数据量</p>
<p>Total DISK WRITE: 34.25 K/s :磁盘每秒写入数据量</p>
<p>下面的是每个线程的的IO情况:</p>
<p>比较简单;只解释一下IO:跟top的wa意义相同,只是此处表示的一个线程的wa。</p>
<p><strong>3.4常用选项</strong> </p>
<p>iotop [-] </p>
<p>参数说明:</p>
<p>d:指定每两次屏幕信息刷新之间的时间间隔。(iotop &ndash;d 1:每秒刷新一次)</p>
<p>p:指定线程ID来仅监控某个线程。(iotop &ndash;d 1234:只查看pid为1234的进程信息)</p>
<p>注:在命令行执行过程中按下字母&lsquo;o&rsquo;,可以只查看有IO的线程。</p>
<p>pstree -p:查看进程树,可以输出进程之间的关系。</p>
<p>ps &ndash;eLf:查看线程。ps &ndash;ef的高级版</p>
<p><strong><font color="#ff0000">4 vmstat:</font></strong></p>
<p><strong>4.1功能</strong> </p>
<p>查看虚拟内存(Virtual Memory)使用状况的工具</p>
<p><strong>4.2命令输出示意图</strong> </p>
<p>$ vmstat</p>
<p>procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu-----</p>
<p>r &nbsp;b &nbsp; swpd &nbsp; free &nbsp; buff &nbsp;cache &nbsp; si &nbsp; so &nbsp; &nbsp;bi &nbsp; &nbsp;bo &nbsp; in &nbsp; cs us sy id wa st</p>
<p>0 &nbsp;0 631376 834896 &nbsp;15108 452024 &nbsp; &nbsp;0 &nbsp; &nbsp;0 &nbsp; &nbsp; 4 &nbsp; &nbsp; 4 &nbsp; &nbsp;1 &nbsp; &nbsp;2 &nbsp;2 &nbsp;1 97 &nbsp;0 &nbsp;0</p>
<p><strong>4.3命令输出解析</strong> </p>
<p>Memory:同top的第四、五行信息。</p>
<p>swap:内存到swap分区换入换出速率。</p>
<p>io:读写磁盘速率</p>
<p>system in:每秒的中断数,包括时钟中断</p>
<p>system cs:每秒的环境(上下文)切换数;频繁切换对系统性能有影响,linux提供了线程对cpu的亲和,可以将某个线程绑定到一个核运行。</p>
<p>cpu:同top输出的第三行</p>
<p>注:swap项不为零,都用到交换分区了,内存可能已经用完已经成为系统瓶颈的一项。</p>
<p><strong>4.4常用选项</strong> </p>
<p>vmstat 1 10:每秒刷新一次,总共刷新十次退出。</p>
<p>注:下面的选项都是专业的查看某一特定项的信息,有几个输出一大堆信息,用到时google吧!</p>
<p>-a:显示活跃和非活跃内存</p>
<p>-f:显示从系统启动至今的fork数量</p>
<p>-m:显示slabinfo</p>
<p>-s:显示内存相关统计信息及多种系统活动数量。</p>
<p>-d:显示磁盘相关统计信息。</p>
<p>-p:显示指定磁盘分区统计信息</p>
<p><strong><font color="#ff0000">5 iostat</font></strong></p>
<p><strong>5.1功能</strong> </p>
<p>用于输出CPU和磁盘I/O相关的统计信息</p>
<p><strong>5.2输出结果示意图</strong> </p>
<p># iostat -x</p>
<p>Linux 2.6.32-279.el6.x86_64 (ShanWei_119_134_255_208) &nbsp; 07/30/2013 &nbsp; &nbsp; &nbsp;_x86_64_ &nbsp; &nbsp; &nbsp; &nbsp;(16 CPU)</p>
<p>avg-cpu: &nbsp;%user &nbsp; %nice %system %iowait &nbsp;%steal &nbsp; %idle</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 2.63 &nbsp; &nbsp;0.00 &nbsp; &nbsp;2.25 &nbsp; &nbsp;5.98 &nbsp; &nbsp;0.00 &nbsp; 89.14</p>
<p>Device: &nbsp; &nbsp; &nbsp; &nbsp; rrqm/s &nbsp; wrqm/s &nbsp; &nbsp; r/s &nbsp; &nbsp; w/s &nbsp; rsec/s &nbsp; wsec/s avgrq-sz avgqu-sz &nbsp; await &nbsp;svctm &nbsp;%util</p>
<p>sda &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 195.42 &nbsp; 163.72 &nbsp;194.33 &nbsp;126.28 28464.35 &nbsp;2319.94 &nbsp; &nbsp;96.02 &nbsp; &nbsp; 1.16 &nbsp; &nbsp;3.63 &nbsp; 1.41 &nbsp;45.30</p>
<p>sdb &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 0.33 &nbsp; &nbsp;48.97 &nbsp;122.71 &nbsp; &nbsp;2.70 29603.37 &nbsp; 413.38 &nbsp; 239.34 &nbsp; &nbsp; 0.27 &nbsp; &nbsp;2.15 &nbsp; 1.00 &nbsp;12.52</p>
<p><strong>5.3命令输出解释</strong> </p>
<p>avg-cpu段:</p>
<p>%user: 在用户级别运行所使用的CPU的百分比.</p>
<p>%nice: nice操作所使用的CPU的百分比.</p>
<p>%sys: 在系统级别(kernel)运行所使用CPU的百分比.</p>
<p>%iowait: CPU等待硬件I/O时,所占用CPU百分比.</p>
<p>%idle: CPU空闲时间的百分比.</p>
<p>Device段:</p>
<p>tps: 每秒钟发送到的I/O请求数</p>
<p>Blk_read /s: 每秒读取的block数</p>
<p>Blk_wrtn/s: 每秒写入的block数</p>
<p>Blk_read: &nbsp; 读入的block总数</p>
<p>Blk_wrtn: &nbsp;写入的block总数</p>
<p>-x选项可以查看到如下更多信息</p>
<p>rrqm/s:每秒这个设备相关的读取请求有多少被Merge了</p>
<p>wrqm/s:每秒这个设备相关的写入请求有多少被Merge了</p>
<p>rsec/s:每秒读取的扇区数</p>
<p>wsec/:每秒写入的扇区数</p>
<p>avgrq-sz: 平均每次设备I/O操作的数据大小 (扇区)</p>
<p>avgqu-sz: 平均I/O队列长度</p>
<p>await:平均每次设备I/O操作的等待时间(单位是毫秒)</p>
<p>svctm: 平均每次设备I/O操作的服务时间 (单位是毫秒)</p>
<p>%util:在统计时间内所有处理IO时间,所以该参数暗示了设备的繁忙程度</p>
<p><strong>5.4常用选项</strong> </p>
<p>iostat -d 2 6:每隔2秒,显示一次设备统计信息.总共输出6次.</p>
<p>-x:查看设备的使用率、响应时间</p>
<p><strong><font color="#ff0000">6 dstat</font></strong></p>
<p><strong>6.1功能</strong> </p>
<p>是一个全能系统信息统计工具,只能对整个系统进行监控而不能对某一个进程或某一个程序进行深入分析;监控项包括:cpu、磁盘、内存、网卡、进程、系统(彩色界面linux下面不多见啊!)</p>
<p>注:此命令需要自行安装(yum install dstat)</p>
<p><strong>6.2命令输出示意图</strong> </p>
<p># dstat -cdlmnpy</p>
<p>----total-cpu-usage---- -dsk/total- ---load-avg--- ------memory-usage----- -net/total- ---procs--- ---system--</p>
<p>usr sys idl wai hiq siq| read &nbsp;writ| 1m &nbsp; 5m &nbsp;15m | used &nbsp;buff &nbsp;cach &nbsp;free| recv &nbsp;send|run blk new| int &nbsp; csw</p>
<p>&nbsp;3 &nbsp; 2 &nbsp;89 &nbsp; 6 &nbsp; 0 &nbsp; 0| &nbsp;28M 1367k|5.41 5.07 4.87|4019M &nbsp;172M 58.5G &nbsp;267M| &nbsp; 0 &nbsp; &nbsp; 0 | &nbsp;0 0.0 1.3|8608 &nbsp; &nbsp;35k</p>
<p>&nbsp;2 &nbsp; 1 &nbsp;85 &nbsp;12 &nbsp; 0 &nbsp; 0| &nbsp;21M &nbsp;828k|5.41 5.07 4.87|4020M &nbsp;172M 58.6G &nbsp;243M| 191k &nbsp; 15M| &nbsp;0 6.0 &nbsp; 0|5711 &nbsp; &nbsp;18k</p>
<p>&nbsp;1 &nbsp; 1 &nbsp;80 &nbsp;18 &nbsp; 0 &nbsp; 0|5828k 4804k|5.41 5.07 4.87|4018M &nbsp;172M 58.6G &nbsp;260M| 190k &nbsp; 17M|2.0 3.0 &nbsp; 0|5802 &nbsp; &nbsp;12k</p>
<p><strong>6.3命令输出解释</strong> </p>
<p>前面基本都解释过了......</p>
<p><strong>6.4常用选项</strong> </p>
<p>dstat &ndash;cdlmnpsy:cdlmnpsy这几个选项基本囊括了常用的,当然还有很多dstat &ndash;-help一下吧。</p>
<p><strong><font color="#ff0000">7 sar</font></strong></p>
<p><strong>7.1功能</strong> </p>
<p>System Activity Reporter系统活动情况报告,是目前 Linux 上最为全面的系统性能分析工具之一,可以从多方面对系统的活动进行报告,包括:文件的读写情况、系统调用的使用情况、磁盘I/O、CPU效率、内存使用状况、进程活动及IPC有关的活动等。</p>
<p><strong>7.2命令输出示意图</strong> </p>
<p># sar -r 1 100</p>
<p>Linux 2.6.32-220.el6.x86_64 (localhost.localdomain) &nbsp; &nbsp; 07/30/2013 &nbsp; &nbsp; &nbsp;_x86_64_ &nbsp; &nbsp; &nbsp; &nbsp;(8 CPU)</p>
<p>03:17:59 PM kbmemfree kbmemused &nbsp;%memused kbbuffers &nbsp;kbcached &nbsp;kbcommit &nbsp; %commit</p>
<p>03:18:00 PM &nbsp; 4988488 &nbsp; 3062224 &nbsp; &nbsp; 38.04 &nbsp; &nbsp;639136 &nbsp; 2115404 &nbsp; &nbsp; 72404 &nbsp; &nbsp; &nbsp;0.44</p>
<p>03:18:01 PM &nbsp; 4984464 &nbsp; 3066248 &nbsp; &nbsp; 38.09 &nbsp; &nbsp;639136 &nbsp; 2115404 &nbsp; &nbsp; 98060 &nbsp; &nbsp; &nbsp;0.60</p>
<p>03:18:02 PM &nbsp; 4985152 &nbsp; 3065560 &nbsp; &nbsp; 38.08 &nbsp; &nbsp;639136 &nbsp; 2115420 &nbsp; &nbsp; 97972 &nbsp; &nbsp; &nbsp;0.60</p>
<p>03:18:03 PM &nbsp; 4985400 &nbsp; 3065312 &nbsp; &nbsp; 38.08 &nbsp; &nbsp;639136 &nbsp; 2115420 &nbsp; &nbsp; 97972 &nbsp; &nbsp; &nbsp;0.60</p>
<p># sar -B 1 100</p>
<p>Linux 2.6.32-220.el6.x86_64 (localhost.localdomain) &nbsp; &nbsp; 07/30/2013 &nbsp; &nbsp; &nbsp;_x86_64_ &nbsp; &nbsp; &nbsp; &nbsp;(8 CPU)</p>
<p>03:19:09 PM &nbsp;pgpgin/s pgpgout/s &nbsp; fault/s &nbsp;majflt/s &nbsp;pgfree/s pgscank/s pgscand/s pgsteal/s &nbsp; &nbsp;%vmeff</p>
<p>03:19:10 PM &nbsp; &nbsp; &nbsp;0.00 &nbsp; &nbsp;157.14 &nbsp;45415.48 &nbsp; &nbsp; &nbsp;0.00 &nbsp;15541.67 &nbsp; &nbsp; &nbsp;0.00 &nbsp; &nbsp; &nbsp;0.00 &nbsp; &nbsp; &nbsp;0.00 &nbsp; &nbsp; &nbsp;0.00</p>
<p>03:19:11 PM &nbsp; &nbsp; &nbsp;0.00 &nbsp; &nbsp; &nbsp;0.00 &nbsp; &nbsp; 40.40 &nbsp; &nbsp; &nbsp;0.00 &nbsp; &nbsp; 75.76 &nbsp; &nbsp; &nbsp;0.00 &nbsp; &nbsp; &nbsp;0.00 &nbsp; &nbsp; &nbsp;0.00 &nbsp; &nbsp; &nbsp;0.00</p>
<p>03:19:12 PM &nbsp; &nbsp; &nbsp;0.00 &nbsp; &nbsp; &nbsp;0.00 &nbsp; 5542.34 &nbsp; &nbsp; &nbsp;0.00 &nbsp; 1584.68 &nbsp; &nbsp; &nbsp;0.00 &nbsp; &nbsp; &nbsp;0.00 &nbsp; &nbsp; &nbsp;0.00 &nbsp; &nbsp; &nbsp;0.00</p>
<p># sar -b 1 100</p>
<p>Linux 2.6.32-220.el6.x86_64 (localhost.localdomain) &nbsp; &nbsp; 07/30/2013 &nbsp; &nbsp; &nbsp;_x86_64_ &nbsp; &nbsp; &nbsp; &nbsp;(8 CPU)</p>
<p>03:19:38 PM &nbsp; &nbsp; &nbsp; tps &nbsp; &nbsp; &nbsp;rtps &nbsp; &nbsp; &nbsp;wtps &nbsp; bread/s &nbsp; bwrtn/s</p>
<p>03:19:39 PM &nbsp; &nbsp; 12.50 &nbsp; &nbsp; &nbsp;0.00 &nbsp; &nbsp; 12.50 &nbsp; &nbsp; &nbsp;0.00 &nbsp; &nbsp;181.82</p>
<p>03:19:40 PM &nbsp; &nbsp; &nbsp;0.00 &nbsp; &nbsp; &nbsp;0.00 &nbsp; &nbsp; &nbsp;0.00 &nbsp; &nbsp; &nbsp;0.00 &nbsp; &nbsp; &nbsp;0.00</p>
<p>03:19:41 PM &nbsp; &nbsp; &nbsp;7.14 &nbsp; &nbsp; &nbsp;0.00 &nbsp; &nbsp; &nbsp;7.14 &nbsp; &nbsp; &nbsp;0.00 &nbsp; &nbsp;128.57</p>
<p># sar -W 1 100</p>
<p>Linux 2.6.32-220.el6.x86_64 (localhost.localdomain) &nbsp; &nbsp; 07/30/2013 &nbsp; &nbsp; &nbsp;_x86_64_ &nbsp; &nbsp; &nbsp; &nbsp;(8 CPU)</p>
<p>03:20:10 PM &nbsp;pswpin/s pswpout/s</p>
<p>03:20:11 PM &nbsp; &nbsp; &nbsp;0.00 &nbsp; &nbsp; &nbsp;0.00</p>
<p>03:20:12 PM &nbsp; &nbsp; &nbsp;0.00 &nbsp; &nbsp; &nbsp;0.00</p>
<p>03:20:13 PM &nbsp; &nbsp; &nbsp;0.00 &nbsp; &nbsp; &nbsp;0.00</p>
<p># sar -d 1 100</p>
<p>Linux 2.6.32-220.el6.x86_64 (localhost.localdomain) &nbsp; &nbsp; 07/30/2013 &nbsp; &nbsp; &nbsp;_x86_64_ &nbsp; &nbsp; &nbsp; &nbsp;(8 CPU)</p>
<p>03:20:48 PM &nbsp; &nbsp; &nbsp; DEV &nbsp; &nbsp; &nbsp; tps &nbsp;rd_sec/s &nbsp;wr_sec/s &nbsp;avgrq-sz &nbsp;avgqu-sz &nbsp; &nbsp; await &nbsp; &nbsp; svctm &nbsp; &nbsp; %util</p>
<p>03:20:49 PM &nbsp; &nbsp;dev8-0 &nbsp; &nbsp; &nbsp;7.69 &nbsp; &nbsp; &nbsp;0.00 &nbsp; &nbsp; 79.12 &nbsp; &nbsp; 10.29 &nbsp; &nbsp; &nbsp;0.00 &nbsp; &nbsp; &nbsp;0.14 &nbsp; &nbsp; &nbsp;0.14 &nbsp; &nbsp; &nbsp;0.11</p>
<p>03:20:49 PM &nbsp; dev8-16 &nbsp; &nbsp; &nbsp;0.00 &nbsp; &nbsp; &nbsp;0.00 &nbsp; &nbsp; &nbsp;0.00 &nbsp; &nbsp; &nbsp;0.00 &nbsp; &nbsp; &nbsp;0.00 &nbsp; &nbsp; &nbsp;0.00 &nbsp; &nbsp; &nbsp;0.00 &nbsp; &nbsp; &nbsp;0.00</p>
<p>03:20:49 PM &nbsp; &nbsp; &nbsp; DEV &nbsp; &nbsp; &nbsp; tps &nbsp;rd_sec/s &nbsp;wr_sec/s &nbsp;avgrq-sz &nbsp;avgqu-sz &nbsp; &nbsp; await &nbsp; &nbsp; svctm &nbsp; &nbsp; %util</p>
<p>03:20:50 PM &nbsp; &nbsp;dev8-0 &nbsp; &nbsp; 10.47 &nbsp; &nbsp; &nbsp;0.00 &nbsp; &nbsp;148.84 &nbsp; &nbsp; 14.22 &nbsp; &nbsp; &nbsp;0.08 &nbsp; &nbsp; &nbsp;7.22 &nbsp; &nbsp; &nbsp;7.11 &nbsp; &nbsp; &nbsp;7.44</p>
<p>03:20:50 PM &nbsp; dev8-16 &nbsp; &nbsp; &nbsp;0.00 &nbsp; &nbsp; &nbsp;0.00 &nbsp; &nbsp; &nbsp;0.00 &nbsp; &nbsp; &nbsp;0.00 &nbsp; &nbsp; &nbsp;0.00 &nbsp; &nbsp; &nbsp;0.00 &nbsp; &nbsp; &nbsp;0.00 &nbsp; &nbsp; &nbsp;0.00</p>
<p><strong>7.3命令输出解释</strong> </p>
<p>kbmemfree:这个值和free命令中的free值基本一致,所以它不包括buffer和cache的空间.</p>
<p>kbmemused:这个值和free命令中的used值基本一致,所以它包括buffer和cache的空间.</p>
<p>%memused:这个值是kbmemused和内存总量(不包括swap)的一个百分比.</p>
<p>kbbuffers和kbcached:这两个值就是free命令中的buffer和cache.</p>
<p>kbcommit:保证当前系统所需要的内存,即为了确保不溢出而需要的内存(RAM+swap).</p>
<p>%commit:这个值是kbcommit与内存总量(包括swap)的一个百分比.</p>
<p>pgpgin/s:表示每秒从磁盘或SWAP置换到内存的字节数(KB)</p>
<p>pgpgout/s:表示每秒从内存置换到磁盘或SWAP的字节数(KB)</p>
<p>fault/s:每秒钟系统产生的缺页数,即主缺页与次缺页之和(major + minor)</p>
<p>majflt/s:每秒钟产生的主缺页数.</p>
<p>pgfree/s:每秒被放入空闲队列中的页个数</p>
<p>pgscank/s:每秒被kswapd扫描的页个数</p>
<p>pgscand/s:每秒直接被扫描的页个数</p>
<p>pgsteal/s:每秒钟从cache中被清除来满足内存需要的页个数</p>
<p>%vmeff:每秒清除的页(pgsteal)占总扫描页(pgscank+pgscand)的百分比</p>
<p>tps:每秒钟物理设备的 I/O传输总量</p>
<p>rtps:每秒钟从物理设备读入的数据总量</p>
<p>wtps:每秒钟向物理设备写入的数据总量</p>
<p>bread/s:每秒钟从物理设备读入的数据量,单位为块/s</p>
<p>bwrtn/s:每秒钟向物理设备写入的数据量,单位为块/s</p>
<p>pswpin/s:每秒系统换入的交换页面(swap page)数量</p>
<p>pswpout/s:每秒系统换出的交换页面(swap page)数量</p>
<p><strong>7.4常用选项</strong> </p>
<p>sar &ndash;</p>
<p>参数说明:</p>
<p>-u:CPU资源监控</p>
<p>-r:内存和交换空间监控</p>
<p>-B:内存分页监控</p>
<p>-b:IO和传输速率监控</p>
<p>-q:进程队列系统负载监控</p>
<p>-W:系统交换分区活动监控</p>
<p>-d:设备使用状况监控</p>
<p><strong><font color="#ff0000">8 tmpfs</font></strong></p>
<p><strong>8.1定义</strong> </p>
<p>tmpfs文件系统是一种基于内存的文件系统,挂载在/dev/shm下面。</p>
<p><strong>8.2特点</strong> </p>
<p>动态改变大小;访问快、完全驻留在RAM中;当然系统重启就没了。</p>
<p><strong>8.3使用方法</strong> </p>
<p>1、 linux下面POSIX标准的共享内存是基于此文件系统实现的(还有一套System V标准的共享内存实现方式);</p>
<p>2、 将文件创建在/dev/shm下面都将直接使用tmpfs;所以如果不需要考虑机器重启后数据的丢失,把数据放在这下面吧,释放你的磁盘压力!</p>
<p>3、 tmpfs的默认大小是物理内存的一半。将最大容量调到40G,并且文件节点数量调到1000000,可以通过下面的命令:</p>
<p>mount -o size=40G -o nr_inodes=1000000 -o noatime,nodiratime -o remount /dev/shm</p>
<p>4、如果需要永久修改tmpfs文件系统的大小,需要修改/etc/fstab</p>
<p><strong><font color="#ff0000">9 crontab:</font></strong></p>
<p><strong>9.1功能</strong> </p>
<p>定时调度一些命令的执行,相当于系统级别的定时器。在/var/spool/cron/有一些以用户名命名的文件,表示的是这个用户的定时执行任务。</p>
<p><strong>9.2配置方法</strong> </p>
<p>格式说明:</p>
<p>&nbsp; * * * * * /command path</p>
<p>前五个字段可以取整数值,指定何时开始工作(分钟 小时 日期 月份 星期),第六个域是字符串,到期执行的脚本、程序等</p>
<p>43 21 * * * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 每天21:43 执行</p>
<p>0 17 * * 1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;每周一的 17:00 执行</p>
<p>0,10 17 * * 0,2,3 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 每周日,周二,周三的 17:00和 17:10 执行</p>
<p>0-10 17 1 * * &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 毎月1日从 17:00到7:10 毎隔1分钟 执行</p>
<p>0 0 1,15 * 1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;毎月1日和 15日和 一日的 0:00 执行</p>
<p>42 4 1 * *     &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 毎月1日的 4:42分 执行</p>
<p>0 21 * * 1-6   &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 周一到周六 21:00 执行</p>
<p>0,10,20,30,40,50 * * * *  &nbsp;每隔10分 执行</p>
<p>*/10 * * * *        &nbsp; &nbsp; 每隔10分 执行</p>
<p>* 1 * * *         &nbsp; &nbsp; 从1:0到1:59 每隔1分钟 执行</p>
<p>0 1 * * *         &nbsp; &nbsp; 1:00 执行</p>
<p>0 */1 * * *        &nbsp; &nbsp; 毎时0分 每隔1小时 执行</p>
<p>0 * * * *         &nbsp; &nbsp; 毎时0分 每隔1小时 执行</p>
<p>2 8-20/3 * * *       &nbsp; &nbsp;8:02,11:02,14:02,17:02,20:02 执行</p>
<p>30 5 1,15 * *       &nbsp; &nbsp; 1日 和 15日的 5:30 执行</p>
<p>如下配置表示:每天3:00执行这个脚本/opt/ clear_old_file.sh;</p>
<p>这个脚本功能是:删除/data1 /data2这两个目录下的五天之内没有访问过的文件</p>
<p>0 3 * * * (cd /opt/ &amp;&amp; ./clear_old_file.sh &gt; /dev/null &amp;)</p>
<p># cat /opt/clear_old_file.sh</p>
<p>#!/bin/sh</p>
<p>find /data1/* -type f -atime +5 -exec rm {} \;</p>
<p>find /data2/* -type f -atime +5 -exec rm {} \;</p>
<p>exit 0</p>
<p><strong><font color="#ff0000">10 proc:待续&hellip;</font></strong> </p>
<p>/proc 文件系统是 GNU/Linux 特有的。它是一个虚拟的文件系统,此文件系统完全驻留在RAM中,因此在该目录中的所有文件都不会消耗磁盘空间。通过它能够非常简便地了解系统中的内核信息、硬件信息等;还可以通过它进行系统内核的参数的配置。许多命令实际上只是从 /proc 的文件中收集信息,然后按照它们自己的格式组织后显示出来;像前面介绍的命令基本就是这么干的。</p>
頁: [1]
查看完整版本: CentOS服务程序性能评估文档详解