• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java.net.SocketException: Too many open files

 
Stephen Huey
Ranch Hand
Posts: 618
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm running some simple but fast-pounding test programs against our
Tomcat server from a machine on the same network, and we've been tuning
our database, etc, based on this. But right now, I'm seeing a new one
coming out of our Java code whenever we try to open a URL:


java.net.SocketException: Too many open files
at java.net.Socket.createImpl(Socket.java:331)
at java.net.Socket.connect(Socket.java:450)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.connect(DashoA12275)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.<init>(DashoA12275)
at com.sun.net.ssl.internal.ssl.SSLSocketFactoryImpl.createSocket(DashoA12275)
at sun.net.www.protocol.https.HttpsClient.doConnect(DashoA12275)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:402)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:618)
at sun.net.www.protocol.https.HttpsClient.<init>(DashoA12275)
at sun.net.www.protocol.https.HttpsClient.a(DashoA12275)
at sun.net.www.protocol.https.HttpsClient.a(DashoA12275)
at sun.net.www.protocol.https.HttpsClient.a(DashoA12275)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.plainConnect(DashoA12275)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(DashoA12275)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.connect(DashoA12275)



We're opening lots of these, and it appears we're opening more than a
maximum number of connections to the internet. Is there a way to bump
this up? Or maybe we're just pounding this harder than it will ever get
hit in the real world? I'm also seeing this as well:





SEVERE: Endpoint ServerSocket[addr=0.0.0.0/0.0.0.0,port=0,localport=80]
ignored exception: java.net.SocketException: Too many open files
java.net.SocketException: Too many open files
at java.net.PlainSocketImpl.socketAccept(Native Method)
at java.net.PlainSocketImpl.accept(PlainSocketImpl.java:353)
at java.net.ServerSocket.implAccept(ServerSocket.java:448)
at java.net.ServerSocket.accept(ServerSocket.java:419)
at org.apache.tomcat.util.net.DefaultServerSocketFactory.acceptSocket(DefaultServerSocketFactory.java:107)
at org.apache.tomcat.util.net.PoolTcpEndpoint.acceptSocket(PoolTcpEndpoint.java:356)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:529)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:619)
at java.lang.Thread.run(Thread.java:534)
Feb 1, 2005 4:53:08 PM org.apache.tomcat.util.net.PoolTcpEndpoint
closeServerSocket
SEVERE: Caught exception trying to unlock accept.
java.net.SocketException: Too many open files
at java.net.Socket.createImpl(Socket.java:331)
at java.net.Socket.<init>(Socket.java:304)
at java.net.Socket.<init>(Socket.java:124)
at org.apache.tomcat.util.net.PoolTcpEndpoint.closeServerSocket(PoolTcpEndpoint.java:326)
at org.apache.tomcat.util.net.PoolTcpEndpoint.acceptSocket(PoolTcpEndpoint.java:397)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:529)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:619)
at java.lang.Thread.run(Thread.java:534)
Feb 1, 2005 4:53:08 PM org.apache.tomcat.util.net.PoolTcpEndpoint
acceptSocket
WARNING: Reinitializing ServerSocket
 
Cal Watson
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Whats the OS? If its a *nix system you may have to bump up the number of allowed open file descriptors.
 
Stephen Huey
Ranch Hand
Posts: 618
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Linux - Red Hat 8...anyway, I understand you can play with that with ulimit...do you know much about that, though? It seems like we might already be at the max (1024?).
 
Cal Watson
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think there is a limit set in /etc/sysctl.conf called maxfiles.
I don't know to much about it because I have only encountered it once, but I think if you change this limit then run ulimit again it may work.
 
Stephen Huey
Ranch Hand
Posts: 618
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
FYI, on Linux, you can use the ulimit command to raise the number of open files that user can have. I did this a few days ago--I think

ulimit -n (number)

will do the trick. Type this to see what it's set at:

ulimit -a



G'night!
 
Paul Santa Maria
Ranch Hand
Posts: 236
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, the problem is probably *NOT* "open files" at all.

It sounds like you're running out of TCP/IP "ephemeral ports". If so, then you need to configure your OS to increase its "Max ports" ("ephemeral ports") range:

EXAMPLE: NT/Windows 2000/XP:
---------------------------
MaxUserPort registry entry
HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters
<= CREATE THE REGISTRY KEY "MaxUserPort" AND SET IT TO 10000 (OR HIGHER)

Instead of editing the registry, you'd use the "ndd" command on Solaris or HPUX.

Here's a reasonably good write-up:
http://members.cox.net/~ndav1/stratasphere/selecting_ports.doc

Hope that helps .. PSM
[ February 06, 2005: Message edited by: Paul Santa Maria ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic