HTTP CONNETCT_TIMEOUT和 SO_TIMEOUT区别

HTTP Client 的CONNETCT_TIMEOUT和 SO_TIMEOUT区别

我们的web应用,依赖于底层的服务。通过http协议通信,当底层服务宕机之后。用户的请求量还是很大,http client 超时了,因为每个请求一个线程,会导致resin的线程用完,即使底层服务恢复,resin依然不能恢复。所以调整http Client 参数 so_timeout和connection_timeout, 把connection_timeout 设置为1000,so_timeout仍然保持5000不变。单位是毫秒。

关于HTTPCONNETCT_TIMEOUT和 SO_TIMEOUT区别如下:

·        CoreConnectionPNames.SO_TIMEOUT='http.socket.timeout':  definesthe socket timeout (SO_TIMEOUT) in milliseconds, which is thetimeout for waiting for data or, put differently, a maximum period inactivitybetween two consecutive data packets). A timeout value of zero is interpretedas an infinite timeout. This parameter expects a value of typejava.lang.Integer.If this parameter is not set, read operations will not time out (infinitetimeout).

·        CoreConnectionPNames.TCP_NODELAY='http.tcp.nodelay':  determineswhether Nagle's algorithm is to be used. Nagle's algorithm tries to conservebandwidth by minimizing the number of segments that are sent. When applicationswish to decrease network latency and increase performance, they can disableNagle's algorithm (that is enableTCP_NODELAY. Data will be sentearlier, at the cost of an increase in bandwidth consumption. This parameterexpects a value of typejava.lang.Boolean. If this parameter isnot set, TCP_NODELAY will be enabled (no delay).

·        CoreConnectionPNames.SOCKET_BUFFER_SIZE='http.socket.buffer-size': determines the size of the internal socket buffer used to buffer data whilereceiving / transmitting HTTP messages. This parameter expects a value of typejava.lang.Integer.If this parameter is not set, HttpClient will allocate 8192 byte socketbuffers.

·        CoreConnectionPNames.SO_LINGER='http.socket.linger':  setsSO_LINGERwith the specified linger time in seconds. The maximum timeout value isplatform specific. Value 0 implies that the option is disabled. Value -1implies that the JRE default is used. The setting only affects the socket closeoperation. If this parameter is not set, the value -1 (JRE default) will beassumed.

·        CoreConnectionPNames.CONNECTION_TIMEOUT='http.connection.timeout': determines the timeout in milliseconds until a connection is established. Atimeout value of zero is interpreted as an infinite timeout. This parameterexpects a value of typejava.lang.Integer. If this parameter isnot set, connect operations will not time out (infinite timeout).

BSD connection timeout

  connect函数将激发TCP的三次握手过程,在连接建立成功或者出错时返回,出错可能是下列这种情况:
若TCP客户没有收到SYN分节的响应,则返回ETIMEOUT错误,,举例来说,调用connect函数时,BSD内核发送一个SYN,若无响应6s后再发送一个,若仍然无响应则等待24s后再发送一个,若等待了75s仍未响应则返回本错误。有些系统提供对超时值的管理性控制。

 

windows connection  timeout

In Windows the value is dynamic forestablished conections, though the default for initial connections is 72 

http://serverfault.com/questions/193160/which-is-the-default-tcp-connect-timeout-in-windows

 

但是经过我时间测试为21s左右,具体办法是telnet 一个存在的主机和不存在的端口。如果telent一个不存在的主机,那么直接返回主机不可到达。

 一篇好贴:http://topic.csdn.net/t/20020915/17/1025424.html

Linux connection timeout

好像没有发现connection timeout的设置,最后才发现是这一个参数:可以通过sysctl 命令显示。接近180s。

tcp_syn_retries

The maximum numberof times initial SYNs for an active TCP connection attempt will beretransmitted. This value should not be higher than 255. The default value is5, which corresponds to approximately 180 seconds.

 

具体的时间间隔:The intervals arecontrolled by values called rtoMin,rtoMax and rtoInitial where rto stands forRound Trip Timeout. Basically, it denotes the time it would take for a packetto do a round trip. So, if when TCP sends the first msg, it would wait forrtoInitial time. If it fails to get a response, it will double the rto (and addsome jitter value) and then try again. This will continue till maxRetries. Thecurrent rto value will never go past rtoMax.

 

参考:http://linux.about.com/od/commands/l/blcmdl7_tcp.htm

 

 

 

 

Java 调用

地址:http://www.javacoffeebreak.com/articles/network_timeouts/

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值