I am using Apache Jmeter for testing our application but suddenly most of the errors that Jmeter displayed was
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.
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.
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.
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 ).
With Java 6:
final Closeable closeable = whatever(); // or Socket, or InputStream, or...
try {
doSomethingWith(closeable);
} finally {
closeable.close();
}
With 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
; and Closeable
extends AutoCloseable
.
NOTE 2: if Java 6 and you can afford Guava 14+, consider using Closer
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.