正在加载...
分页: 36/55 第一页 上页 31 32 33 34 35 36 37 38 39 40 下页 最后页 [ 显示模式: 摘要 | 列表 ]

SAR系统性能检测工具

[ 2009/04/08 23:52 | by selboo ]
Options:
  -A    列出保存的当天的所有活动的文件内容, 等同于-bBcdqrRuvwWy -I SUM -n FULL -P ALL

  -b    报告I/O和传送速率统计。这个参数仅用于2.5及以后内核。可显示以下字段
        tps        每秒从物理磁盘I/O的次数。多个逻辑请求会被合并为一个I/O磁盘请求。一次传输的大小是不确定的
         rtps      每秒的读请求数
         wtps      每秒的写请求数
         bread/s   每秒读磁盘的数据块数(in blocks  1 block = 512B, 2.4以后内核)
         bwrtn/s   每秒写磁盘的数据块数(in blocks  1 block = 512B, 2.4以后内核)

  -B     显示内核页统计。 可显示如下字段
         pgpgin/s
         pgpgout/s
         fault/s
         majflt/s

  -c     显示进程创建活动, 显示如下字段
         proc/s    每秒进程创建数

  -d m n  报告每个块设备的活动情况(2.4及以后内核)
         m 每m秒采样一次
         n 共采样n次
         sar -d 30 5
         Average:          DEV       tps  rd_sec/s  wr_sec/s  avgrq-sz  avgqu-sz     await     svctm     %util
                          dev8-0    2.39     16.37     35.99     21.88      0.00      0.85      0.66      0.16
         tps             显示指定设备的每秒I/O流量,多个逻辑请求可以合并为一个物理请求,流量为不确定大小
         rd_sec/s        从设备读取的扇区数,(1扇区=512B)
         wr_sec/s        写入设备的扇区数
         avgrq-sz        流出设备的扇区数
         avgqu-sz        流出设备的平均队列长度
         await           从设备流出的平均I/O请时间,包括请求在队列和服务时的时间
         svctm           平均I/O请求的服务时间
         %util           I/O请求的CPU时间百分比,当数字接近100%时,设备出现饱和

  -H
  -h
  -i interval     选取尽可能接近interval所标识的数量的记录数 (Select data records at  seconds as close as possible to the number specified by the interval parameter)

  -q    报告队列长度和平均负载,可列出下列字段
        runq-sz    执行中的队列长度(等待运行的进程数)
        plist-sz   进程列表中的进程数
        ldavg-1    最后一分钟的系统负载
        ldavg-5    最后5分钟的系统负载
        ldavg-15   最后15
Tags:
在Apache的配置文件中找到下面两行,将注释#去掉,重启。

LoadModule deflate_module modules/mod_deflate.so
LoadModule expires_module modules/mod_expires.so

在你网站的目录下新建.htaccess,添加如下内容:


ExpiresActive On
ExpiresByType image/gif A2592000
ExpiresByType image/jpeg A2592000
ExpiresByType image/png A2592000
ExpiresByType image/x-icon A2592000
ExpiresByType application/x-javascript A604800
ExpiresByType text/css A604800



SetOutputFilter DEFLATE
AddOutputFilterByType DEFLATE text/html text/css image/gif image/jpeg image/png application/x-javascript


解释一下。ExpiresByType是通过MIME类型来设置具体文件的缓存时间,A表示访问,A后面的数字表示访问后的缓存时间。AddOutputFilterByType表示根据后面的MIME类型来压缩文件,这里对css,html,gif,jpeg,png,JavaScript等进行gzip压缩。更多选项请参考apache手册哦。

关闭ETag。Etag的问题在于,它是根据可以辨别网站所在的服务器的具有唯一性的属性来生成的。当浏览器从一台服务器上获得页面内容后到另外一台服务器上进行验证时ETag就会不匹配,这种情况对于使用服务器组和处理请求的网站来说是非常常见的。在配置文件中写入下面一行即可:

FileETag none

如果是多服务器负载均衡,可以设置为FileETag MTime Size,
apache默认设置为FileETag INode MTime Size,去掉INode。
Tags: ,

性能分析工具汇总

