Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / September 2006

Tip: Looking for answers? Try searching our database.

find max number of open file descriptors using java

Thread view: 
puzzlecracker - 07 Sep 2006 05:11 GMT
I am writing a server which can have maximum number of simultaneous
connection equal to the maximum number of open file descriptors. How
can it be enforced in java as well as best design strategy?

Thanks
Gordon Beaton - 07 Sep 2006 07:36 GMT
> I am writing a server which can have maximum number of simultaneous
> connection equal to the maximum number of open file descriptors. How
> can it be enforced in java as well as best design strategy?

The operating system will enforce the limit for you. Your application
will fail to open additional files, sockets etc after reaching the
descriptor limit.

/gordon

Signature

[ don't email me support questions or followups ]
g o r d o n  +  n e w s  @  b a l d e r 1 3 . s e

Chris Brat - 07 Sep 2006 08:37 GMT
Hi,

This just seems like a bad idea to me.

In practice if this single server actually holds your max number of
simultaneous connections then you wont be able to do anything else on
that OS. No other applications will be able to open any other
resources.

I'd rather impose a configurable maximum number of simultaneous
connections.

My 2c

Chris

> I am writing a server which can have maximum number of simultaneous
> connection equal to the maximum number of open file descriptors. How
> can it be enforced in java as well as best design strategy?
>
> Thanks
Gordon Beaton - 07 Sep 2006 08:59 GMT
> In practice if this single server actually holds your max number of
> simultaneous connections then you wont be able to do anything else
> on that OS. No other applications will be able to open any other
> resources.

On most platforms I know, you'll be stopped by a per-process limit
long before you reach any system wide limit.

/gordon

Signature

[ don't email me support questions or followups ]
g o r d o n  +  n e w s  @  b a l d e r 1 3 . s e

Chris Uppal - 07 Sep 2006 09:39 GMT
> On most platforms I know, you'll be stopped by a per-process limit
> long before you reach any system wide limit.

Not to mention that in most configurations of most systems, that limit is set
higher than a sensible architecture would attempt to use.

   -- chris
Chris Brat - 07 Sep 2006 11:15 GMT
> > On most platforms I know, you'll be stopped by a per-process limit
> > long before you reach any system wide limit.
[quoted text clipped - 3 lines]
>
>     -- chris

Hi,

Both good points.

Unfortunately I worked on an existing application that did run out of
file-handles and caused the environent to sieze.

To manage the problem the support team wrote a script to periodically
check the number of open filehandles and when a pre-defined limit was
reached the application would reboot, to prevent the environment
siezing.

I don't think the problem was ever actually resolved.

Regards,
Chris
puzzlecracker - 07 Sep 2006 13:30 GMT
> > > On most platforms I know, you'll be stopped by a per-process limit
> > > long before you reach any system wide limit.
[quoted text clipped - 20 lines]
> Regards,
> Chris
OK, is it possible in Java to find when max fd  when is being (or about
to be ) reached? how?  what is a good design for it?

thanks
Gordon Beaton - 07 Sep 2006 14:04 GMT
> OK, is it possible in Java to find when max fd when is being (or
> about to be ) reached? how? what is a good design for it?

There is no general way to know how many file descriptors you've got
open, except by keeping track of every Socket, ServerSocket, and
FileInputStream you open (and I've probably missed some), and knowing
when library methods open these things for you (as Runtime.exec()
does).

On Linux you can cheat a little by counting the files in
/proc/self/fd, and you can check the limit with "ulimit -n".

But this seems to like a lot of trouble, I don't see the point of
knowing that they will "soon" run out, because you'll get an exception
when you attempt to exceed the limit anyway (so why stop sooner).

What real problem are you trying to solve?

/gordon

Signature

[ don't email me support questions or followups ]
g o r d o n  +  n e w s  @  b a l d e r 1 3 . s e

Chris Uppal - 07 Sep 2006 14:54 GMT
> Unfortunately I worked on an existing application that did run out of
> file-handles and caused the environent to sieze.
[quoted text clipped - 3 lines]
> reached the application would reboot, to prevent the environment
> siezing.

Good sound support engineering ;-)

In fact, if you have a leak in code you can't get at, such as the OS or a
third-party library, then there may be nothing you can do except restart at
intervals.  I think it's a good idea for long-running processes to restart
themselves automatically from time to time -- just as a precaution.

   -- chris


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.