amirwap 发表于 2007-11-12 16:17

I/O、内存、网络性能优化命令

I/O、内存、网络性能优化命令
Input Output statistics (iostat )
iostat反映了终端、磁盘I/O情况和CPU活动。输出结果的第一行是从系统启动到现在为止的这段时间的结果,接下去的每一行是interval时间段内的结果。Kernel里有一组计数器用来跟踪这些值。
iostat的默认参数是tdc(terminal,disk, and CPU)。如果任何其他的选项被指定,这个默认参数将被完全替代,例如,iostat -d将只反映磁盘的统计结果。
语法:
基本语法: iostat;   intervalcount
option - 让你指定所需信息的设备,像磁盘、cpu或者终端(-d , -c , -tor -tdc ) 。x 选项给出了完整的统计结果(gives the extended
statistic)。
interval -在两个samples之间的时间(秒)。
count- 就是需要统计几次
例子:
$ iostat -xtc 5 2
                        extended disk statistics       tty         cpu
   disk r/sw/s Kr/s Kw/s wait actv svc_t%w%btin tout us sy wt id
   sd0   2.6 3.0 20.7 22.7 0.10.259.2   6   19   0   84385 11 0
   sd1   4.2 1.0 33.58.0 0.00.247.2   2   23
   sd2   0.0 0.00.00.0 0.00.0   0.0   0    0
   sd310.2 1.6 51.4 12.8 0.10.331.2   3   31
   The fields have the following meanings:
      disk    name of the disk磁盘名
      r/s   reads per second每秒钟读取的次数
      w/s   writes per second每秒钟写入的次数
      Kr/s    kilobytes read per second每秒钟读取的千字节数
      Kw/s    kilobytes written per second
      wait    average number of transactions waiting for service (Q length)等待服务的平均事务数
      actv    average number of transactionsactivelybeing serviced (removedfromthe queue but not yet completed)
      %w      percent of time there are transactionswaiting
            for service (queue non-empty)
%W 仍有事务在等待服务的时间百分比(队列非空)
      %b      percent of time the disk is busy(transactions in progress)   磁盘繁忙的时间百分比(事务正在执行中)
Results and Solutions:
从iostat输出结果中需要注意的值:
Reads/writesper second (r/s , w/s)
Percentage busy (%b)
Service time (svc_t)
如果磁盘显示长时间的高reads/writes,并且磁盘的percentage busy (%b)也远大于5%,同时average service time(svc_t)也远大于30
milliseconds,这以下的措施需要被执行:
1.)调整应用,令其使用磁盘i/o更加有效率,可以通过修改磁盘队列、使用应用服务器的cache
2.)将文件系统分布到2个或多个磁盘上,并使用volume manager/disksuite的条带化特点
3.) 增加系统参数值,如inode cache, ufs_ninode。Increase the system parameter values forinode cache, ufs_ninode ,which isNumber of inodes to be held in memory. Inodes are cached globally (for UFS), not on a per-file system basis
4.) 将文件系统移到更快的磁盘/控制器,或者用更好的设备来代替
Virtual Memory Statistics ( vmstat )报告虚拟内存的统计
vmstat -vmstat反映了进程的虚拟内存、虚拟内存、磁盘、trap(是不是翻译成中断??)和cpu的活动情况
在多cpu系统中,vmstat在输出结果中平均了cpu数量。For per-process statistics .如果没有选项,vmstat显示一行虚拟内存活动的概要,汇总。
结果,是从系统启动时开始的。
语法:
/bin/vmstat;   intervalcount
option - 让你指定所需的信息类型,例如 paging-p , cache   -c ,.interrupt -ietc.
如果没有指定选项,将会显示进程、内存、页、磁盘、中断和cpu信息,
interval- 同iostat
count- 同iostat 指定重复进行统计的次数,不可被用于-i和-s选项
例子
   The following command displays a summary of what thesystem
   is doing every five seconds.
   example% vmstat 5
   procsmemory          page             disk      faults      cpu
   r b w swapfree re mf pi p fr de sr s0 s1 s2 s3insycs us sy id
   0 0 0 11456 4120 141 19 1302040048 112 1304 14 82
   0 0 1 10132 4280 0   4 44 00000 2300 211 230 1443 35 62
   0 0 1 10132 4616 0   0 20 00000 1900 150 172 1463 33 64
   0 0 1 10132 5292 0   09 00000 2100 165 105 1301 21 78