[ 2009/04/08 23:32 | by selboo ]
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/中的文件,修改内核参数。

#cd /proc/sys/kernel/

# ls /proc/sys/kernel/

acct hotplug panic real-root-dev

cad_pid modprobe panic_on_oops sem

cap-bound msgmax pid_max shmall

core_pattern msgmnb powersave-nap shmmax

core_uses_pid msgmni print-fatal-signals shmmni

ctrl-alt-del ngroups_max printk suid_dumpable

domainname osrelease printk_ratelimit sysrq

exec-shield ostype printk_ratelimit_burst tainted

exec-shield-randomize overflowgid pty threads-max

hostname overflowuid random version

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

# sysctl kernel.threads-max

kernel.threads-max = 8192

# sysctl kernel.threads-max=10000

kernel.threads-max = 10000



Memory性能调整

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

页面频繁换进换出;

缺少非活动页。

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

Memory性能调整方法:

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

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

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

# ls /proc/sys/vm/

block_dump laptop_mode nr_pdflush_threads

dirty_background_ratio legacy_va_layout overcommit_memory

dirty_expire_centisecs lower_zone_protection overcommit_ratio

dirty_ratio max_map_count page-cluster

dirty_writeback_centisecs min_free_kbytes swappiness

hugetlb_shm_group nr_hugepages vfs_cache_pressure

# sysctl vm.min_free_kbytes

vm.min_free_kbytes = 1024

# sysctl -w vm.min_free_kbytes=2508

vm.min_free_kbytes = 2508

# cat /etc/sysctl.conf



vm.min_free_kbytes=2058



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等文件系统;

# mkfs -t reiserfs -j /dev/sdc1

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

tune2fs (ext2/ext3)

reiserfstune (reiserfs)

jfs_tune (jfs)

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

# vi /etc/fstab



/dev/sdb1 /backup reiserfs acl, user_xattr, noatime, nodiratime 1 1

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。增加网络缓冲区和包的队列。

# cat /proc/sys/net/ipv4/tcp_mem

196608 262144 393216

# cat /proc/sys/net/core/rmem_default

135168

# cat /proc/sys/net/core/rmem_max

131071

# cat /proc/sys/net/core/wmem_default

135168

# cat /proc/sys/net/core/wmem_max

131071

# cat /proc/sys/net/core/optmem_max

20480

# cat /proc/sys/net/core/netdev_max_backlog

300

# sysctl net.core.rmem_max

net.core.rmem_max = 131071

# sysctl -w net.core.rmem_max=135168

net.core.rmem_max = 135168

3。调整Webserving。

# sysctl net.ipv4.tcp_tw_reuse

net.ipv4.tcp_tw_reuse = 0

# sysctl -w net.ipv4.tcp_tw_reuse=1

net.ipv4.tcp_tw_reuse = 1

# sysctl net.ipv4.tcp_tw_recycle

net.ipv4.tcp_tw_recycle = 0

# sysctl -w net.ipv4.tcp_tw_recycle=1

net.ipv4.tcp_tw_recycle = 1
Tags: ,

Apache 优化加速

[ 2009/04/08 23:22 | by selboo ]
站点描述:
全静态页面,站点数据大小250M左右。
内存:4G
内存使用率才:10%都不到

解决方案;
本机加个SQUID做加速。个人感觉意义不大。
然后,看了下apache cookbook有个叫mem_cahce的模块。想尝试下呵呵。

使用mem_cache模块,编译apache时候必须添加
"--enable-cache"
"--enable-mem-cache"
或者使用apxs -ica 添加模块

mod_mem_cache需要mod_cache模块的支持。
mem_cache 简单应用:
CODE:

    
        
        CacheEnable mem /                    
        MCacheSize 262144                
        MCacheMaxObjectCount 10000        
        MCacheMinObjectSize 1            
        MCacheMaxObjectSize 1000000
        MCacheRemovalAlgorithm LRU
        

    

        CacheEnable mem /                    #需要存储的目录。
        MCacheSize 262144                     #cache使用内存的最大数量(kbyte)
        MCacheMaxObjectCount 10000      #允许在cache中存储的最大数量
        MCacheMinObjectSize 1                 #最小允许在cache中存储文件的字节数(byte)
        MCacheMaxObjectSize 1000000          #最大允许在cache中存储文件的字节书(byte)
        MCacheRemovalAlgorithm LRU             #文件在cache中使用的算法(默认GDSF)

