Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

time-wait #160

Open
lovelmh13 opened this issue Jul 26, 2021 · 0 comments
Open

time-wait #160

lovelmh13 opened this issue Jul 26, 2021 · 0 comments

Comments

@lovelmh13
Copy link
Owner

什么是 TIME_WAIT

tcp 4次挥手时,最后主动发起关闭链接的一端( Client ),在最后等待 2 MSL 后关闭。

image

影响

在高并发短连接的TCP服务器上,当服务器处理完请求后立刻主动正常关闭连接。这个场景下会出现大量socket处于TIME_WAIT状态。

第一是内存资源占用,这个目前看来不是太严重,基本可以忽略。
第二是对端口资源的占用,一个 TCP 连接至少消耗一个本地端口。要知道,端口资源也是有限的,一般可以开启的端口为 32768~61000 ,也可以通过net.ipv4.ip_local_port_range指定,如果 TIME_WAIT 状态过多,会导致无法创建新连接。这个也是我们在一开始讲到的那个例子。

参考:

高并发下的TIME_WAIT

大量的 TCP 连接是 TIME_WAIT 状态,有什么影响?怎么处理?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant