Hi,
I try to setup a Active/Passive cluster via HAProxy. I setup a test
environment according to the blog (
http://blog.haproxy.com/2014/01/17/emulating-activepassing-application-clustering-with-haproxy/)
, but test result are different.
Environment: Local VM box
OS: Ubuntu 14.04.1 LTS x86_64
HAProxy: version 1.6.11 2016/12/25
Nodejs: v0.10.25
Configure file:
global
> log 127.0.0.1 local0
> stats socket /var/run/haproxy.sock mode 600 level admin
> stats timeout 2m
> chroot /var/lib/haproxy
> user haproxy
> group haproxy
> daemon
>
> defaults
> log global
> mode http
> option tcplog
> option dontlognull
> errorfile 400 /etc/haproxy/errors/400.http
> errorfile 403 /etc/haproxy/errors/403.http
> errorfile 408 /etc/haproxy/errors/408.http
> errorfile 500 /etc/haproxy/errors/500.http
> errorfile 502 /etc/haproxy/errors/502.http
> errorfile 503 /etc/haproxy/errors/503.http
> errorfile 504 /etc/haproxy/errors/504.http
> timeout connect 5000ms
> timeout client 50000ms
> timeout server 50000ms
>
> listen backend
> bind *:5555
> mode tcp
> stick-table type ip size 1
> stick on dst
> server server1 127.0.0.1:1234 check inter 1s
> server server2 127.0.0.1:9000 backup check inter 1s
>
> listen stats
> bind *:9999
> mode http
> log global
> maxconn 10
> stats enable
> stats hide-version
> stats refresh 30s
> stats show-node
> stats uri /haproxy?stats
>
Backend server:
var http = require('http');
>
> var PORT= process.argv[2] || 1234;
>
> function handleRequest(request, response){
> console.log(request.url);
> if(request.url == "/hello"){
> response.end('It Works!! Path Hit: ' + request.url);
> }else{
> response.statusCode = 404;
> response.end();
> }
> }
>
> var server = http.createServer(handleRequest);
>
> server.listen(PORT, function(){
> });
Test step:
1. start two nodejs process, p1 listen 1234, p2 listen 9000
2. test by curl, only p1 handle request, and stick-table info
#echo "show table backend" | socat /var/run/haproxy.sock stdio
> # table: backend, type: ip, size:1, used:1
> 0x1f1bd44: key=127.0.0.1 use=0 exp=0 server_id=1
3. stop p1, test by curl, p2 handle request, and stick-table info
# echo "show table backend" | socat /var/run/haproxy.sock stdio
> # table: backend, type: ip, size:1, used:1
> 0x1f1bd44: key=127.0.0.1 use=0 exp=0 server_id=2
4. start p1, test by curl, p2 handle request, stick-table doesn't change
5. But test concurrency scenario, both p1 and p2 handle the request
although stick-table show p2 should deal with all the request.
$ ab -n 100 -c 10 http://localhost:5555/hello
>
If I change the table size to 100, and retest, in step5 all request are
processed by p2.
I don't know how stick-table to deal with concurrency connection, anyone
can help to explain the stick-table working flow and why setting size to 1
cause p1 accept some request?
Thanks,
Linbo