Menu Close

Enabling “HTTP Keep Alive” For Faster Page Speed

Keep Alive

[vc_row][vc_column][vc_custom_heading text=”Optimize Your Website: Enable Keep Alive” font_container=”tag:h2|text_align:left|color:%2399ccff” use_theme_fonts=”yes”][vc_column_text]Let’s begin by understanding what actually keep alive means.

Whenever there is a request for a file done by the browser from a server, one by one downloading of file takes place, i.e. after every single file download there is a break in connection which again opens to download the next file. So, the number of processes increases, which finally delays the loading of the website.

So, to resolve this issue the basic idea is to establish such a connection which ensures that all downloading of all the required files from same connection without multiple make and break of the connections.

Here HTTP keep alive play a significant role, as it enables loading of all the files in a single request via same open connection, this cuts off the continuous connecting and disconnecting time and thus leads to much faster loading of the content.[/vc_column_text][/vc_column][/vc_row][vc_row][vc_column][vc_custom_heading text=”How to check Keep Alive status” font_container=”tag:h2|text_align:left|color:%2399ccff” use_theme_fonts=”yes”][vc_column_text]Most of the online tools read the HTTP Header of your URL and tell whether keep-alive connections are enabled by detecting the keep-alive configurations listed in the header response.

Here are some of the tools that can be used to check the Keep-Alive status:

  1. Recently we used Giftofspeed tool for checking the Keep-Alive.
  2. Online tools like GTmetrix notify whether keep alive is active or not
  3. Other tools like varvy also notify if keep alive is in off mode.

[/vc_column_text][vc_custom_heading text=”General Terms Related to Keep-Alive to be Kept in Mind” font_container=”tag:h2|text_align:left|color:%2399ccff” use_theme_fonts=”yes”][/vc_column][/vc_row][vc_row][vc_column width=”1/2″][vc_column_text]

  • KeepAlive: Switches KeepAlive on or off. Use “KeepAlive on” to turn it on and “KeepAlive off” to turn it off.
  • MaxKeepAliveRequests: The maximum number of requests a single persistent connection will service. A number ranging between 50 and 75 would be enough.
  • KeepAliveTimeout: This determines that how long should the server wait for new requests from connected clients. The default is 15 seconds which is way too high. Set it something between 1 to 5 seconds to avoid having processes that are wasting RAM while waiting for requests.

[/vc_column_text][/vc_column][vc_column width=”1/2″][vc_single_image image=”8829″ img_size=”full” alignment=”center” onclick=”link_image”][/vc_column][/vc_row][vc_row][vc_column width=”2/3″][vc_custom_heading text=”Ways to Enable Keep Alive” font_container=”tag:h2|text_align:left|color:%2399ccff” use_theme_fonts=”yes”][vc_custom_heading text=”Code in .htaccess file” font_container=”tag:h3|text_align:left|color:%2399cc00″ use_theme_fonts=”yes”][vc_column_text]

<ifModule mod_headers.c>
Header set Connection keep-alive
</ifModule>

Add this code in your .htaccess file and it will enable keep alive for the requests.[/vc_column_text][/vc_column][vc_column width=”1/3″][/vc_column][/vc_row][vc_row][vc_column width=”3/4″][vc_custom_heading text=”In Apache server using config file” font_container=”tag:h3|text_align:left|color:%2399cc00″ use_theme_fonts=”yes”][vc_column_text]

# KeepAlive On for more than one request per connection. 
#Set to "Off" to deactivate (for new connection for every request).

KeepAlive On
# MaxKeepAliveRequests: The maximum number of requests to allow
# During a persistent connection, set MaxKeepAliveRequests to 0 to allow an unlimited amount.
# You can keep its number high to attain maximum performance.

MaxKeepAliveRequests 100

# KeepAliveTimeout: Number of seconds to wait for the next request from the
# same client on the same connection.

KeepAliveTimeout 100

[/vc_column_text][vc_custom_heading text=”For Nginx Server” font_container=”tag:h3|text_align:left|color:%2399cc00″ use_theme_fonts=”yes”][/vc_column][vc_column width=”1/4″][/vc_column][/vc_row][vc_row][vc_column width=”1/2″][vc_column_text]For Keep Alive

