标签:style blog http io os ar java for sp
php网站优化最佳实践:优化前端(压缩js/css/images)--->程序优化(编码最佳实践、opcode缓存、变量/数据缓存)--->数据库、服务器调优-->操作系统调优
定义请求/响应生命周期
典型的http请求包含正在尝试访问的主机信息、浏览器信息以及对web服务器有用的其他信息。
实例:
D:\Webdev\bin\apache\apache2.2.22\bin>ab -n 10000 -c 50 http://localhost/phpinf
.php
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking localhost (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Completed 10000 requests
Finished 10000 requests
Server Software: Apache/2.2.8
Server Hostname: localhost
Server Port: 80
Document Path: /phpinfo.php
Document Length: 52477 bytes
Concurrency Level: 50
Time taken for tests: 22.932 seconds
Complete requests: 10000
Failed requests: 2158
(Connect: 0, Receive: 0, Length: 2158, Exceptions: 0)
Write errors: 0
Total transferred: 526424140 bytes #传输的总数据大小(以字节为单位);
HTML transferred: 524774140 bytes
Requests per second: 436.07 [#/sec] (mean) #web服务器在模拟流量下每秒可以支持的请求总数;
Time per request: 114.660 [ms] (mean) #完成一个请求所花费的最长时间(以毫秒为单位)
Time per request: 2.293 [ms] (mean, across all concurrent requests) #完成一个请求所花费的最长时间(以毫秒为单位)
Transfer rate: 22417.81 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 1.9 0 16
Processing: 16 114 32.4 109 468
Waiting: 0 109 26.6 109 281
Total: 16 114 32.4 109 468
Percentage of the requests served within a certain time (ms)
50% 109
66% 109
75% 125
80% 125
90% 140
95% 172
98% 203
99% 218
100% 468 (longest request)
关键字段:HTML transferred(整个模拟传输的内容正文的总大小)、Request per second(每秒支持的请求总数)、Time per request(满足一个请求需要花费的总时间)
目标:减少HTML transferred、提高Request per second并且降低Time per request
连接指标细目分类:
-c的值必须小于等于n的值
模拟10个用户在20秒的时间内同时访问网站
ab - n http://localhost/而不是ab -n http://localhost,加上/
设置用户代理:
apache处理并发是通过MPM模块完成的,MPM有三种处理模式(perform、worker、winnt)首先查看MPM的处理模式
然后查看httpd.conf,加载MPM模块
修改httpd-mpm.conf
测试指标
几个关键的指标:
Data transerred:响应数据的总大小(不包含头数据)
Transaction rate:每秒要响应的事务总数
Longest transaction:满足一个请求所需的最长时间
Shortest transaction:满足一个请求所需的最短时间 9.85 trans/sec
在/usr/local/etc/urls.txt
测试
测试结果:
工具:
1.分析响应(Firebug、YSlow和Page Speed)
2.优化响应(YUI compressor,Closure Compiler和Smush.it),利用这些工具压缩JavaScript、CSS以及网页所需的图像。
php相关性能说明的列表:
http://talks.php.net/index.php/PHP
代码测试:
require_once_test.php内容:
几个类文件只是定义了一个空类
每秒处理 1077.93个请求,处理时间为9.277ms
测试require:
require_test.php内容:
其他文件还是定义一个空类
测试结果:
可以看出,每秒的请求数从1077个到1612个请求,响应时间从9秒降到6秒。
for1.php:
for2.php:
连续运行这两个文件,发现后者比前者快好多
标签:style blog http io os ar java for sp
原文地址:http://www.cnblogs.com/luoyunshu/p/4035854.html