您的位置:首页 > 理论基础 > 计算机网络

HTTP CONNETCT_TIMEOUT和 SO_TIMEOUT区别

2016-07-29 00:00 260 查看

HTTPCONNETCT_TIMEOUT和SO_TIMEOUT区别

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

关于HTTPCONNETCT_TIMEOUT和SO_TIMEOUT区别如下:

·CoreConnectionPNames.SO_TIMEOUT='http.socket.timeout':definesthesockettimeout(SO_TIMEOUT)inmilliseconds,whichisthetimeoutforwaitingfordataor,putdifferently,amaximumperiodinactivitybetweentwoconsecutivedatapackets).Atimeoutvalueofzeroisinterpretedasaninfinitetimeout.Thisparameterexpectsavalueoftypejava.lang.Integer.Ifthisparameterisnotset,readoperationswillnottimeout(infinitetimeout).

·CoreConnectionPNames.TCP_NODELAY='http.tcp.nodelay':determineswhetherNagle'salgorithmistobeused.Nagle'salgorithmtriestoconservebandwidthbyminimizingthenumberofsegmentsthataresent.Whenapplicationswishtodecreasenetworklatencyandincreaseperformance,theycandisableNagle'salgorithm(thatisenableTCP_NODELAY.Datawillbesentearlier,atthecostofanincreaseinbandwidthconsumption.Thisparameterexpectsavalueoftypejava.lang.Boolean.Ifthisparameterisnotset,TCP_NODELAYwillbeenabled(nodelay).

·CoreConnectionPNames.SOCKET_BUFFER_SIZE='http.socket.buffer-size':determinesthesizeoftheinternalsocketbufferusedtobufferdatawhilereceiving/transmittingHTTPmessages.Thisparameterexpectsavalueoftypejava.lang.Integer.Ifthisparameterisnotset,HttpClientwillallocate8192bytesocketbuffers.

·CoreConnectionPNames.SO_LINGER='http.socket.linger':setsSO_LINGERwiththespecifiedlingertimeinseconds.Themaximumtimeoutvalueisplatformspecific.Value0impliesthattheoptionisdisabled.Value-1impliesthattheJREdefaultisused.Thesettingonlyaffectsthesocketcloseoperation.Ifthisparameterisnotset,thevalue-1(JREdefault)willbeassumed.

·CoreConnectionPNames.CONNECTION_TIMEOUT='http.connection.timeout':determinesthetimeoutinmillisecondsuntilaconnectionisestablished.Atimeoutvalueofzeroisinterpretedasaninfinitetimeout.Thisparameterexpectsavalueoftypejava.lang.Integer.Ifthisparameterisnotset,connectoperationswillnottimeout(infinitetimeout).

BSDconnectiontimeout

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

windowsconnectiontimeout

InWindowsthevalueisdynamicforestablishedconections,thoughthedefaultforinitialconnectionsis72

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

Linuxconnectiontimeout

好像没有发现connectiontimeout的设置,最后才发现是这一个参数:可以通过[code=plain]sysctl命令显示。接近180s。[/code]
tcp_syn_retries

ThemaximumnumberoftimesinitialSYNsforanactiveTCPconnectionattemptwillberetransmitted.Thisvalueshouldnotbehigherthan255.Thedefaultvalueis5,whichcorrespondstoapproximately180seconds.

具体的时间间隔:TheintervalsarecontrolledbyvaluescalledrtoMin,rtoMaxandrtoInitialwherertostandsforRoundTripTimeout.Basically,itdenotesthetimeitwouldtakeforapackettodoaroundtrip.So,ifwhenTCPsendsthefirstmsg,itwouldwaitforrtoInitialtime.Ifitfailstogetaresponse,itwilldoubletherto(andaddsomejittervalue)andthentryagain.ThiswillcontinuetillmaxRetries.ThecurrentrtovaluewillnevergopastrtoMax.


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

Java调用

地址:http://www.javacoffeebreak.com/articles/network_timeouts/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: