首页 > 其他 > 详细

Nginx做前端代理时缓存与否的性能差别

时间:2014-04-29 06:34:38      阅读:482      评论:0      收藏:0      [点我收藏+]

bubuko.com,布布扣

Nginx做前端代理,后端两台apache

upstream webservers {------------------定义在http段
        server 172.16.20.31 ;
        server 172.16.20.32 ;
}
proxy_cache_path /cache/webserver levels=1:2 keys_zone=web:100m max_size=1g inactive=12h;-----------------------------------------定义在http段
server {
        listen 80;
        server_name www.c.net;
add_header X-Cache $upstream_cache_status;
        location / {
                proxy_pass http://webservers;
                proxy_set_header X-Real-IP $remote_addr;
        }
}

未开启缓存的测试结果:

[root@node2 ~]# ab -c1000 -n10000 http://www.c.net/index.html
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 www.c.net (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:        nginx/1.4.7
Server Hostname:        www.c.net
Server Port:            80
Document Path:          /index.html
Document Length:        192 bytes
Concurrency Level:      1000
Time taken for tests:   6.589 seconds
Complete requests:      10000
Failed requests:        9218
   (Connect: 0, Receive: 0, Length: 9218, Exceptions: 0)
Write errors:           0
Non-2xx responses:      782
Total transferred:      2847868 bytes
HTML transferred:       352940 bytes
Requests per second:    1517.60 [#/sec] (mean)
Time per request:       658.933 [ms] (mean)
Time per request:       0.659 [ms] (mean, across all concurrent requests)
Transfer rate:          422.06 [Kbytes/sec] received
Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0  280 611.3     27    3066
Processing:     1  175 374.1     94    5439
Waiting:        1  168 374.3     89    5439
Total:          9  456 798.6    125    5834
Percentage of the requests served within a certain time (ms)
  50%    125
  66%    170
  75%    393
  80%    440
  90%   1141
  95%   2387
  98%   3137
  99%   3768
 100%   5834 (longest request)

开启nginx缓存

        upstream webservers {
                server 172.16.20.31 ;
                server 172.16.20.32 ;
#               server 127.0.0.1:80 backup;
        }
        proxy_cache_path /cache/webserver levels=1:2 keys_zone=web:100m max_size=1g inactive=12h;
        server {
                listen 80;
                server_name www.c.net;
        add_header X-Cache $upstream_cache_status;
                location / {
                        proxy_pass http://webservers;
                        proxy_set_header X-Real-IP $remote_addr;
                        proxy_cache web;
                        proxy_cache_valid 200 2h;
                        proxy_cache_valid 301 302 10m;
                        proxy_cache_valid any 1m;
                }
        }

Nginx开启缓存功能后的测试结果:

[root@node2 ~]# ab -c1000 -n10000 http://www.c.net/index.html
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 www.c.net (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:        nginx/1.4.7
Server Hostname:        www.c.net
Server Port:            80
Document Path:          /index.html
Document Length:        0 bytes
Concurrency Level:      1000
Time taken for tests:   2.944 seconds
Complete requests:      10000
Failed requests:        9589
   (Connect: 0, Receive: 0, Length: 9589, Exceptions: 0)
Write errors:           0
Total transferred:      2809577 bytes
HTML transferred:       210958 bytes
Requests per second:    3396.32 [#/sec] (mean)
Time per request:       294.436 [ms] (mean)
Time per request:       0.294 [ms] (mean, across all concurrent requests)
Transfer rate:          931.86 [Kbytes/sec] received
Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0   85 265.3      0    1005
Processing:     0   65 135.3     37    1475
Waiting:        0   60 135.6     36    1474
Total:         26  150 341.8     37    2478
Percentage of the requests served within a certain time (ms)
  50%     37
  66%     40
  75%     45
  80%    131
  90%    206
  95%   1040
  98%   1244
  99%   1653
 100%   2478 (longest request)


Nginx做前端代理时缓存与否的性能差别,布布扣,bubuko.com

Nginx做前端代理时缓存与否的性能差别

原文:http://xuqimin.blog.51cto.com/3832456/1403117

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!