Common Java Web container http long connection timeout settings

Source: Internet
Author: User
Tags ack java web

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:

    1. 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.

    2. 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

    1. 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

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.