HAProxy community

How to maintain my persistence connection between my server and clent


Hi Team,

I am running a test for 20 users from the testing tool.
so the request flow is like this

LoadGenerator ----> haproxy(1.8) ------> tomcat.

Here is the configuration of haproxy

log /dev/log local0
log /dev/log local1 notice
chroot /var/lib/haproxy
stats timeout 30s
user haproxy
group haproxy

log global
mode http
option httplog
option dontlognull
option http-keep-alive
timeout connect 5000
timeout client 50000
timeout server 50000
timeout http-keep-alive 600000
max-keep-alive-queue 20
maxconn 40

frontend http_front
bind *:80
stats uri /haproxy?stats
default_backend http_back

backend http_back
balance roundrobin
http-reuse safe
server demo01 x.x.x.x:8080 check

Now what i want is create a persistence connection between haproxy and tomcat.
The thing i am observing on my tomcat server is the socket with ESTABLISHED connection(request comming from haproxy to tomcat).
Now the problem is i see the foreign host port keeps on changing even though the haproxy documentation says, it uses by default keep-alive setting.

If my understanding is correct then when you use persistence connection then the client making request to server with different port won’t change. If yes how can i solve this issue. If not please put a light on this.

Sourav Suman


Persistence means that the same users will hit the same backend server on subsequent transactions, avoiding application problems when the backend servers do not share the client session data with each other.

You did not configure haproxy to use persistent connections, but you also have just a single backend server, so it doesn’t really matter here anyway.

You are talking about ESTABLISHED sockets and changing port numbers though, so I think you are talking about stuffing all those 20 clients into a single TCP session between the haproxy and your server. That would be connection multiplexing and haproxy does not support this (yet).


Hi Team,

Thanks for the reply.

The test is running for 20 users for 10 minute duration. So the load generator is making every time new request to the haproxy server and further tomcat. So we are in stateless state. Right? So their is not a scenario of same users. Multiple users are making request.

Right now for new request new socket is being created and destroying the previous socket connection.
So, my question is multiple request being served by same socket. Kind of reusing the socket. How can this be achieved?

Any configuration changes would be helpful.


Please read the documentation about http-reuse:


I think you’d want either aggressive or always mode.


Thank for the reply @lukastribus

i am using http-reuse with safe mode. I tried with always mode and it was not working.
Will let you know the effects for aggressive mode.

Sourav Suman