1.http long-Connection related knowledge
HTTP long connections are not unfamiliar to us, but long connections are not always closed. The following points need to be noted for HTTP long connections:
Keepalive_timeout refers to the time when the Web server has sent the last response message, and closes the connection if it has not received the next request on the connection for the specified period of keepalive_timeout.
The HTTP long connection Keepalive_time and the keepalive_timeout of the TCP connection are different.
HTTP keep-alive is not the same as TCP keep-alive. The HTTP keep-alive is designed to allow TCP to live longer to transmit multiple HTTP on the same connection, increasing the efficiency of the socket. TCP Keep-alive is a fresh-keeping mechanism for TCP to detect TCP connection condition. TCP keep-alive freshness Timer, supports three system kernel configuration parameters:
echo 1800 >/proc/sys/net/ipv4/tcp_keepalive_timeecho >/proc/sys/net/ipv4/tcp_keepalive_intvlecho 5 >/ Proc/sys/net/ipv4/tcp_keepalive_probes
KeepAlive is a TCP freshness timer, when a TCP connection is established on both ends of the network, idle idle (without any traffic between the two sides) Tcp_keepalive_time, the server kernel will attempt to send a detection packet to the client to determine the TCP connection status ( It is possible that the client crashes, the app is forcibly closed, the host is unreachable, and so on). If you do not receive an answer (ACK packet), you will try to send the detection packet again after TCP_KEEPALIVE_INTVL, until you receive an ACK to the other side, if you have not received the other side of the ACK, will try to tcp_keepalive_probes times, Each time interval is 15s, 30s, 45s, 60s, 75s, respectively. If you try to tcp_keepalive_probes and you still do not receive an ACK packet from the other, the TCP connection is discarded. The default idle time for TCP connections is 2 hours and is generally set to 30 minutes enough.
3. In addition to memory-related tcpkeepalive settings, there are 3 corresponding parameters for each TCP connection, which can be set for a separate socket via the setsockopt system call:
TCPKEEPCNT: Overwrite tcpkeepaliveprobestcpkeepidle: Overwrite TCPKEEPALIVETIMETCPKEEPINTVL: Overwrite TCPKEEPALIVE_INTVL
2. Common Java Web container http long connection settings
Tomcat
<connector port= "protocol=" http/1.1 "connectiontimeout=" 60000 "keepalivetimeout=" 15000 "/>
2.nginx
Nginx uses the instruction Keepalive_timeout [TIME] to set the value of the HTTP long connection keepalive_timeout, which can be set in three places, HTTP context, server context, location context.
3.apache
KeepAlive on
KeepAliveTimeout 15
This article is from the "Java Small Novices" blog, be sure to keep this source http://leokongwq.blog.51cto.com/1310215/1702675
Common Java Web container http long connection timeout settings