详细配置请参考:
http://httpd.apache.org/docs/2.2/mod/mod_cache.html
http://httpd.apache.org/docs/2.2/mod/mod_mem_cache.html
http://httpd.apache.org/docs/2.2/caching.html#inmemory
Tags: , ,
一、PHP加速器介绍

      PHP加速器是一个为了提高PHP执行效率,从而缓存起PHP的操作码,这样PHP后面执行就不用解析转换了,可以直接调用PHP操作码,这样速度上就提高了不少。

      Apache中使用mod_php的请求、响应执行流程:

1、Apache接收请求。
2、Apache传递请求给mod_php。
3、mod_php定位磁盘文件,并加载到内存中。
4、mod_php编译源代码成为opcode树。
5、mod_php执行opcode树。

      PHP加速器相应的就是第四步,它的目的就是防止PHP每次请求都重复编译PHP代码,因为在高访问量的网站上,大量的编译往往没有执行速度快呢?所以这里面有个瓶颈就是PHP的重复编译既影响了速度又加载了服务器负载,为了解决此问题,PHP加速器就这样诞生了。

二、PHP加速器安装与配置

1、安装配置APC

      APC全称是Alternative PHP Cache,官方翻译叫”可选PHP缓存”,它是PHP PECL中的一个扩展,好像是facebook在使用它,下面开始安装(ubuntu环境):      

01.$wget http://pecl.php.net/get/APC-3.0.19.tgz
$tar xvzf APC-3.0.19.tgz
$cd APC-3.0.19/APC-3.0.19
$/usr/local/php/bin/phpize
$./configure –enable-apc –enable-apc-mmap –with-php-config=/usr/local/php/bin/php-config
$make
$sudo make install


下面我们再配置APC,因为我的PECL扩展路径改变了,所以我得移动下编译好的文件:


$sudo mv /usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/apc.so /usr/local/php/lib/php/extensions/PECL


      然后我们再编辑php.ini文件进行配置,请把下面的代码加入到php.ini中即可:

extension_dir = "/usr/local/php/lib/php/extensions/PECL"
extension = apc.so
; APC
apc.enabled = 1
apc.shm_segments = 1
apc.shm_size = 64
apc.optimization = 1
apc.num_files_hint = 0
apc.ttl = 0
apc.gc_ttl = 3600
apc.cache_by_default = on


      这样重启apache就会在phpinfo()信息中显示。

2、安装配置eAccelerator

      eAccelerator的前身其实是truck-mmcache,因为开发truk-mmcache的人被Zend给招安了,所以开发eAccelerator的人继承了truk-mmcache的一些特性,设计出eAccelerator加速器。安装如下:

01.$wget http://jaist.dl.sourceforge.net/sourceforge/eaccelerator/eaccelerator-0.9.5.tar.bz2
02.$tar -jxf eaccelerator-0.9.5.tar.bz2
03.$cd eaccelerator-0.9.5
04.$/usr/local/php/bin/phpize
05.$./configure –enable-eaccelerator=shared –with-php-config=/usr/local/php/bin/php-config
06.$make
07.$sudo make install
08.$sudo mv /usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/eaccelerator.so /usr/local/php/lib/php/extensions/PECL


      将下面代码加入php.ini文件中


01.extension = eaccelerator.so
02.; eAccelerator
03.eaccelerator.shm_size = "16"
04.eaccelerator.cache_dir = "/tmp/eaccelerator"
05.eaccelerator.enable = "1"
06.eaccelerator.optimizer = "1"
07.eaccelerator.check_mtime = "1"
08.eaccelerator.debug = "0"
09.eaccelerator.filter = ""
10.eaccelerator.shm_max = "0"
11.eaccelerator.shm_ttl = "0"
12.eaccelerator.prune_period = "0"
13.eaccelerator.shm_only = "0"
14.eaccelerator.compress = "1"
15.eaccelerator.compress_level = "9"
      

      创建缓存目录,重启apache

