HAproxy current session is zero

cookieshaproxysticky-sessions

I have some problems on sticky sessions with HAproxy.

Haproxy counts every request as a new session.
I have a Java servlet that creates the cookie JSESSIONID.

If I refresh that page 5 times. The servlet count it as 1 session and 5 request from that sessionid.
But the HAproxy stats page shows it as 5 different sessions.
And 0 current sessions.
Haproxy prefixes the cookie correct, cookie: "JSESSIONID=test1~3fjp6734ys78grhk50ler16r" and is persistent.
I hit the same server every time.

This is my config file:

global
    daemon
    maxconn 256

defaults
    mode http
    timeout connect 5000ms
    timeout client 50000ms
    timeout server 50000ms

frontend http-in
    bind *:3333
    acl Testrule path -m beg /test
    use_backend Test if Testrule


backend Test
    option httpchk GET /test
    cookie JSESSIONID prefix
    appsession JSESSIONID len 52 timeout 20m prefix
    server test2 vm-stapp-146:9003 check cookie test2
    server test1 vm-stapp-145:9003 check cookie test1


listen stats *:3334
    mode http
    stats enable
    stats uri /proxy-stats
    stats admin if TRUE

Why do the stats page show every request as a new session? And it always shows 0 current sessions.

Thanks.

Best Answer

HAProxy session count refers to tcpip sessions not browser sessions. The count is 0 because at the time you asked for stats there were none in progress. That is quite typical for a non-busy loadbalancer.

If your requests from the same session are hitting the same backend server it sounds like sticky sessions are working.