nginx和apache關於負載均衡的比較

安裝apache2.2.17

gzip -d httpd--****.tar.gz
tar xvf httpd---***.tar
apache的安裝參數
./configure --with-included-apr --prefix=/home/lhh/apache2 --enable-so --enable-mods-shared=proxy

apache的prefork參數

<IfModule mpm_prefork_module>
    StartServers                 800
    MinSpareServers          800
    MaxSpareServers         1000
    ServerLimit                   1500
    MaxClients                    1500
    MaxRequestsPerChild   1000
</IfModule>

代理配置

ProxyPass /test balancer://mycluster stickysession=JSESSIONID|jsessionid scolonpathdelim=On
<Proxy balancer://mycluster>
        BalancerMember http://192.168.128.136:8180/test
        BalancerMember http://192.168.128.136:8280/test
        BalancerMember http://192.168.128.139:8180/test
</Proxy>

安裝nginx

./configure --prefix=/home/zxg/nginx --with-http_stub_status_module --with-http_ssl_module --with-cc-opt='-O2'

nginx的參數設置

use epoll;#僅用於linux

代理配置

    #add by zhao,xingguo
    upstream balance-tomcat  {
            server   192.168.128.136:8180;
            server   192.168.128.136:8280;
            server   192.168.128.139:8180;
    }
      server
      {
              listen  8085;
              server_name  192.168.128.139;

              location / {
                       proxy_redirect     off;
                       proxy_pass         http://balance-tomcat;
              }
      }

說明:

1.apache和nginx都作爲代理服務器,代理三臺相同的tomcat服務器

2.每臺tomcat服務器最大性能大概爲970request/s(代碼裏有Thread.sleep(200l);模擬業務)

3.四次測試結果如下:

apache和nginx的反向代理的比較,單位request/s
nginx  800--8000  3248  2409  2774  2135  2410 
apache 600--8000  2431  1645  2198  1288  1909

由此分析可以看出

1.nginx性能高,佔用cpu,內存少

2.apache的進程開的太多了,真煩。

3.高併發下nginx有完美的表現

4.apache有會話保持功能,儘管nginx有ip_hash但是不能代替session stick

5.儘量的用nginx和apache同時代理後端的服務器,

nginx對外部的webservice(性能高),apache對外部的web訪問(session stick)。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章