tcp连接的状态变迁以及如何调整tcp连接中处于time_wait的时间
一、状态变迁图

二、time_wait状态
针对time_wait和close_wait有个简单的描述帮助理解:
Due to the way TCP/IP works, connections can not be closed immediately. Packets may arrive out of order or be retransmitted after the connection has been closed. CLOSE_WAIT indicates that the remote endpoint (other side of the connection) has closed the connection. TIME_WAIT indicates that local endpoint (this side) has closed the connection. The connection is being kept around so that any delayed packets can be matched to the connection and handled appropriately. The connections will be removed when they time out within four minutes. See http://en.wikipedia.org/wiki/Transmission_Control_Protocol for more details.
发起socket主动关闭的一方 socket将进入TIME_WAIT状态,TIME_WAIT状态将持续2个MSL(Max Segment Lifetime),在Windows下默认为4分钟,即240秒,TIME_WAIT状态下的socket不能被回收使用. 具体现象是对于一个处理大量短连接的服务器,如果是由服务器主动关闭客户端的连接,将导致服务器端存在大量的处于TIME_WAIT状态的socket, 甚至比处于Established状态下的socket多的多,严重影响服务器的处理能力,甚至耗尽可用的socket,停止服务. TIME_WAIT是TCP协议用以保证被重新分配的socket不会受到之前残留的延迟重发报文影响的机制,是必要的逻辑保证.
三、windows下调整TIME_WAIT下等待的时间
On Windows platforms, the default timeout is 120 seconds, and the maximum number of ports is approximately 4,000
To avoid port exhaustion and support high connection rates, reduce the TIME_WAIT value and increase the port range.
Note: This problem does not usually appear on UNIX systems due to the higher default connection rate in those operating systems.
To set TcpTimedWaitDelay (TIME_WAIT):
Use the regedit command to access the
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\ Services\TCPIP\Parametersregistry subkey.Create a new
REG_DWORDvalue named TcpTimedWaitDelay.Set the value to 60.
Stop and restart the system.
To set MaxUserPort (ephemeral port range):
Use the
regeditcommand to access theHKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\ Services\TCPIP\Parametersregistry subkey.Create a new
REG_DWORDvalue named MaxUserPort.Set this value to 32768.
Stop and restart the system.
四、linux中进行时长调整
参考了:
http://blog.51cto.com/kerry/105233
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_fin_timeout = 30 然后执行 /sbin/sysctl -p 让参数生效。tcp连接的状态变迁以及如何调整tcp连接中处于time_wait的时间的更多相关文章
- 动手学习TCP:客户端状态变迁
上一篇文章中介绍了TCP连接的建立和终止. 通过实际操作了解到,在TCP协议工作过程中,客户端和服务端都会接收或者发送特定标志的TCP数据包,然后进入不同的状态. 也就是说,TCP协议就是一个包含多种 ...
- TCP建立连接和释放的过程,及TCP状态变迁图
一.TCP报文格式 下面是TCP报文格式图: 重要字段介绍: (1)序号:Seq序号,占32位,用来标识从TCP源端向目的端发送的字节流,发起方发送数据时对此进行标记. (2)确认序号:Ack序号,占 ...
- (转)TCP连接的11种状态变迁
自:http://blog.csdn.net/engrossment/article/details/8104482 http://blog.csdn.net/xiaofei0859/article/ ...
- TCP连接的状态与关闭方式及其对Server与Client的影响
TCP连接的状态与关闭方式及其对Server与Client的影响 1. TCP连接的状态 首先介绍一下TCP连接建立与关闭过程中的状态.TCP连接过程是状态的转换,促使状态发生转换的因素包括用户调用. ...
- TCP连接的状态与关闭方式,及其对Server与Client的影响
1. TCP连接的状态 首先介绍一下TCP连接建立与关闭过程中的状态.TCP连接过程是状态的转换,促使状态发生转换的因素包括用户调用.特定数据包以及超时等,具体状态如下所示: CLOSED:初始状态, ...
- TCP 连接中的TIME_WAIT
原文:http://blog.csdn.net/wangpengqi/article/details/17245349 这就有个细节,一次http请求,谁会先断开TCP连接?什么情况下客户端先断,什么 ...
- C#如何检测网络端口连接的状态
原文:C#如何检测网络端口连接的状态 C#如何检测/监控远程连接网络端口的情况(例如:3389端口是否处于监听状态,是否建立了连接等). using System; using System.Coll ...
- 谈谈TCP中的TIME_WAIT
所以,本文也来凑个热闹,来谈谈TIME_WAIT. 为什么要有TIME_WAIT? TIME_WAIT是TCP主动关闭连接一方的一个状态,TCP断开连接的时序图如下: 当主动断开连接的一方(Initi ...
- TCP协议中的TIME_WAIT详细说明
文章目录 4.3设置TIME_WAIT状态的目的 4.3.1 实现TCP全双工连接的关闭 4.3.2 使过时的重复报文段失效 4.3.3 TIME_WAIT状态的自结束 4.3.4 TIME_WAIT ...
随机推荐
- 配置Server.xml
Service下面的Connector, Engine, Executor. 组件的目录结构,配置文件,配置节点.
- jsp连接mysql----------第一篇技术类文章
今天做作业连了一天的mysql. 最后我痛定思痛,决定从0開始学习jsp.省的又面临不会的局面. 忙活了一晚上.最终把数据库连接上了,只是.好伤心啊,我连个数据库都这么墨迹. . . <%@ p ...
- Objc将数据写入iOS真机的plist文件里
大熊猫猪·侯佩原创或翻译作品.欢迎转载,转载请注明出处. 假设认为写的不好请多提意见,假设认为不错请多多支持点赞.谢谢! hopy ;) 怎样写入模拟器的博文在 这里 可是这对真机无论用,由于在真机环 ...
- Masonry插件:内容始终水平居中
跟随浏览器框架大小,主题内容居中 代码 <!DOCTYPE html> <html> <head> <title>masonry瀑布流插件</ti ...
- 获取 SharpSvn 执行 svn 操作的实时日志
1 获取 SharpSvn 操作日志的方式 之前一篇随笔(使用 SharpSvn 执行 svn 操作)讲到可以通过声称一个绑定到一个 SvnClient 对象的 SvnClientReport 对象. ...
- asp.net MVC中防止跨站请求攻击(CSRF)的ajax用法
参考: Preventing Cross-Site Request Forgery (CSRF) AttacksValidating .NET MVC 4 anti forgery tokens in ...
- storm学习之七-storm UI页面参数详解
http://lbxc.iteye.com/blog/1522318 --参考文章 http://blog.csdn.net/rong_89/article/details/39473917 --参考 ...
- C++输入cin,输出cout,换行endl,getline连续读取字符
简记:cin=键盘,cout=屏幕. >>和<<指向代表数据流动方向.<<是流插入运算符,右操作数(运算符右边的值)会被插入到输出流中. 首先要包含:#includ ...
- QT编译错误:cannot find file: *.pro
编译一个之前同事写的QT程序,结果出现了编译错误:cannot find file: *.pro 解决方法:将程序放在英文路径下 尽管出现一些红色的编译信息部门,但是最终还算是编译成功了~
- 处理执行sql语句
sqlplus / as sysdba @1.sqlsqlplus / as sysdba @2.sqlsqlplus / as sysdba @3.sql