• Home
  • pcDuino
  • WiKi
  • Store
  • Distributors
  • Home
  • pcDuino
  • WiKi
  • Store
  • Distributors
HomepcDuinoLinux ApplicationsLoad effect comparison test of nginx and HAProxy o ...
Previous Next

Load effect comparison test of nginx and HAProxy on pcduino

Posted by: Alvin Jin , January 17, 2014

[vc_row][vc_column width=”1/1″][vc_column_text]Original: http://www.simonzhang.net/?p=2105[/vc_column_text][/vc_column][/vc_row][vc_row][vc_column width=”1/1″][vc_tour][vc_tab title=”HAProxy” tab_id=”1389928016-1-95″][vc_column_text]Install HAProxy

Dowanload address:

http://www.haproxy.org/download/1.4/src/haproxy-1.4.24.tar.gz

Install
make TARGET=linux26 ARCH=arm PREFIX=/program/haproxy
make install PREFIX=/program/haproxy

Configured as follows:

global
        log 192.168.1.132   local0
        #log 127.0.0.1  local1 notice
        #log loghost    local0 info
        maxconn 4096
        chroot /program/haproxy
        uid 0                          #User's UID
        gid 0                         #User's group
        daemon
        nbproc 1
        pidfile /program/haproxy/run/haproxy.pid
        #debug
        #quiet

defaults
        log     global
        log     192.168.1.132       local3        #Log file output
        mode    http                            #Processing category
        option  httplog                        #Log category
        option  httpclose
        option  dontlognull
        option  forwardfor
        option  redispatch
        retries 2                      #set multiple concurrent processes to improve performance
        maxconn 2000
        balance roundrobin                     #Load balancing algorithm
        stats   uri     /haproxy-stats        #The haproxy monitor page address
        # Vist by http://localhost:1080/haproxy-stats 
        contimeout      5000
        clitimeout      50000
        srvtimeout      50000

listen  localhost 0.0.0.0:1080                   #Port and host name of the running
        mode    http
        option  httpchk GET /          
        server  s1 192.168.1.132:9900 weight 3 check
        server  s2 192.168.1.80:8880 weight 3 check

Simply test as follows:
Start Service:

# /program/haproxy/sbin/haproxy -f /program/haproxy/haproxy.cfg

Reboot Service:

# /program/haproxy/sbin/haproxy -f /program/haproxy/haproxy.cfg -st `cat /program/haproxy/logs/haproxy.pid`

Stop Service:

# killall haproxy

#./haproxy -h explanation
-v Shield Version
-vv Compile Options
-V Version
-d Reception, debug mode
-db Shielded background mode
-D Startup daemon mode
-q Quiet mode
-c Check Syntax of the configuration files
-s Display statistics
-l Display detailed statistics
-ds Do not use speculative epoll
-de Do not use epoll
-dp Do not use poll
-sf FINISH signal will be sent to pidlist in the process after the program starts.Put this parametric at the end of command line.

-st TERMINATE signal will be sent to pidlist in the process after the program starts.Put this parametric at the end of command line.[/vc_column_text][/vc_tab][vc_tab title=”Hginx” tab_id=”1389928016-2-58″][vc_column_text]Install nginx
Download address

http://nginx.org/download/nginx-1.5.6.tar.gz

Install pcre first.
ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.33.tar.gz
Then, configure, make, make install.

At the end, make a soft link.

ln -s /usr/local/lib/libpcre.so.1 /usr/lib/

Starting install nginx, compile the parameters as follows:
./configure –prefix=/program/nginx –user=root –group=root –with-pcre –with-select_module –with-poll_module –with-http_stub_status_module –with-http_ssl_module –with-http_realip_module –with-http_gzip_static_module
Configuration is as follows:

user  root root;
worker_processes 1;
pid        logs/nginx.pid;
events {
    use epoll;
    worker_connections  5120;
}

http {
    include       mime.types;
    default_type  application/octet-stream;
    server_tokens off;
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for" "$request_time" '
                      '"$upstream_cache_status"';
    access_log  logs/access.log  main ;
    sendfile        on;
    keepalive_timeout  120;
    tcp_nodelay on;
    tcp_nopush on;
    client_header_buffer_size 128k;
    large_client_header_buffers 4 64k;
    reset_timedout_connection on;
    proxy_ignore_client_abort on;
   ######################################
   upstream  deploy_tool {
            server 192.168.1.132:9900;
       }
   server {
        listen       80;
        server_name 192.168.1.132;
        location / {
        proxy_pass_header      Server;
        proxy_redirect          off;
        proxy_set_header        X-Real-IP $remote_addr;
        proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header        Host $http_host;
        client_max_body_size   150m;
        proxy_connect_timeout  2000;
        proxy_send_timeout     2000;
        proxy_read_timeout     300;
        access_log off;
        proxy_pass              http://deploy_tool;
        }
        location /status {
             stub_status on;
             access_log  off;
             auth_basic_user_file    /lnmp/nginx/conf/htpasswd;
        }
     }
}

[/vc_column_text][/vc_tab][vc_tab title=”Summary” tab_id=”1389937217937-2-5″][vc_column_text]WEB project using my deployment tools, just connect to the home page. python use 2.7. Pressure tool is to write multi-threaded access to the page code with urllib2, concurrent 150. Test results are as follows:

HAProxy:
haproxystatus
ubuntu

nginx:
nginxstatus
ubuntu-nginx

Conclusion:
If you simply reverse connection, both have the same efficiency. HAProxy back end detection works well, for handling long connection is also very good. Can load mysql and other servers. nginx has a more powerful modules, such as cache, uwsgi together with other functions, nginx on a lot of convenience. WEB services uses nginx, others need loads can use HAProxy.[/vc_column_text][/vc_tab][/vc_tour][/vc_column][/vc_row]

Tags: Linux Applications

Share!
Tweet

Alvin Jin

About the author

Leave a Reply Cancel reply

You must be logged in to post a comment.

Category

  • Home
  • pcDuino
  • WiKi
  • Store
  • Distributors