Accept Error : Too many open files

Hi !

Running Solaris on a Sun Ultra we are getting an error from accept() stating that there are too many files open.
How can we avoid this, we have tried setting the number of file descriptors by using ulimit -n from 64 to 128, but this makes no difference.
checkinAsked:
Who is Participating?
 
FKernConnect With a Mentor Commented:
As you probably know, in Unix, sockets are actually special purpose files.  Some flavors of Unix have one or more kernel configurable parameters for the max number of files open for any single user and/or system wide at any given time.  Now since the accept takes the open request from the master (listen) socket and spawns a slave socket to handle the transaction, this is actually creating another open file.  There are a couple of things that you will want to look at:

Q)   Ref: (The application is a server which accepts
          connections to clients, a single client can
          open 30 connections which last for about 3
          seconds before they are closed.)
A)   You may only open 30 connections at a time, but
          they don't just go away when they are closed.
          They actually go into a close(time) wait state
          for a short while.  So when you do you next 30
          connections, the first 30 may not have timed
          out and been released to the OS yet.

1) Is the max open files configurable in your kernel?  By default this is set low (usually 64, they were not  thinking about sockets when they set this default... only actual user files).  If so, set it high (I suggest 1024), this will not degrade performance only give your application a little more leaway to do what it need to to get the job done.  If this is not configurable, then there is no limit (aix is like this).

...or...

Are you running as root or normal user?
Are you running as a daemon or normal application?

2) You may want to look at using shutdown() instead of close().  shutdown() seems to release the socket back to the OS quicker.

~Fred
0
 
TriskelionCommented:
How many files do you have open at a time?
Can you close unused files?

0
 
checkinAuthor Commented:
the application is a server which accepts connections to clients, a single client can open 30 connections which last for about 3 seconds before they are closed.
At the momment we can not get over 2 clients connecting simulateously without getting the error from accept of too many files open.  We are connecting using Unix Domain Sockets.
0
 
lcowanCommented:
Where is your accept()?  Are you forking for each call?  Have you tried making multiple processes that run fulltime,
one for each line in (or however many you want to handle at once), and using pipes to them for handling the transactions?  I guess the last question is really trying to find out if your process is complaining about too many open, or the OS is complaining.  If the latter, is there an OS install parameter you have set too small?  A sample of your handler which opens 30 redone to execute by itself, and hold them open until killed, could be run as many times as you need simultaneously to give you more info and tell you when you have the problem solved.
0
All Courses

From novice to tech pro — start learning today.