HTTP protocol keep-alive

Source: Internet
Author: User

What is Keep-alive? Overview

By default, HTTP links are usually closed after the request is complete. This means that the server closes the TCP link after the delivery of the response has been completed. To keep the link open to satisfy multiple requests, you can use the keep-alive header information.

How does HTTP work without keep-alive?
    • 1. The client needs to recreate a link and server interaction to receive a file.
    • 2. The client uses a new link to request an HTML file to the server, which is closed when the file is finished.
    • 3. The browser parses the HTML file and checks to see if additional files are needed to complete the page's presentation. (e.g. CSS files, JS files, pictures)
    • 4. After thorough analysis, the browser then re-creates the link to request each of these files.
We need keep-alive.

Creating multiple links can slow loading and also take advantage of more server resources. We can overcome this problem by enabling Keep-alive to pass these files through a single link, thus avoiding duplicate creation and closing of new connections. If Keep-alive is not enabled, the process of presenting a Web page can take a considerable amount of time.

How to turn on keep-alive

The keep-alive is enabled by explicitly declaring it in the HTTP header information. In the case of Apache Web server, if you have access to the Apache configuration file (httpd.conf), you can open keep-alive here. The configuration method is shown below.

3 properties that affect the Keep-alive feature. Keep-live

Use "KeepAlive on" to enable, use "KeepAlive off" to disable. The response header after opening is probably as follows:

http/1.1 OK
Connection:keep-alive
content-type:text/html; Charset=utf-8
Date:thu, 16:45:29 GMT
content-length:1845
keep-alive:timeout=10, max=20
server:apache/2.4.9 (Unix) php/5.6.2

Maxkeepaliverequests

Used to set the maximum number of keepalive links. The appropriate value depends on the actual situation.

KeepAliveTimeout

This setting prevents unused links from taking too long. This is actually the question of how long the link needs to keep. For example, setting 7-10 seconds is usually possible. In the case of high traffic, this value may have to be set a bit larger to ensure that there are no frequent TCP link restarts. If this value is set too small, then perhaps it is the purpose of keep-alive itself.

Benefits of Keep-alive
    • 1. Reduce CPU usage: Creating a new TCP link consumes some resources, such as CPU and memory usage. Keeping links alive for a long time avoids the frequent creation of new links, thus reducing resource usage.
    • 2. Page load speed: Using the same link to load multiple files can be a quick point for page loading.
    • 3.https:https is very resource intensive, so it is highly recommended to turn on HTTPS keep-alive and make some adjustments using HTTP/2 as much as possible.

If you are using http/1.1, which is implemented differently from the http/1.0 keek-live, the http/1.1 link is kept active by default, assuming that all links are persistent unless the response header contains: "Connection:close" header. However, if you do not send the "Connection:close" header does not mean that the link will persist forever, the link will still be closed.

HTTP protocol keep-alive

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.