Linux下性能分析工具汇总

来自:http://os.51cto.com/art/201104/253114.htm

本文讲述的是:CPU性能分析工具、Memory性能分析工具、I/O性能分析工具、Network性能分析工具、  Linux 性能调优工具、Linux下性能分析工具汇

AD:2013云计算架构师峰会课程资料下载

性能分析工具汇总

CPU性能分析工具:

vmstat

ps

sar

time

strace

pstree

top

Memory性能分析工具:

vmstat

strace

top

ipcs

ipcrm

cat /proc/meminfo

cat /proc/slabinfo

cat /proc//maps

I/O性能分析工具:

vmstat

ipstat

repquota

quotacheck

Network性能分析工具:

ifconfig

ethereal

tethereal

iptraf

iwconfig

nfsstat

mrtg

ntop

netstat

cat /proc/sys/net

Linux 性能调优工具

当通过上述工具及命令,我们发现了应用的性能瓶颈以后,我们可以通过以下工具或者命令来进行性能的调整。

CPU性能调优工具:

nice / renic

sysctl

Memory性能调优工具:

swapon

ulimit

sysctl

I/O性能调优工具:

edquota

quoton

sysctl

boot line:

elevator=

Network性能调优工具:

ifconfig

iwconfig

sysctl

CPU性能调整

当一个系统的CPU空闲时间或者等待时间小于5%时,我们就可以认为系统的CPU资源耗尽,我们应该对CPU进行性能调整。

CPU性能调整方法:

编辑/proc/sys/kernel/中的文件,修改内核参数。

  1. #cd /proc/sys/kernel/ 
  2.  
  3. # ls /proc/sys/kernel/ 
  4.  
  5. acct hotplug panic real-root-dev 
  6.  
  7. cad_pid modprobe panic_on_oops sem 
  8.  
  9. cap-bound msgmax pid_max shmall 
  10.  
  11. core_pattern msgmnb powersave-nap shmmax 
  12.  
  13. core_uses_pid msgmni print-fatal-signals shmmni 
  14.  
  15. ctrl-alt-del ngroups_max printk suid_dumpable 
  16.  
  17. domainname osrelease printk_ratelimit sysrq 
  18.  
  19. exec-shield ostype printk_ratelimit_burst tainted 
  20.  
  21. exec-shield-randomize overflowgid pty threads-max 
  22.  
  23. hostname overflowuid random version 
  24.  

一般可能需要编辑的是pid_max和threads-max,如下:

  1. # sysctl kernel.threads-max 
  2.  
  3. kernel.threads-max = 8192
  4.  
  5. # sysctl kernel.threads-max=10000
  6.  
  7. kernel.threads-max = 10000
  8.  

Memory性能调整

当一个应用系统的内存资源出现下面的情况时,我们认为需要进行Memory性能调整:

页面频繁换进换出;

缺少非活动页。

例如在使用vmstat命令时发现,memory的cache使用率非常低,而swap的si或者so则有比较高的数据值时,应该警惕内存的性能问题。

Memory性能调整方法:

1。关闭非核心的服务进程。

相关的方法请见CPU性能调整部分。

2。修改/proc/sys/vm/下的系统参数。

  1. # ls /proc/sys/vm/ 
  2.  
  3. block_dump laptop_mode nr_pdflush_threads 
  4.  
  5. dirty_background_ratio legacy_va_layout overcommit_memory 
  6.  
  7. dirty_expire_centisecs lower_zone_protection overcommit_ratio 
  8.  
  9. dirty_ratio max_map_count page-cluster 
  10.  
  11. dirty_writeback_centisecs min_free_kbytes swappiness 
  12.  
  13. hugetlb_shm_group nr_hugepages vfs_cache_pressure 
  14.  
  15. # sysctl vm.min_free_kbytes 
  16.  
  17. vm.min_free_kbytes = 1024
  18.  
  19. # sysctl -w vm.min_free_kbytes=2508
  20.  
  21. vm.min_free_kbytes = 2508
  22.  
  23. # cat /etc/sysctl.conf 
  24.  
  25. … 
  26.  
  27. vm.min_free_kbytes=2058
  28.  
  29. … 
  30.  

3。配置系统的swap交换分区等于或者2倍于物理内存。

# free

total used free shared buffers cached

Mem: 987656 970240 17416 0 63324 742400

-/+ buffers/cache: 164516 823140

Swap: 1998840 150272 1848568

I/O性能调整

系统出现以下情况时,我们认为该系统存在I/O性能问题:

系统等待I/O的时间超过50%;

一个设备的平均队列长度大于5。

我们可以通过诸如vmstat等命令,查看CPU的wa等待时间,以得到系统是否存在I/O性能问题的准确信息。

I/O性能调整方法:

1。修改I/O调度算法。

Linux已知的I/O调试算法有4种:

