简体   繁体   English

连接到目标主机时捕获到I / O异常(java.net.SocketException):打开的文件太多

[英]I/O exception (java.net.SocketException) caught when connecting to the target host: Too many open files

I am using Apache Jmeter for testing our application but suddenly most of the errors that Jmeter displayed was 我正在使用Apache Jmeter测试我们的应用程序,但突然之间,Jmeter显示的大多数错误是

java.net.SocketException: Too many open files at java.net.Socket.createImpl(Socket.java:447) at java.net.Socket.getImpl(Socket.java:510) at java.net.Socket.setSoTimeout(Socket.java:1101)
at org.apache.http.conn.scheme.PlainSokcetFactory.connectSocket(PlainSocketFactory.java:126)

as I searched on the internet most of the comments about this error is because of the open limit of the machine, and then there was an answer that said Entities should be consume and when I tried on consuming the Entities the number of errors were reduced but not that many. 当我在互联网上搜索时,大多数关于此错误的评论都是由于机器的开放限制引起的,然后有一个回答说应使用实体,而当我尝试使用实体时,错误的数量减少了,但是没有那么多。 are there any other ways to handle this kind of error? 还有其他方法可以处理这种错误吗?

Default maximum number of open files and or sockets on Linux machines is 1024. Linux机器上的默认打开文件和/或套接字的最大数量为1024。

If your test exceeds it although shouldn't you need to inspect your test and detect and fix leaks. 如果您的测试超过了极限,尽管您不应该这样做,则需要检查测试并检测并修复泄漏。

If it's expected and you just increase limits on files/sockets it should be possible to increase them to reasonably higher value. 如果可以预期,并且您只是增加了文件/套接字的限制,则应该可以将它们增加到合理更高的值。 See ulimit command reference and information on limits.conf file.Alternatively you could try running JMeter as root user. ulimit的命令的参考和信息limits.conf file.Alternatively你可以尝试运行的JMeter作为root用户。

To get maximum number of allowed open files execute 要获取允许的最大打开文件数,请执行

ulimit -n 

in terminal 在终端

References: 参考文献:

Hope this helps 希望这可以帮助

The most likely cause is that you create a lot of Socket s but do not .close() them properly. 最可能的原因是您创建了许多Socket但是没有正确.close()它们。

You don't show code so no one can fix that for you; 您不会显示代码,因此没有人可以为您解决该问题。 anyway, there are classical idioms when dealing with Socket s, or indeed any class which implements Closeable ( which Socket does ). 无论如何,在处理Socket ,或者实际上是实现Closeable 任何类( Socket都在做 )时,都有经典的习惯用法。

With Java 6: 使用Java 6:

final Closeable closeable = whatever(); // or Socket, or InputStream, or...
try {
    doSomethingWith(closeable);
} finally {
    closeable.close();
}

With Java 7: 使用Java 7:

try (
    final Closeable closeable = whatever();
) {
    doSomethingWith(closeable);
}
// Automatically closed for you

NOTE: with Java 7, it is in fact anything which implements AutoCloseable ; 注意:在Java 7中,实际上任何实现AutoCloseable东西都可以; and Closeable extends AutoCloseable . Closeable扩展了AutoCloseable

NOTE 2: if Java 6 and you can afford Guava 14+, consider using Closer . 注意2:如果您使用Java 6并且可以买得起Guava 14+,请考虑使用Closer

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 打开的文件太多; 嵌套异常是 java.net.SocketException - Too many open files; nested exception is java.net.SocketException 异常:java.net.SocketException:打开文件过多 - Exception : java.net.SocketException: Too many open files Tomcat 7 maven 插件 - 处理请求时捕获的 I/O 异常 (java.net.SocketException):管道损坏 - Tomcat 7 maven plugin - I/O exception (java.net.SocketException) caught when processing request: Broken pipe 处理请求时捕获到 I/O 异常 (java.net.SocketException) - Getting I/O exception (java.net.SocketException) caught when processing request java.net.SocketException:打开文件过多 - java.net.SocketException: Too many open files java.net.SocketException: 打开的文件太多 - java.net.SocketException: Too many open files Jboss - java.net.SocketException:打开的文件太多 - Jboss - java.net.SocketException: Too many open files 初始化错误:java.net.SocketException:打开文件过多 - init error: java.net.SocketException: Too many open files Solr-java.net.SocketException:打开的文件太多 - Solr - java.net.SocketException: Too many open files Tomcat7 maven 插件 - 处理请求时捕获 I/O 异常 (java.net.SocketException):管道损坏 - Tomcat7 maven plugin - I/O exception (java.net.SocketException) caught when processing request: Broken pipe
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM