Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Possible to enable Keep-alive with a load balancer?

I'm trying to optimize my web application using Google's Page Speed API which has highlighted the absence of "Keep-alive" in my HTTP response headers as a major page speed weakness.

In talking with my back-end devs and sys admins, they've told me that using Keep-alive on the site is impossible because we use a load balancer.

I'm wondering, is this accurate? Are there load balancers that support Keep-alive?

It seems strange to me that the Page Speed API would complain about Keep-alive if it were impossible to use with load balancers because I would imagine a fair amount of applications and large sites use load balancers.

Thanks!

like image 311
Benjamin Knight Avatar asked Nov 21 '11 18:11

Benjamin Knight


People also ask

How do I enable Keep-Alive?

Apache. If you have access to your Apache configuration file ( httpd. conf ), you can turn on Keep-Alive there. To enable HTTP Keep-Alive , set to KeepAlive On or to disable it set to KeepAlive Off .

How do you enable the HTTP keep-alive option for your EC2 instances?

For backend connections, we recommend that you enable the HTTP keep-alive option for your EC2 instances. You can enable HTTP keep-alive in the web server settings for your EC2 instances. If you enable HTTP keep-alive, the load balancer can reuse backend connections until the keep-alive timeout expires.

Should I Enable Keep-Alive?

Enabling Keep-Alive is a great way to optimize your website as it helps improve speed and performance, ensuring faster load times and higher efficiency. By turning the Keep-Alive header on, the client and server can reuse a single TCP connection for a number of requests and responses.

Does HTTP 1.0 support Keep-Alive?

Keep-alive connections are enabled by default in HTTP/1.1 while not in HTTP/1.0.


1 Answers

I don't know what type of load-balancers do you have... but I don't think that it would prevent the use of keep-alive connections.

The load balancer will handle each incoming connection to one of the backend servers. Now for each object the browser needs to make a new connection just to fetch that object (for example all small images). Establishing and closing TCP connections takes some time. This is why the Google Page Speed suggests to have keep-alive turned on. Another option is put all your small images into one big image and use css sprites to display part of it on different places on your page.

But back to the load balancer. If you have network load balancer, it should work without any questions - it will just redirect incoming TCP connection to one of the backend servers. If you have HTTP load-balancer, it will accept the connection, read the request, send the request to backend server, wait for it to answer and send the answer back to the browser. If you enable keep-alive, the load balancer should forward the next request it receives over the same connection.

For dynamic pages you don't need keep-alive. Keep-alive is mainly useful for static content (js, images, css) as for each one html page you have usually more than 10 static objects. So I would suggest to continue serving html trough that load-balancer and serve static content over different hostname (static.example.com).

like image 85
Marki555 Avatar answered Oct 03 '22 14:10

Marki555