deadline - Deadline I/O scheduler

as - Anticipatory I/O scheduler

cfq - Complete Fair Queuing scheduler

noop - Noop I/O scheduler

可以编辑/etc/yaboot.conf文件修改参数elevator得到。

# vi /etc/yaboot.conf

image=/vmlinuz-2.6.9-11.EL

label=linux

read-only

initrd=/initrd-2.6.9-11.EL.img

root=/dev/VolGroup00/LogVol00

append="elevator=cfq rhgb quiet"

2。文件系统调整。

对于文件系统的调整,有几个公认的准则:

将I/O负载相对平均的分配到所有可用的磁盘上;

选择合适的文件系统,Linux内核支持reiserfs、ext2、ext3、jfs、xfs等文件系统;

  1. # mkfs -t reiserfs -j /dev/sdc1 
  2.  

文件系统即使在建立后,本身也可以通过命令调优;

  1. tune2fs (ext2/ext3) 
  2.  
  3. reiserfstune (reiserfs) 
  4.  
  5. jfs_tune (jfs) 
  6.  

3。文件系统Mount时可加入选项noatime、nodiratime。

  1. # vi /etc/fstab 
  2.  
  3. … 
  4.  
  5. /dev/sdb1 /backup reiserfs acl, user_xattr, noatime, nodiratime 1 1 
  6.  

4。调整块设备的READAHEAD,调大RA值。

[root@overflowuid ~]# blockdev --report

RO RA SSZ BSZ StartSec Size Device

rw 256 512 4096 0 71096640 /dev/sdb

rw 256 512 4096 32 71094240 /dev/sdb1

[root@overflowuid ~]# blockdev --setra 2048 /dev/sdb1

[root@overflowuid ~]# blockdev --report

RO RA SSZ BSZ StartSec Size Device

rw 2048 512 4096 0 71096640 /dev/sdb

rw 2048 512 4096 32 71094240 /dev/sdb1

Network性能调整

一个应用系统出现如下情况时,我们认为该系统存在网络性能问题:

网络接口的吞吐量小于期望值;

出现大量的丢包现象;

出现大量的冲突现象。

Network性能调整方法:

1。调整网卡的参数。

# ethtool eth0

Settings for eth0:

Supported ports: [ TP ]

Supported link modes: 10baseT/Half 10baseT/Full

100baseT/Half 100baseT/Full

1000baseT/Full

Supports auto-negotiation: Yes

Advertised link modes: 10baseT/Half 10baseT/Full

100baseT/Half 100baseT/Full

1000baseT/Full

Advertised auto-negotiation: Yes

Speed: 100Mb/s

Duplex: Half

Port: Twisted Pair

PHYAD: 0

Transceiver: internal

Auto-negotiation: on

Supports Wake-on: d

Wake-on: d

Current message level: 0x00000007 (7)

Link detected: yes

#ethtool -s eth0 duplex full

#ifconfig eth0 mtu 9000 up

2。增加网络缓冲区和包的队列。

  1. # cat /proc/sys/net/ipv4/tcp_mem 
  2.  
  3. 196608 262144 393216 
  4.  
  5. # cat /proc/sys/net/core/rmem_default 
  6.  
  7. 135168 
  8.  
  9. # cat /proc/sys/net/core/rmem_max 
  10.  
  11. 131071 
  12.  
  13. # cat /proc/sys/net/core/wmem_default 
  14.  
  15. 135168 
  16.  
  17. # cat /proc/sys/net/core/wmem_max 
  18.  
  19. 131071 
  20.  
  21. # cat /proc/sys/net/core/optmem_max 
  22.  
  23. 20480 
  24.  
  25. # cat /proc/sys/net/core/netdev_max_backlog 
  26.  
  27. 300 
  28.  
  29. # sysctl net.core.rmem_max 
  30.  
  31. net.core.rmem_max = 131071
  32.  
  33. # sysctl -w net.core.rmem_max=135168
  34.  
  35. net.core.rmem_max = 135168
  36.  

3。调整Webserving。

  1. # sysctl net.ipv4.tcp_tw_reuse 
  2.  
  3. net.ipv4.tcp_tw_reuse = 0
  4.  
  5. # sysctl -w net.ipv4.tcp_tw_reuse=1
  6.  
  7. net.ipv4.tcp_tw_reuse = 1
  8.  
  9. # sysctl net.ipv4.tcp_tw_recycle 
  10.  
  11. net.ipv4.tcp_tw_recycle = 0
  12.  
  13. # sysctl -w net.ipv4.tcp_tw_recycle=1
  14.  
  15. net.ipv4.tcp_tw_recycle = 1

Linux下性能分析工具的汇总就讲到这里了。

posted @ 2014-02-24 19:17  TechDOC  阅读(484)  评论(0编辑  收藏  举报