- 浏览: 127605 次
- 性别:
- 来自: 上海
-
文章分类
最新评论
转: http://hi.baidu.com/w_ge/blog/item/105877c6a361df1b9c163d21.html
大概原因是短时间内new socket操作很多,而socket.close()操作并不能立即释放绑定的端口,而是把端口设置为TIME_WAIT状态,过段时间(默认240s)才释放,(用netstat -na可以看到),最后系统资源耗尽(windows上是耗尽了pool of ephemeral ports ,这段区间在1024-5000之间; )
避免出现这一问题的方法有两个,一个是调高你的web服务器的最大连接线程数,调到1024,2048都还凑合,以resin为例,修改resin.conf中的thread-pool.thread_max,如果你采用apache连resin的架构,别忘了再调整apache;
另一个是修改运行web服务器的机器的操作系统网络配置,把time wait的时间调低一些,比如30s。
在red hat上,查看有关的选项,
[xxx@xxx~]$ /sbin/sysctl -a|grep net.ipv4.tcp_tw
net.ipv4.tcp_tw_reuse = 0
net.ipv4.tcp_tw_recycle = 0
[xxx@xxx~]$vi /etc/sysctl,修改
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
[xxx@xxx~]$sysctl -p,使内核参数生效
socket-faq中的这一段讲time_wait的,摘录如下:
2.7. Please explain the TIME_WAIT state.
Remember that TCP guarantees all data transmitted will be delivered,
if at all possible. When you close a socket, the server goes into a
TIME_WAIT state, just to be really really sure that all the data has
gone through. When a socket is closed, both sides agree by sending
messages to each other that they will send no more data. This, it
seemed to me was good enough, and after the handshaking is done, the
socket should be closed. The problem is two-fold. First, there is no
way to be sure that the last ack was communicated successfully.
Second, there may be "wandering duplicates" left on the net that must
be dealt with if they are delivered.
Andrew Gierth (andrew@erlenstar.demon.co.uk) helped to explain the
closing sequence in the following usenet posting:
Assume that a connection is in ESTABLISHED state, and the client is
about to do an orderly release. The client's sequence no. is Sc, and
the server's is Ss. Client Server
====== ======
ESTABLISHED ESTABLISHED
(client closes)
ESTABLISHED ESTABLISHED
------->>
FIN_WAIT_1
<<--------
FIN_WAIT_2 CLOSE_WAIT
<<-------- (server closes)
LAST_ACK
, ------->>
TIME_WAIT CLOSED
(2*msl elapses...)
CLOSED
Note: the +1 on the sequence numbers is because the FIN counts as one
byte of data. (The above diagram is equivalent to fig. 13 from RFC
793).
Now consider what happens if the last of those packets is dropped in
the network. The client has done with the connection; it has no more
data or control info to send, and never will have. But the server does
not know whether the client received all the data correctly; that's
what the last ACK segment is for. Now the server may or may not care
whether the client got the data, but that is not an issue for TCP; TCP
is a reliable rotocol, and must distinguish between an orderly
connection close where all data is transferred, and a connection abort
where data may or may not have been lost.
So, if that last packet is dropped, the server will retransmit it (it
is, after all, an unacknowledged segment) and will expect to see a
suitable ACK segment in reply. If the client went straight to CLOSED,
the only possible response to that retransmit would be a RST, which
would indicate to the server that data had been lost, when in fact it
had not been.
(Bear in mind that the server's FIN segment may, additionally, contain
data.)
DISCLAIMER: This is my interpretation of the RFCs (I have read all the
TCP-related ones I could find), but I have not attempted to examine
implementation source code or trace actual connections in order to
verify it. I am satisfied that the logic is correct, though.
More commentarty from Vic:
The second issue was addressed by Richard Stevens (rstevens@noao.edu,
author of "Unix Network Programming", see ``1.5 Where can I get source
code for the book [book title]?''). I have put together quotes from
some of his postings and email which explain this. I have brought
together paragraphs from different postings, and have made as few
changes as possible.
From Richard Stevens (rstevens@noao.edu):
If the duration of the TIME_WAIT state were just to handle TCP's full-
duplex close, then the time would be much smaller, and it would be
some function of the current RTO (retransmission timeout), not the MSL
(the packet lifetime).
A couple of points about the TIME_WAIT state.
o The end that sends the first FIN goes into the TIME_WAIT state,
because that is the end that sends the final ACK. If the other
end's FIN is lost, or if the final ACK is lost, having the end that
sends the first FIN maintain state about the connection guarantees
that it has enough information to retransmit the final ACK.
o Realize that TCP sequence numbers wrap around after 2**32 bytes
have been transferred. Assume a connection between A.1500 (host A,
port 1500) and B.2000. During the connection one segment is lost
and retransmitted. But the segment is not really lost, it is held
by some intermediate router and then re-injected into the network.
(This is called a "wandering duplicate".) But in the time between
the packet being lost & retransmitted, and then reappearing, the
connection is closed (without any problems) and then another
connection is established between the same host, same port (that
is, A.1500 and B.2000; this is called another "incarnation" of the
connection). But the sequence numbers chosen for the new
incarnation just happen to overlap with the sequence number of the
wandering duplicate that is about to reappear. (This is indeed
possible, given the way sequence numbers are chosen for TCP
connections.) Bingo, you are about to deliver the data from the
wandering duplicate (the previous incarnation of the connection) to
the new incarnation of the connection. To avoid this, you do not
allow the same incarnation of the connection to be reestablished
until the TIME_WAIT state terminates.
Even the TIME_WAIT state doesn't complete solve the second problem,
given what is called TIME_WAIT assassination. RFC 1337 has more
details.
o The reason that the duration of the TIME_WAIT state is 2*MSL is
that the maximum amount of time a packet can wander around a
network is assumed to be MSL seconds. The factor of 2 is for the
round-trip. The recommended value for MSL is 120 seconds, but
Berkeley-derived implementations normally use 30 seconds instead.
This means a TIME_WAIT delay between 1 and 4 minutes. Solaris 2.x
does indeed use the recommended MSL of 120 seconds.
A wandering duplicate is a packet that appeared to be lost and was
retransmitted. But it wasn't really lost ... some router had
problems, held on to the packet for a while (order of seconds, could
be a minute if the TTL is large enough) and then re-injects the packet
back into the network. But by the time it reappears, the application
that sent it originally has already retransmitted the data contained
in that packet.
Because of these potential problems with TIME_WAIT assassinations, one
should not avoid the TIME_WAIT state by setting the SO_LINGER option
to send an RST instead of the normal TCP connection termination
(FIN/ACK/FIN/ACK). The TIME_WAIT state is there for a reason; it's
your friend and it's there to help you :-)
I have a long discussion of just this topic in my just-released
"TCP/IP Illustrated, Volume 3". The TIME_WAIT state is indeed, one of
the most misunderstood features of TCP.
I'm currently rewriting "Unix Network Programming" (see ``1.5 Where
can I get source code for the book [book title]?''). and will include
lots more on this topic, as it is often confusing and misunderstood.
An additional note from Andrew:
Closing a socket: if SO_LINGER has not been called on a socket, then
close() is not supposed to discard data. This is true on SVR4.2 (and,
apparently, on all non-SVR4 systems) but apparently not on SVR4; the
use of either shutdown() or SO_LINGER seems to be required to
guarantee delivery of all data.
发表评论
-
(转)JDK工具(查看JVM参数、内存使用情况及分析等)
2018-12-25 15:50 372https://www.cnblogs.com/z ... -
[转]jstat查看jvm的GC情况
2018-12-25 15:38 590jstat 1. jstat -gc pid ... -
设置Core Dump 生产
2017-12-06 17:13 583步骤一:开启core dump文 ... -
转一个 jmap 的基本使用方法
2017-04-05 11:52 552原文:http://hbluojiahui.bl ... -
(转)JVM内存堆布局图解分析
2017-04-05 11:56 427转载原文出处:http://www.codeceo.com/ ... -
(转)系统吞吐量(TPS)、用户并发量、性能测试概念和公式
2017-03-27 11:19 471PS:下面是性能测试的主要概念和计算公式,记录下: 一.系 ... -
(转)Linux OOM Killer个人总结
2017-01-16 11:47 1186Linux下面有个特性叫OOM killer(Out Of ... -
(转)深入理解Major GC, Full GC, CMS
2016-11-02 11:27 521原文:http://blog.csdn.net/iter_ ... -
(转)OpenSSL 1.0.0生成p12、jks、crt等格式证书的命令个过程
2016-07-26 18:51 699OpenSSL 1.0.0生成p12、jks、crt等格式 ... -
(转)Java 内存区域和GC机制
2016-07-26 14:09 385录 Java垃圾回收概况 Java内存区域 Java ... -
Understanding CMS GC Logs
2016-07-26 11:06 553Understanding CMS GC Logs By ... -
(转)vmstat详解
2016-07-12 16:29 1207对于CPU的使用情况,可以通过vmstat命令查看: # ... -
(转)Java动态代理机制详解(JDK 和CGLIB,Javassist,ASM)
2016-07-08 17:56 854源地址:http://blog.csdn.net/lu ... -
linux下查看最占性能的JAVA进程
2016-03-08 11:58 653记录一下自己常用的linux系统命令,方便以后查阅,发觉记忆 ... -
linux 查看 CPU,内存,网络流量和磁盘 I/O
2015-10-27 14:10 1079使用vmstat命令来察看系统资源情况在命令行方式下,如何查看 ... -
(转,精)Java 多线程 并发编程
2015-10-10 19:50 819源地址:http://blog.csdn.n ... -
java虚拟机内存监控工具jps,jinfo,Jstack,jstat,jmap,jhat使用
2015-09-21 13:14 1231源地址:http://my.oschina. ... -
(转)Linux netstat 命令查看端口状态
2014-11-21 12:21 1333Netstat 命令用于显示各种网络相关信息,如网络连接, ... -
(转)JMM模型
2014-11-11 16:53 503源地址:http://blog.csdn.net/gt ... -
(转)《深入浅出 Java Concurrency》目录
2014-11-10 15:55 427原文地址:http://www.blogjava.net/x ...
相关推荐
【Java中的`java.net.BindException: Address already in use: JVM_Bind`异常】 在Java编程中,当你尝试启动一个服务器端应用,如Tomcat,或者任何需要监听特定端口的服务时,可能会遇到`java.net.BindException: ...
在myeclipse中将html文件改成jsp文件时myeclipse卡住;将之前的任务关掉;再打开时多次部署项目的时候报错
在使用Jmeter进行高并发测试时,可能会遇到"java.net.BindException: Address already in use: connect"的错误。这种错误通常是因为端口被之前的进程占用而未能及时释放,导致新的连接无法建立。此时,通过修改...
在Android开发过程中,网络通信是应用的重要组成部分,而使用UDP(User Datagram Protocol)进行数据传输时,可能会遇到`java.net.BindException: bind failed: EADDRINUSE`的问题。这个异常通常意味着应用程序尝试...
nested exception is: java.net.BindException: Address already in use: JVM_Bind 这里说的是1099端口被其它进程占用了. 二.解决办法 找出占用1099端口的进程,进入windows命令,查看什么进程占用了1099端口...
使用JMeter压测时,报java.net.bindexception:address already is use:connect异常,可执行本资源的.bat文件,修改系统注册表。
在进行Java网络编程时,一个常见的问题便是java.net.BindException,它通常发生于尝试绑定网络地址到一个已经被其他进程使用的端口时。这种异常可能会在开发Web应用、网络服务或任何需要监听网络端口的程序时遇到。...
1. **java.net.BindException: Address already in use: JVM_Bind** 这个异常表明尝试绑定的端口已被其他服务占用。解决方法是检查并更改端口号,选择一个未被使用的端口。使用`netstat -an`命令可以帮助识别哪些...
jemeter 的压测结果可以帮助开发者和测试人员快速地发现和修复软件中的问题,提高软件的可靠性和稳定性。 jemeter 的主要功能有: * 压力测试:jemeter 可以对服务器、网络或对象模拟巨大的负载,在不同压力类别下...
在开发基于Java Netty的应用程序时,可能会遇到`java.net.BindException: Address already in use: no further information`这类错误。本篇文章将详细解析这一异常的原因、可能的影响以及如何有效地解决该问题。 ##...
java.net.BindException: Address already in use 该异常发生在服务器端进行 new ServerSocket(port) 操作时,原因是因为与 port 相同的端口已经被占用,解决方法是找到一个空闲的端口。 java.net....
在Java中,当我们使用`ServerSocket`类创建服务器并指定一个端口时,如果该端口已经被另一个进程占用,`bind()`方法会抛出`BindException`,具体表现为"Address already in use"。在`java.net.ServerSocket`类的源码...
nested exception is: java.net.BindException: Address already in use: JVM_Bind 这提示是 1099 端口被占用了。这是因为 Tomcat 服务器需要使用 1099 端口来启动,但是这个端口已经被其他应用程序占用了。 解决...
vhost WARN 200 - _defaultVHost_Bind failed, try again ([any]:1935): java.net.BindException: Address already in use ``` **原因分析:** 该错误通常发生在同一台服务器上有多个WowzaMediaServer实例同时运行...
它能够深入扫描系统,找出那些隐藏的、不易被发现的软件残留,确保在卸载后系统保持整洁,避免因残留文件占用磁盘空间,甚至可能导致冲突或系统不稳定的问题。 "Uninstall Tool汉化绿色版_3987.com"是这个压缩包内...
java.net.BindException: Address already in use: JVM_Bind 当尝试通过`new ServerSocket(port)`创建一个服务器套接字,并指定端口号`port`(该值应在0到65536之间)时,如果出现此异常,表明所指定的端口已被...
Reason: java.io.IOException: Transport Connector could not be registered in JMX: Failed to bind to server socket: tcp://0.0.0.0:61616 due to java.net.BindException: Address already in use: JVM_Bind”...
端口冲突java.net.BindException: Address already in use: JVM_Bind java.lang.ClassNotFoundException: org.apache.juli.logging.LogFactory deploy(部署)项目。点击 deploy 按钮,在弹出的Project Deployments...