The number of connections to an upstream server that remain open for each worker process. There is no default value for this.

Default: keepalive_disable msie6;
Syntax: keepalive_disable none | browser …;[/vc_column_text][/vc_column][vc_column width=”1/2″][vc_column_text]For Keep Alive Timeout

How long an idle keepalive connection remains open.

Default: keepalive_timeout 75s;
Syntax: keepalive_timeout timeout [header_timeout];[/vc_column_text][/vc_column][/vc_row][vc_row][vc_column][vc_column_text]For Keep Alive Number Of Request per connection

It is a number of requests a client can make over a single keepalive connection. The default value is 100, but a much higher value can be especially useful for sending a large number of requests from a single client.

Default: keepalive_requests 100;
Syntax: keepalive_requests number;

[/vc_column_text][/vc_column][/vc_row][vc_row][vc_column][vc_custom_heading text=”How It works” font_container=”tag:h2|text_align:left|color:%2399ccff” use_theme_fonts=”yes”][vc_column_text]

The module of Keep-alives was added to HTTP, mainly to significantly reduce the overhead of rapidly creating & closing socket connections for each new request in same session.

Let’s assume that when a page is requested, 5-7 files are needed to get loaded before page actually shows up.

[/vc_column_text][vc_custom_heading text=”When Keep Alive in not active” font_container=”tag:h3|text_align:left|color:%2399cc00″ use_theme_fonts=”yes”][vc_column_text css=”.vc_custom_1512630059140{margin-top: -10px !important;}”]After page is requested all the elements that are needed to show the page start loading one after the one. If keep Alive is not active a new request is created for every single element to load. After every element get loaded, there is a break in connection and for further request by the browser server says No. So, there is a delay as new connection is to be established for every element to download.[/vc_column_text][vc_custom_heading text=”When Keep Alive is active” font_container=”tag:h3|text_align:left|color:%2399cc00″ use_theme_fonts=”yes”][vc_column_text css=”.vc_custom_1512630096973{margin-top: -10px !important;}”]If Keep Alive is active all the elements needed gets downloaded in a single, go via single connection.[/vc_column_text][vc_column_text css=”.vc_custom_1512630171150{margin-top: -10px !important;}”]Mostly by default keep alive is active but if not, you can activate it with the above discussed methods. But even after following the above instructions if keep alive is still not activated then you need to contact your hosting company as they sometimes don’t keep it in the on mode from their side. You can request them to turn it on. Mostly this case appears when the hosting is shared.[/vc_column_text][/vc_column][/vc_row][vc_row content_layout=”grid” options_bg=”default” video_webm=”” video_mp4=”” video_ogv=”” mute=”muted” gmap_lat=”” gmap_long=”” gmap_marker=”” section_id=”” css=”.vc_custom_1493968482886{margin-top: 20px !important;border-top-width: 1px !important;border-right-width: 1px !important;border-bottom-width: 1px !important;border-left-width: 1px !important;background-color: #f4f4f4 !important;border-left-color: #78c9eb !important;border-left-style: solid !important;border-right-color: #78c9eb !important;border-right-style: solid !important;border-top-color: #78c9eb !important;border-top-style: solid !important;border-bottom-color: #78c9eb !important;border-bottom-style: solid !important;}”][vc_column ps_animation=”noAnimation” ps_animation_delay=”” align_text=”text-left” inner_columns=”” css=”.vc_custom_1489489075999{margin-top: 10px !important;}”][vc_row_inner][vc_column_inner width=”1/4″][vc_single_image image=”7190″][/vc_column_inner][vc_column_inner width=”3/4″][vc_column_text css=”.vc_custom_1512633146837{padding-top: 20px !important;}”]Activating keep-alive enables us to use one established TCP/IP connection to fetch and retrieve multiple web files (all the files your web pages load) at once. So, there will be no need of establishing a new connection for every single file. This helps in speeding up the process of retrieving web files since it makes sure that one persistent TCP/IP connection is used instead of establishing multiple connections. This in turn results in faster page load times.[/vc_column_text][/vc_column_inner][/vc_row_inner][/vc_column][/vc_row]

1 Comment

Leave a Reply

Your email address will not be published. Required fields are marked *