vim /etc/httpd/conf/httpd.conf
MPM 有两种工作方式:1、worker 线程 
         2、prefork 进程时(一个连接产生一个进程)

解压     tar fzxv httperf-0.9.0
    cd httperf-0.9.0
    ./configure && make && make install
    vim /tmp/wsesslog
    #session 1 definition 定义一个session,即一个来的访问操作
    /index.html
        /cs.jpg
    /b.html
        /x.jgp

通过脚本可以判定出热点网页:
     awk -F \" '{print $2}' /var/log/httpd/access_log | awk '{print $2}' | grep 'html$' | sort | uniq -c | 
     sort -nr | head -n 10 
     awk ' $7 ~ "html$" {print $7} ' /var/log/httpd/access_log | sort | uniq -c | sort -nr | head -n 10

规则    
httperf --hog(优化参数) --server=192.168.18.199(被测试的主机) --rate(测试的频率) 1 --wsesslog=4,1(thinktime),
/tmp/wesslog  
Reply time[ms]:response  transfer 

压缩
<Ifmodule mod_deflate.c>
DeflateCompressionLevel 6
AddOutputFilterByType DEFLATE text/html
</Ifmodule>



并发量  
1、连接进程数的多少
2、netstat -ant | grep -i "estab" | wc -l 处于estab状态的数量
3、凡是与80端口有关的都算是并发
4、syn estalished

Reply status
2 代表正常
3 代表重定向
4 页面无法请求
5 服务器资源不足

apache的worker模式(如果想用线程方式,建议去用nginx)
vim /etc/sysconfig/httpd
HTTPD=/usr/sbin/httpd.worker
/etc/inint.d/httpd restart

ps -eo nlwp,pid,user,comm | grep apache

nlwp 产看当前进程中有多少个线程
apache自身
1、日志(可以连接到/dev/null)
2、文件描述符(限制进程使用的数是1024)
3、mkdir -pv /tmp/mm
   mount -o size=500M -t tmpfs none /tmp/mm  
   500M 内存到这个目下,以后在对数据处理时,就相当于往内存中写,而这些数据不会因清空缓存而数据丢失,而是相当于做了一个
   预热(保证数据都在内存中,把内存当作硬盘来用)

apache与I/O
1、挂载的时候加上 notime
2、BI/O(电梯层:整合、排序 )层用deadline 时时性比较好
3、分raid

apache与Memory
单个apache对内存的使用情况
awk ' $3 ~ "kB" { sum[$1] += $2 } END {for (key in sum) print key,sum[key]"KB"}' smaps
1、与调用的模快有关 LoadModule
2、与进程数多少有关

apache网络 
httpd协议的最重要参数 
1、http的连线超时时间  Timeout 默认10S
2、KeepAlive on  占用的是内存
   KeepAlive Tmieout 15 
   解决Time_wait数量多的时候
   echo 1 > /proc/sys/net/ipv4/tcp_tw_recycle
   echo 1 > /proc/sys/net/ipv4/tcp_tw_reuse
   注:短时间内不会有请求页面的时候,不需要开启。通常情况下静态页面开启
网络数据进行压缩,用CPU来换取带宽
注:建议大家用apache作动态页面
wiki.nginx.org nginx优化

php优化调整(都与开发进行沟通)

vim /etc/php.ini
max_execution_time = 600;     最大运行时间,最多占用600S
max_input_time = 600;          最大超时时间
memory_limit = 128M           内存限制
-output_buffering = 4096      数据发送之前需要多少缓存

opcode 操作码
软件 xpc apc
首先保证安装PHP: yum install php -y
安装:rpm -ivh php-eaccelerator-0.9.5.2-2.el5.i386.rpm 
vim /etc/php.d/eaccelerator.ini
eaccelerator.shm_sime = "0"   系统默认的内存 ipcs -l  
eaccelerator.shm_ttl = "3600" 缓存时间
eaccelerator.allowed_admin_path = "/var/www/html/control.php 指定管理页面
eaccelerator.cache_dir = "/var/cache/php-eaccelerator" 缓存的磁盘路径
cp /usr/share/doc/php-eaccelerator-0.9.5.2/control.php /var/www/html 拷贝模板
测试:ab -n 100 -c 10 http://192.168.18.199/time.php
关闭缓存再进行测试,比较两次测试里面的时间


vim /etc/security/limits.conf
* soft nofile 102400
* soft nofile 102400
su -
ulimit -SHn
vim /usr/include/bits/typesizes.h
#define __FD_SETSIZE            102400

cd httperf-0.9.0
./configure && make && make install

测试
1、考虑你的并发量:httperf --hog --server=192.168.18.199 --rate 500 --wsesslog=5000000,1,/tmp/wesslog
2、vim /etc/httpd/conf/httpd.conf
   <IfModule prefork.c>
    StartServers       80
    MinSpareServers    50
    MaxSpareServers   200
    ServerLimit       500
    MaxClients        500
    MaxRequestsPerChild  4000
   </IfModule>
3、apache测试脚本 在被测试的机器上运行
    vim /tmp/net
    netstat -ant | awk '$1 ~ "^tcp" {sum[$NF] += 1} END {for (key in sum) print key,sum[key]}'
    :wq
    chmod +x /tmp/net
    watch -n 1 /tmp/net
4、    netstat -ant | grep 18.113(用来测试的机器) | grep -i 'syn_recv' | wc -l
    netstat -ant | grep 18.113(用来测试的机器) | grep -i 'established' | wc -l
    top  load average
    free -m
注:将测试主机和被测试主机的文件描述符都改成 102400
并发:avg        14
     进程数     8900
     进程数+established   8900
     进程数+established+syn_baklog  大约3万多

results matching ""

    No results matching ""