您的位置:首页 > 运维架构 > Nginx

Nginx静态资源性能测试

2016-12-26 17:54 330 查看
基本配置

硬件 1核cpu 1g内存

tomcat1 端口8080

tomcat2 端口1314

Nginx 1.10.2

Nginx配置如下:

我启用了压缩传输,还有负载,还有nginx的缓存(把静态内容放到nginx的内存里)
#user  nobody;
worker_processes  1;

events {
worker_connections  1024;
}

http {
#扩展名与文件类型映射表
include mime.types;
default_type  application/octet-stream;

sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;

#gzip 压缩传输
gzip on;
gzip_min_length 1k;  #最小1K
gzip_buffers 16 64K;
gzip_http_version 1.1;
gzip_comp_level 6;
gzip_types text/plain application/x-javascript text/css application/xml application/javascript;
gzip_vary on;

proxy_cache_key '$host:$server_port$request_uri';
proxy_temp_file_write_size 64k;
proxy_temp_path /dev/shm/JieLiERP/proxy_temp_path; #这个位置 就在内存里
proxy_cache_path /dev/shm/JieLiERP/proxy_cache_path levels=1:2 keys_zone=cache_one:200m inactive=5d max_size=1g;
proxy_ignore_headers X-Accel-Expires Expires Cache-Control Set-Cookie;

#配置代理参数
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 10m;
client_body_buffer_size 128k;
proxy_connect_timeout 65;
proxy_send_timeout 65;
proxy_read_timeout 65;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;

#静态服务器组
upstream  static.com {
server 127.0.0.1:4808;
}
#动态服务器组
upstream  dymic2.com {
server 127.0.0.1:8080;
server 127.0.0.1:1314;
}

server{
listen 80;
server_name www.xdloveglt.cn;

location ~ (\.jsp)|(\.do)$ {
proxy_pass http://dymic2.com; }

location ~ (\.html)|(\.jpg)|(\.jpeg)|(\.png)|(\.js)|(\.css)$ {
proxy_cache cache_one;
proxy_cache_valid 200 304 302 5d;
proxy_cache_valid any 5d;
proxy_cache_key '$host:$server_port$request_uri';
add_header X-Cache '$upstream_cache_status from $host';

proxy_pass http://static.com; expires 30d; #缓存30天
}
location  / {  #servlet或者别的没有后缀名的web款姐请求 也OK
proxy_pass http://dymic2.com; }
}

server{
listen 4808;
server_name www.xdloveglt.cn;

location / {
root /usr/local/tomcat7_forZW/webapps;
}

location ~ (\.html)|(\.jpg)|(\.jpeg)|(\.png)|(\.js)|(\.css)$ {
root /usr/local/tomcat7_forZW/webapps;
}
}

}


我直接访问
http://www.xdloveglt.cn/PathTest/js/jquery-1.11.3.min.js
就等于通过nginx了

如果是:
http://www.xdloveglt.cn:1314/PathTest/js/jquery-1.11.3.min.js http://www.xdloveglt.cn:8080/PathTest/js/jquery-1.11.3.min.js
那就是直接去tomcat了#

使用JMeter去测试一下
线程数是5,Tamp-Up Period是10s,循环次数是3

先是直接访问tomcat



访问Nginx



平均速度能提升10%左右

感觉提升并不是很大,我猜测,应该是我的服务器配置太低了,否则调大nginx的works数量,应该是能更大的提升它处理静态资源的速度

参考资料
http://www.cnblogs.com/wunaozai/p/5001742.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Nginx Tomcat JMeter