1.吞吐率:单位时间内服务器处理的请求数 reqs/s
2.apache 开启module_status 查看服务器状态:
加载module_status并在配置文件中添加:
<location /server-status> //命令名称,可以修改为xx-server-status
SetHandler server-status
Order Deny,Allow
Deny from all
Allow from all //允许的访问IP,在生产环境中需要修改为特定的IP地址
</location>
这样在浏览器中输入http://localhost/server-status 就可以看到状态了
3.apache压力测试:使用apache自带的ab命令 E:\wamp\bin\apache\apache2.2.8\bin> ab -V 可以看到ab工具的版本
使用命令 ab -n1000 -c10 http://localhost/index.php 可以进行压力测试
-n1000 表示总请求为1000
-c10 表示并发用户数为10
http://localhost/index.php 表示请求地址
命令结果:
server software 表示web服务器的软件名称
server Hostname 表示url中主机部分的名称
server port 表示web服务器监听的端口
document path 表示url中的绝对根路径
document length 表示http响应数据的正文长度
concurrency level 表示并发用户数
time taken for tests 表示请求被处理完成所花费的总时间
complete requests 表示总请求数
failed requests 表示失败的请求数
total transferred 表示所有请求的响应数据长总和
Html transferred 表示所有请求的响应数据中正文数据的总和
requests per second 吞吐率 每秒处理的请求次数
time per request 用户平均等待时间
time per request (across all concurrent requests) 服务器平均请求处理时间 time per request/concurrency level
transfer rate 请求在单位时间内从服务器获取的数据长度 =total transferred/time taken for tests 用于计算最大请求时所需要的带宽
Percentage of the requests served within a certain time (ms) 描述每个请求处理时间的分布情况
4.缓存的几种方式,以测试结果显示吞吐率:
smarty cache: 173
APC cache: 473
XCache cache: 462
memcache cache: 388
其中smarty是页面缓存,apc和xcache是本地内存缓存,memcache可以做成分布式缓存
5.选框架的时候需要选择能提供局部缓存的框架
6.静态化内容能提高上百倍的吞吐率,但是由于带宽限制并不能达到理想状态,
更新策略:
1.在数据更新时重新生成静态内容;
2.定时重新生成静态化内容。
7.局部静态化,可以使用SSI技术实现各个局部页面的独立更新,可以大大减少重建网页时的开销和磁盘I/O开销.使用SSI需要将后缀名修改为.shtml。
一旦网页支持SSI,那么每次请求的时候服务器都会读取网页内容查找inclue标签,会消耗大量的CPU开销。对于不需要SSI的页面修改后缀为.htm即可
8.使用opcode(操作码)缓存,节省解释性语言的开销,避免重复编译,性能获得极大的提升
使用APC 打开opcode cache开关:
apc.cache_by_default =on
apc使用cache的方式:
$vaule =apc_fetch('value');//取出缓存
if($value!==false){//存在缓存
return $value;
}
$value = get_value();
apc_add('value',$value,$cache_time);//添加缓存
return $value;
查看apc缓存的信息:
print_r(apc_cache_info());
缓存了opcode的动态程序每次都要检查程序是否有所变化,APC可以跳过过期检查:
apc.stat =off (如果更新代码必须重启web服务器)
9.解释语言的扩展模块会带来效率上的影响,尽量减少不必要的扩展
10.使用xdebug追踪代码
11.使用浏览器缓存
Last-Modified:告诉浏览器过期时间(CTRL+F5会刷新,F5不会)
<?php
$modified_time =$_SERVER['HTTP_IF_MODIFIED_SINCE'];
if(strtotime($modified_time)+3600 >time()){
header("HTTP/1.1 304");
exit();
}
header("Last-modified: ".gmdate("D, d M Y H:i:s"). " GMT");
echo time();
?>
使用SSI的内容是不会附加Last-Modified标记的,需要修改Apache配置:
XBitHack full
修改权限:
chmod g+x index.shtml
Apache开启XBitHack之后使用SSI会降低1/3左右的吞吐率,使用lighttped不会出现这个问题
Expires:告诉浏览器该内容过期之前不需要询问服务器,直接使用本地缓存(CTRL+F5会刷新,F5也会刷新)
<IfModule mod_expires.c>
ExpiresActive on
ExpiresByType image/gif "access plus 1 month"
ExpiresByType text/css "now plus 1 day"
ExpiresDefault "now plus 1 day"
</IfModule>
由于服务器时间可能与浏览器时间冲突,可以使用Cache-Control,格式如下:
Cache-Control:max-age=<second>
在apache中配置如下:
ExpiresByType image/gif "access plus 1 hour" (使用access)
php中:
header("Cache-Control:max-age=3600");
2.apache 开启module_status 查看服务器状态:
加载module_status并在配置文件中添加:
<location /server-status> //命令名称,可以修改为xx-server-status
SetHandler server-status
Order Deny,Allow
Deny from all
Allow from all //允许的访问IP,在生产环境中需要修改为特定的IP地址
</location>
这样在浏览器中输入http://localhost/server-status 就可以看到状态了
3.apache压力测试:使用apache自带的ab命令 E:\wamp\bin\apache\apache2.2.8\bin> ab -V 可以看到ab工具的版本
使用命令 ab -n1000 -c10 http://localhost/index.php 可以进行压力测试
-n1000 表示总请求为1000
-c10 表示并发用户数为10
http://localhost/index.php 表示请求地址
命令结果:
server software 表示web服务器的软件名称
server Hostname 表示url中主机部分的名称
server port 表示web服务器监听的端口
document path 表示url中的绝对根路径
document length 表示http响应数据的正文长度
concurrency level 表示并发用户数
time taken for tests 表示请求被处理完成所花费的总时间
complete requests 表示总请求数
failed requests 表示失败的请求数
total transferred 表示所有请求的响应数据长总和
Html transferred 表示所有请求的响应数据中正文数据的总和
requests per second 吞吐率 每秒处理的请求次数
time per request 用户平均等待时间
time per request (across all concurrent requests) 服务器平均请求处理时间 time per request/concurrency level
transfer rate 请求在单位时间内从服务器获取的数据长度 =total transferred/time taken for tests 用于计算最大请求时所需要的带宽
Percentage of the requests served within a certain time (ms) 描述每个请求处理时间的分布情况
4.缓存的几种方式,以测试结果显示吞吐率:
smarty cache: 173
APC cache: 473
XCache cache: 462
memcache cache: 388
其中smarty是页面缓存,apc和xcache是本地内存缓存,memcache可以做成分布式缓存
5.选框架的时候需要选择能提供局部缓存的框架
6.静态化内容能提高上百倍的吞吐率,但是由于带宽限制并不能达到理想状态,
更新策略:
1.在数据更新时重新生成静态内容;
2.定时重新生成静态化内容。
7.局部静态化,可以使用SSI技术实现各个局部页面的独立更新,可以大大减少重建网页时的开销和磁盘I/O开销.使用SSI需要将后缀名修改为.shtml。
一旦网页支持SSI,那么每次请求的时候服务器都会读取网页内容查找inclue标签,会消耗大量的CPU开销。对于不需要SSI的页面修改后缀为.htm即可
8.使用opcode(操作码)缓存,节省解释性语言的开销,避免重复编译,性能获得极大的提升
使用APC 打开opcode cache开关:
apc.cache_by_default =on
apc使用cache的方式:
$vaule =apc_fetch('value');//取出缓存
if($value!==false){//存在缓存
return $value;
}
$value = get_value();
apc_add('value',$value,$cache_time);//添加缓存
return $value;
查看apc缓存的信息:
print_r(apc_cache_info());
缓存了opcode的动态程序每次都要检查程序是否有所变化,APC可以跳过过期检查:
apc.stat =off (如果更新代码必须重启web服务器)
9.解释语言的扩展模块会带来效率上的影响,尽量减少不必要的扩展
10.使用xdebug追踪代码
11.使用浏览器缓存
Last-Modified:告诉浏览器过期时间(CTRL+F5会刷新,F5不会)
<?php
$modified_time =$_SERVER['HTTP_IF_MODIFIED_SINCE'];
if(strtotime($modified_time)+3600 >time()){
header("HTTP/1.1 304");
exit();
}
header("Last-modified: ".gmdate("D, d M Y H:i:s"). " GMT");
echo time();
?>
使用SSI的内容是不会附加Last-Modified标记的,需要修改Apache配置:
XBitHack full
修改权限:
chmod g+x index.shtml
Apache开启XBitHack之后使用SSI会降低1/3左右的吞吐率,使用lighttped不会出现这个问题
Expires:告诉浏览器该内容过期之前不需要询问服务器,直接使用本地缓存(CTRL+F5会刷新,F5也会刷新)
<IfModule mod_expires.c>
ExpiresActive on
ExpiresByType image/gif "access plus 1 month"
ExpiresByType text/css "now plus 1 day"
ExpiresDefault "now plus 1 day"
</IfModule>
由于服务器时间可能与浏览器时间冲突,可以使用Cache-Control,格式如下:
Cache-Control:max-age=<second>
在apache中配置如下:
ExpiresByType image/gif "access plus 1 hour" (使用access)
php中:
header("Cache-Control:max-age=3600");