This howto will explain you how you can use your Aloha LoadBalancer to implement HTTP Keepalive and save resources on your server at the same time.
What is HTTP KeepAlive?
In early version of HTTP protocol, clients used to send request over a new TCP connection to the server, getting content from the server through this connection and finally close it.
This method works well when web pages have a few objects.
More objects means more time to wait for each TCP connection setup and close.
HTTP 1.0 introduced the header Connection: Keepalive.
Clients and servers sent each other this header in order to tell the other side to keep the connection opened.
By default, there was no keepalive.
HTTP 1.1 considers every connection to be kept alive.
If one doesn’t want the connection to stay opened, the client or the server has to send the header: Connection: Close.
By using HTTP Keepalive, you’re going to reduce the web pages load time.
On the other hand, too many TCP connections maintained opened on an Apache server can make it consumes too much memory and CPU.
Using HAProxy to implement HTTP Keepalive
You can use HAProxy to add HTTP keepalive on the client side while not doing it on the server side.
The purpose is to deliver the objects quickly to the client without the overhead of TCP handcheck latency and to release memory and CPU on the server side by releasing TCP connection.
Note: Since HAProxy and the server are on the same LAN, the overhead of latency is negligible.
You can enable HTTP Keepalive on the client side by enabling option http-server-close
frontend public bind :80 option http-server-close default_backend apache backend apache option http-server-close server srv 127.0.0.1:8080
PS: Indeed it works for other HTTP server software like IIS, Tomcat, etc….