0

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.

ofbje
  • 1
  • 1

2 Answers2

1

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.

JamesRyan
  • 8,166
  • 2
  • 25
  • 36
  • Thanks! But my problems occured when trying to drain a server. It should go from drain to maint after the sessions are done. How should this work? – ofbje Jul 21 '14 at 14:09
  • NOLB will not magically switch to MAINT, because HAproxy has no notion of whether there are still valid sessions on the draining backend. – Felix Frank Jul 22 '14 at 08:31
0

That stats column you want to look for when testing session persistence is lbtot, which increases whenever a client makes a request without a recognized session cookie.

Felix Frank
  • 3,093
  • 1
  • 16
  • 22