The fields of vmstat's display are
   procs
             r   in run queue 在运行队列中
             b   blocked for resources I/O, paging etc.
             w   swapped
   memory (in Kbytes)
            swap -amountofswap   space   currently   available               
            free   - size of the free list 闲置列表长度。
   page ( in units per second).
         re    page reclaims -see-Soptionforhowthis field is modified. 页面回收
         mf    minor faults -see-Soptionforhow    this field is modified. 镜像错误
         pi    kilobytes paged in页面调入的千字节数
         po    kilobytes paged out
         fr    kilobytes freed
         de    anticipated short-term memory shortfall (Kbytes)
         sr    pages scanned by clock algorithm
   disk( operations per second ) 报告每秒钟的磁盘操作总数
         There areslots for up to four disks, labeled with a single letter and number.
         The letter indicatesthetypeofdisk(s = SCSI, i = IPI, etc) . The number isthe logical unit number.
   faults
            in    (non clock) device interrupts
         sy    system calls
         cs    CPU context switches
   cpu-   breakdown of percentage usage of CPUtime.On multiprocessorsthis is an a verage across all processors.
         us    user time
         sy    system time
         id    idle time

结果和解决方案:
A.   CPU issues:
下面几列需要被察看,以确定cpu是否有问题
Processes in the run queue (procs r)
User time (cpu us)
System time (cpu sy)
Idle time (cpu id)
   procs      cpu
   r b w    us syid
   0 0 0    41482
   0 0 1    33562
   0 0 1    33364
   0 0 1    12178
问题情况:
1.) 如果processes in run queue (procs r)的数量远大于系统中cpu的数量,将会使系统便慢。
2.) 如果这个数量是cpu的4倍的话,说明系统正面临cpu能力短缺,这将使系统运行速度大幅度降低
3.) 如果cpu的idle时间经常为0的话,或者系统占用时间(cpu sy)是用户占用时间(cpu us)两辈的话,系统面临缺少cpu资源

解决方案 :
解决这些情况,涉及到调整应用程序,使其能更有效的使用cpu,同时增加cpu的能力或数量。