01.$sudo mkdir /tmp/eaccelerator
02.$sudo chmod 777 /tmp/eaccelerator
03.$sudo /usr/local/apache/apachectl restart


      在phpinfo()检查是否安装成功.

3、安装配置XCache

      XCache作为国人自己开发的东西,做小菜鸟的我也感到骄傲,而且XCache无论在速度还是性能上都做的不错。下面就赶紧让我们品尝它吧!


01.$wget http://xcache.lighttpd.net/pub/Releases/1.2.2/xcache-1.2.2.tar.gz
02.$tar xvzf xcache-1.2.2.tar.gz
03.$cd xcache-1.2.2
04.$/usr/local/php/bin/phpize
05.$./configure –enable-xcache –enable-xcache-coverager –with-php-config=/usr/local/php/php-config
06.$make
07.$sudo make install
08.$sudo mv /usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/xcache.so /usr/local/php/lib/php/extensions/PECL


      在php.ini添加配置信息:


01.extension = xcache.so
02.; xcache
03.xcache.admin.user = "admin"
04.xcache.admin.pass = "(执行) echo ’(你的密码)’|md5sum(得出的密文)"
05.;
06.xcache.size = 24M
07.xcache.shm_scheme = "mmap"
08.xcache.count = 2
09.xcache.slots = 8k
10.xcache.ttl = 0
11.xcache.gc_interval = 0
12.
13.xcache.var_size = 8M
14.xcache.var_count = 1
15.xcache.var_slots = 8k
16.xcache.var_ttl = 0
17.xcache.var_maxttl = 0
18.xcache.var_gc_interval = 300
19.xcache.test = Off
20.xcache.readonly_protection = On
21.xcache.mmap_path = "/tmp/xcache"
22.xcache.coredump_directory = ""
23.xcache.cacher = On
24.xcache.stat = On
25.xcache.optimizer = Off
26.;
27.xcache.coverager = On
28.xcache.coveragedump_directory = ""


      创建缓存目录,重启apache


01.$sudo mkdir /tmp/xcache
02.$sudo chmod 777 /tmp/xcache
03.$sudo /usr/local/apache/bin/apachectl restart


      去查看phpinfo()信息吧!

三、PHP加速器测试

1、测试环境

硬件:   AMD Athlon 64 X2 Dual Core Processor 4400+ @ 2.2GHz  CPU,  2GB 内存. 160GB SATA 硬盘
软件:   Linux Ubuntu server Gutsy 7.10, Apache 2.2.4, MySQL 5.0.45 和 PHP 5.2.3
测试指令:  ab -c5 -n3000 http://example.com/    
(我们使用的是Apache Benchmark (ab) 工具,并发连接为5,3000次请求)

2、测试结果

无任何加速器:


