- 论坛徽章:
- 0
|
优化步骤
确定优化目标
收集性能数据
分析,做出假设
进一步收集数据证明或否定假设
调整系统
硬件性能
- CPU
- /proc/cpuinfo
- bit: uname -m
- 个数:cat /proc/cpuinfo | grep processor | wc
- 主频:cat /proc/cpuinfo | grep "cpu MHz"
- BogoMIPS: cat /var/log/dmesg | grep BogoMIPS
- Memory
- /proc/meminfo
- level 1 and leve 2 cache
- free
- I/O
性能工具
- 进程:top, ps, pmap, pstack
- 内存:vmstat, free
- 磁盘:iostat, hdparm
- 网络:netstat, tcpdump, MRTG, pmacct, ntop
- 其他:strace, ltrace, oprofile, dprobes, performance inspector, isag, LKST, sysctl, syslog
apache
- http://httpd.apache.org/docs-2.0/misc/perf-tuning.html
基准测试工具
- linpack
- http://www.netlib.org/utk/people/JackDongarra/faq-linpack.html
- 运行一些浮点矩阵运算
- 主要测量CPU浮点计算能力,也受到内存带宽的影响。
- top500.org用的是linpack
- 测量方法:
- wget http://www.netlib.org/benchmark/linpackc
- cc -DDP -DUNROLL -O2 linpackc -lm -o linpack
- ./linpack
- 测量结果:
- 我的ASUS V6800V (PentiumM 2.0G) 的linpack结果为:340Mflops
- 我的desktop (Celeron 1.7G) 的结果为:200Mflops
- builder (4 Xeon 3.4G) 的结果为:680Mflops
- 目前世界第一的Blue Genes的结果为:70720Gflops (Rmax)
- 曙光4000A的结果为:8061Gflops (Rmax)
- nbench
- iozone
- bonnie++
- netbench
- tiobench
- loadrunner
- mysql-bench
- apache bench (AB)
性能数据
/proc/meminfoMemTotal: 1032048 kB 重点工具介绍
vmstat是procps项目中的一员,除了ps, top, kill之外,procps还提供很多有用的工具,比如: watch, pmap等。
vmstat = "Virtual Memory Statistics". 虽然从名称上看是收集有关内存管理系统性能数据的,但其实vmstat还提供进程,CPU, 磁盘I/O等其他性能数据:
procs -----------memory---------- ---swap-- -----io---- --system-- ----cpu----
r b swpd free buff cache si so bi bo in cs us sy id wa
0 0 105128 232828 29852 405364 11 27 58 50 1125 821 6 1 91 1
0 0 105128 232828 29860 405364 0 0 0 72 1090 301 3 0 96 1
- 进程
- r - 正在等待CPU的进程数目(包括正在运行的进程),也就是run-queue的大小。
- b - 处于不可中断睡眠状态的进程数目。比如等待I/O完成。
- 内存
- swpd - 交换分区中已经被使用的交换内存大小。
- free - 空闲内存大小
- buff - 用于写缓冲的内存大小
- cache - 用于读缓冲的内存大小
- 交换分区
- si - 每秒交换入内存页
- sw - 每秒交换出内存页
- I/O
- bi - 每秒从块设备中读入的块数
- bo - 每秒向块设备中写入的块数
- 系统
- in - 每秒发出中断数目
- cs - 每秒进行上下文切换时间
- CPU
- us - 用户时间百分比
- sy - 系统时间百分比
- id - 空闲时间百分比
- wa - IO等待时间百分比
- 2.4核心
- 只有 user, nice, system, idle
- us = user+nice
- sy = system
- id = idle
- irq = softirq = wa = 0
- 2.6核心
- 有 user, nice, system, idle, iowait, irq, softirq
- us = user+nice
- sy = system+irq+softirq
- id = idle+iowait
Rule of Thumb
现象
说明
解决方案
运行队列个数 >> CPU个数
CPU是系统性能瓶颈
纵向扩展:升级CPU或增加CPU个数
横向扩展:做负载均衡
调节应用
swap-io, swap-out较高
内存压力较大
误解问题
用户的描述有时会有岐义
从多个角度问同一个问题
小技巧
- 更好的ps结果输出
- ps -eo user,pid,ppid,%cpu,%mem,vsz,rss,tty,stat,start,time,wchan,command --forest
- ps -emo user,pid,ppid,%cpu,%mem,vsz,rss,tty,stat,start,time,wchan,command
- top -id 1
- watch
- 仔细记录
- free's free != real free
- try truss
Case Study
- ICBC
- china news (Oracle 9.2.0.1)
- 内存泄漏检查
ToDo
- strace, ltrace 原理
- hdparm 原理
- try kprobes/dprobes
- try LKST
- try kdb
- sysctl
- cook the sar result a little bit more:
- average CPU time (user, sys, iowait)
- peak CPU time (what? when?)
- average run queue size
- peak run queue size
- network send/recv
- I/O read/write
- used memory size
参考资料
- http://people.redhat.com/alikins/system_tuning.html
- Performance Tuning for Linux® Servers
- http://www.pearsoned.co.uk/Bookshop/detail.asp?item=100000000052291
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/22249/showart_158304.html |
|