B.   Memory Issues:
内存的瓶颈取决于scan rate (sr) 。scan rate是每秒时钟对页的扫描 (he scan rate is the pages scanned by the clock algorithm per
second.)如果 scan rate (sr)一直大于200 pages每秒,这时就是内存短缺的现实。
解决方案 :
1. 调整应用和服务器,使其能更好的使用memory和cache
2. 增加系统内存
3. Implement priority paging in s in pre solaris 8 versions by adding line "set priority paging=1" in/etc/system. Remove this line if upgrading from Solaris 7 to 8 & retaining old /etc/system file.
Network Statistics (netstat)
netstat通过选项来显示不通的网络相关的数据结构(netstat displays thecontentsofvariousnetwork-relateddata structures
independing on the options selected.)
语法 :
netstat;
多个选项可以同时使用
Options
-a - displays the state of all sockets.
-r - shows the system routing tables
-i - gives statistics on a per-interface basis.
-m - displays information from the network memory buffers. On Solaris, this shows statistics          forSTREAMS
-p - retrieves statistics for the specified protocol
-s - shows per-protocol statistics. (some implementations allow -ss to remove fileds with a value of 0 (zero) from the display.)
-D - display the status of DHCP configured interfaces.
-n do not lookup hostnames, display only IP addresses.
-d (with -i) displays dropped packets per interface.
-I retrieve information about only the specified interface.
-v be verbose
interval-   number for continuous display of statictics.
Example :
$netstat -rn
Routing Table: IPv4
Destination         Gateway               FlagsRef   Use   Interface
-------------------- -------------------- ----- ----- ------ ---------
192.168.1.0         192.168.1.11         U      1   1444      le0
224.0.0.0             192.168.1.11         U      1   0            le0
default                  192.168.1.1         UG       1   68276
127.0.0.1             127.0.0.1               UH       110497   lo0
这个显示了一台solaris机器的ip为192.168.1.11,他的默认网关192.168.1.1
结果和解决方案:
A.)网络连通
上面的命令经常用来检查网络的连通性。特别是当机器无法访问外部网络时:
1.默认路由ip是否正确
2.能否ping通网关
3. 如果网关地址不对,可以使用route add命令,参考 man route
route command examples:
$route add default ;
$route add 192.0.2.32;
If the router address is correct but still you can't ping itthere may be somenetwork cable /hub/switch problemand you
have to try and eliminate the faulty component .
B.) 网络反映
$ netstat -i
NameMtuNet/DestAddressIpktsIerrsOpktsOerrsCollisQueue
lo08232loopbacklocalhost77814077814000
hme01500server1server1106585663483251102792570
这个选项用于诊断网络问题,网络连通但连接速度慢
Values to look at:
Collisions (Collis)
Output packets (Opkts)
Input errors (Ierrs)
Input packets (Ipkts)
The above values will give information to workout
i.Network collision rate(网络冲突率)如下 :
Network collision rate = Output collision counts / Output packets
网络冲突率大于10%就显示,网络负载过大、网络配置不正确、硬件问题
ii.Input packet error rate(进入包错误率)如下 :
Input Packet Error Rate = Ierrs / Ipkts.
如果input error rate高(ver 0.25 percent),这个主机就正在丢包。hub/switch 连线就需要被检查是否存在潜在的问题。
C.Network socket &TCP Cconnection state
netstat给出了关于网络socket和tcp state的重要信息。只是非常有用的,在寻找开放、关闭和等待网络tcp连接。
netstat返回如下的网络状态 :
   CLOSED               ----Closed.The socketisnotbeing used.
   LISTEN               ----Listening for incoming connections.
   SYN_SENT         ----Actively trying toestablishconnection.
   SYN_RECEIVED---- Initial synchronization of the connection under way.
   ESTABLISHED   ----Connection has been established.
   CLOSE_WAIT      ----Remote shut down; waitingforthe socket to close.
   FIN_WAIT_1      ----Socket closed; shuttingdownconnection.
   CLOSING             ----Closed,   then   remote   shutdown; awaiting acknowledgement.
   LAST_ACK          ----   Remoteshutdown,then   closed ;awaiting acknowledgement.
   FIN_WAIT_2      ----Socket closed; waiting for shutdown from remote.
   TIME_WAIT         ----Wait after close forremoteshutdown retransmission.
   
Example:
#netstat -a
Local Address Remote Address Swind    Send-Q RwindRecv-Q State   
*.* *.* 0 0 24576 0 IDLE
*.22 *.* 0 0 24576 0 LISTEN
*.22 *.* 0 0 24576 0 LISTEN
*.* *.* 0 0 24576 0 IDLE
*.32771 *.* 0 0 24576 0 LISTEN
*.4045 *.* 0 0 24576 0 LISTEN
*.25 *.* 0 0 24576 0 LISTEN
*.5987 *.* 0 0 24576 0 LISTEN
*.898 *.* 0 0 24576 0 LISTEN
*.32772 *.* 0 0 24576 0 LISTEN
*.32775 *.* 0 0 24576 0 LISTEN
*.32776 *.* 0 0 24576 0 LISTEN
*.* *.* 0 0 24576 0 IDLE
192.168.1.184.22 192.168.1.186.50457 41992 0 24616 0 ESTABLISHED
192.168.1.184.22 192.168.1.186.56806 38912 0 24616 0 ESTABLISHED
192.168.1.184.22 192.168.1.183.58672 18048 0 24616 0 ESTABLISHED
ifyou see a lots of connections in FIN_WAIT statetcp/ip parameters   have to be tunedbecause the
connectionsare not being closed and they gets accumulating . After some time system may run out of
resource . TCP parameter can be tuned to define a time out so that connections can be released and
used by new connection.   
A detailed document abouttuning tcp/ip can be found at               
http://www.sean.de/Solaris/soltune.html


本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u1/53154/showart_420478.html
页: [1]
查看完整版本: I/O、内存、网络性能优化命令