01.Document Path:          /
02.Document Length:        21757 bytes
03.Concurrency Level:      5
04.Time taken for tests:   288.255212 seconds
05.Complete requests:      3000
06.Failed requests:        0
07.Write errors:           0
08.Total transferred:      66777000 bytes
09.HTML transferred:       65271000 bytes
10.Requests per second:    10.41 [#/sec] (mean)
11.Time per request:       480.425 [ms] (mean)
12.Time per request:       96.085 [ms] (mean, across all concurrent requests)
13.Transfer rate:          226.23 [Kbytes/sec] received
14.Connection Times (ms)
15.min  mean[+/-sd] median   max
16.Connect:        0    0   0.5      0      19
17.Processing:   181  479 186.0    444    1822
18.Waiting:      166  461 184.7    427    1708
19.Total:        181  479 186.0    444    1822
20.Percentage of the requests served within a certain time (ms)
21.50%    444
22.66%    525
23.75%    577
24.80%    619
25.90%    732
26.95%    819
27.98%    946
28.99%   1012
29.100%   1822 (longest request)  
    

APC加速器:


01.Document Path:          /
02.Document Length:        21757 bytes
03.Concurrency Level:      5
04.Time taken for tests:   98.530068 seconds
05.Complete requests:      3000
06.Failed requests:        0
07.Write errors:           0
08.Total transferred:      66777000 bytes
09.HTML transferred:       65271000 bytes
10.Requests per second:    30.45 [#/sec] (mean)
11.Time per request:       164.217 [ms] (mean)
12.Time per request:       32.843 [ms] (mean, across all concurrent requests)
13.Transfer rate:          661.84 [Kbytes/sec] received
14.Connection Times (ms)
15.min  mean[+/-sd] median   max
16.Connect:        0    0   0.0      0       2
17.Processing:    58  163  71.2    155    2452
18.Waiting:       53  158  69.6    150    2329
19.Total:         58  163  71.2    155    2452
20.Percentage of the requests served within a certain time (ms)
21.50%    155
22.66%    178
23.75%    193
24.80%    204
25.90%    235
26.95%    258
27.98%    285
28.99%    302
29.100%   2452 (longest request)  


eAccelerator加速器:


01.Document Path:          /
02.Document Length:        21757 bytes
03.Concurrency Level:      5
04.Time taken for tests:   95.983986 seconds
05.Complete requests:      3000
06.Failed requests:        0
07.Write errors:           0
08.Total transferred:      66777000 bytes
09.HTML transferred:       65271000 bytes
10.Requests per second:    31.26 [#/sec] (mean)
11.Time per request:       159.973 [ms] (mean)
12.Time per request:       31.995 [ms] (mean, across all concurrent requests)
13.Transfer rate:          679.39 [Kbytes/sec] received
14.Connection Times (ms)
15.min  mean[+/-sd] median   max
16.Connect:        0    0   0.1      0       3
17.Processing:    57  159  91.3    148    3830
18.Waiting:       50  152  89.8    142    3704
19.Total:         57  159  91.3    148    3830
20.Percentage of the requests served within a certain time (ms)
21.50%    148
22.66%    174
23.75%    193
24.80%    205
25.90%    239
26.95%    263
27.98%    289
28.99%    309
29.100%   3830 (longest request)


      XCache加速器:


01.Document Path:          /
02.Document Length:        21757 bytes
03.Concurrency Level:      5
04.Time taken for tests:   99.76300 seconds
05.Complete requests:      3000
06.Failed requests:        0
07.Write errors:           0
08.Total transferred:      66777000 bytes
09.HTML transferred:       65271000 bytes
10.Requests per second:    30.28 [#/sec] (mean)
11.Time per request:       165.127 [ms] (mean)
12.Time per request:       33.025 [ms] (mean, across all concurrent requests)
13.Transfer rate:          658.19 [Kbytes/sec] received
14.Connection Times (ms)
15.min  mean[+/-sd] median   max
16.Connect:        0    0   0.0      0       2
17.Processing:    59  164  83.4    155    3367
18.Waiting:       52  156  66.4    148    1802
19.Total:         59  164  83.4    155    3367
20.Percentage of the requests served within a certain time (ms)
21.50%    155
22.66%    178
23.75%    196
24.80%    206
25.90%    237
26.95%    263
27.98%    287
28.99%    305
29.100%   3367 (longest request)  


3、结果摘要

请求时间(秒) 单次请求时间(毫秒) 最大内存占用(MB) 最小内存占用(MB)
None  10.41            96.08                  24                              24
APC 30.45               32.84                  21                              21
eAccelerator 31.26   31.99                  23                              18
XCache 30.28          33.02                  29                              19

四、PHP加速器比较结果总结

     1、通过测试得出eAccelerator在请求时间和内存占用综合方面是最好的。
     2、通过测试得出使用加速器比无加速器在请求时间快了3倍左右。
     3、通过各个官方观察,XCache是更新最快的,这也说明最有发展的。

      以上是总结结果,你也许会问我到底用那个加速器好呢?我只能告诉你,首先,用一定比不用好,其次每个加速器还有一些可以调优的参数,所以要根据你的系统环境而定,然后,我个人觉得你可以详细研究下eAccelerator和XCache,这两款潜力还是很大的,最后我从比较专业的测试网站搞了一张结果图:
点击在新窗口中浏览此图片
分页: 36/55 第一页 上页 31 32 33 34 35 36 37 38 39 40 下页 最后页 [ 显示模式: 摘要 | 列表 ]