1.keep-alive
The Linux kernel is configured with a tcp_keepalive_time, a keepalive timer for TCP. When two connected processes on the network have no data to send to each other, TCP sends keepalive data at intervals to keep the connection, and the interval is tcp_keepalive_time set. The default is 7,200 seconds. When optimizing a Web server, you should set a smaller number of values, when the customer shuts down, the crash can be discovered faster, and there is no need to wait 2 hours before noticing, which can quickly clean up invalid connections.
HTTP keepalive: The default HTTP server closes this connection after an HTTP response is completed, setting this to survive for a period of time, continuing to accept requests from customers with this connection. This effectively reduces the system to establish a TCP connection overhead, but keep the connection will also occupy the system resources, use the time to weigh, the general small file more stations should be used, large file download is not necessary.
2.keep-alive reasons for the occurrence:
http connect , and the server sends back the response information while closing the connection. If the requested page contains other resource connections, the flsah
Support for KeepAlive is available in both the HTTP1.0 and HTTP1.1 agreements. Where HTTP1.0 need to add "connection:keep-alive" header in request to support, and HTTP1.1 default support.
The data interaction process supported by 1>http1.0 KeepAlive is as follows:
A) The client sends a request, where the HTTP version number of the request is 1.0. The same is included in the request a header: "Connection:keep-alive".
b) Web ServerreceivedRequestin theHTTPAgreement is1.0and "Connection:keep-alive"is considered to be a long connection request, which will beResponseof theHeaderalso added in the "Connection:keep-alive". The same is not to close the establishedTCPconnection.
c) ClientreceivedWeb Serverof theResponseincluded in theConnection:keep-alive", it was considered a long connection, notClose TCPconnection. and use theTCPConnect and ResendRequest. (Jump toa))
The data interaction process supported by 2>http1.1 KeepAlive is as follows:
A) The Client sends a requestwith the HTTP version number of the request being 1.1 .
b) Web ServerreceivedRequestin theHTTPAgreement is1.1is considered to be a long connection request, which will beResponseof theHeaderalso added in the "Connection:keep-alive". The same is not to close the establishedTCPconnection.
c) ClientreceivedWeb Serverof theResponseincluded in theConnection:keep-alive", it was considered a long connection, notClose TCPconnection. and use theTCPConnect and ResendRequest. (Jump toa))
keep-alive analysis:
Now some servers can set keep-alive Keep-alive Keep-alive quantity (the quantity is generally not very large, otherwise it will be very stressful for the server).
so we consider 3
1 when users browse a Web page, they refer to more than one javascript file, multiple files, multiple picture files, and these files are all in the same server.
2 , when a user browses a webpage, in addition to the Web page itself, it also refers to a JavaScript file, a picture file.
3 , the user browses a Dynamic Web page, the program generates the content instantly, and does not reference other content.
3 kinds of case,1 is best for opening keep-alive ,2 Casual,3 Best for closing keep-alive
Open itkeep-alive , it means that each time a user finishes all access, it will be closedTCPconnection, there is bound to be a server process that corresponds to that user and cannot process other users before closing the connection, assuming keep-alive the time-out isTenseconds, server processing per second -Independent user access, the systemApachethe total number of processes isTen *= -If a process takes up a4Mmemory, then the total will consume2Gmemory, so it can be seen that in this configuration, the memory is quite depleted, but the advantage is that the system only handles -TimesTCPhandshake and close operation.
If you closekeep-alive, if it's still every second -User Access, if the number of consecutive requests per user is3One, thenApachethe total number of processes is* 3 =per process, if you are still using a4Mmemory, then the total memory consumption is600M, this configuration can save a lot of memory, but the system handles MaxTimesTCPhandshake and closed operation, so it consumes moreCPUResources.
This article is from the "Output Diamond pattern" blog, so be sure to keep this source http://10541571.blog.51cto.com/10531571/1786699
Keep alive under the HTTP protocol