Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > find max number of open file descriptors using java

Reply
Thread Tools

find max number of open file descriptors using java

 
 
puzzlecracker
Guest
Posts: n/a
 
      09-07-2006
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

 
Reply With Quote
 
 
 
 
Gordon Beaton
Guest
Posts: n/a
 
      09-07-2006
On 6 Sep 2006 21:11:01 -0700, puzzlecracker wrote:
> 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

--
[ 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
 
Reply With Quote
 
 
 
 
Chris Brat
Guest
Posts: n/a
 
      09-07-2006
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


puzzlecracker wrote:
> 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


 
Reply With Quote
 
Gordon Beaton
Guest
Posts: n/a
 
      09-07-2006
On 7 Sep 2006 00:37:45 -0700, Chris Brat wrote:
> 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

--
[ 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
 
Reply With Quote
 
Chris Uppal
Guest
Posts: n/a
 
      09-07-2006
Gordon Beaton wrote:

> 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


 
Reply With Quote
 
Chris Brat
Guest
Posts: n/a
 
      09-07-2006

Chris Uppal wrote:
> Gordon Beaton wrote:
>
> > 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


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

 
Reply With Quote
 
puzzlecracker
Guest
Posts: n/a
 
      09-07-2006

Chris Brat wrote:
> Chris Uppal wrote:
> > Gordon Beaton wrote:
> >
> > > 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

>
> 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

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

 
Reply With Quote
 
Gordon Beaton
Guest
Posts: n/a
 
      09-07-2006
On 7 Sep 2006 05:30:28 -0700, puzzlecracker wrote:
> 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

--
[ 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
 
Reply With Quote
 
Chris Uppal
Guest
Posts: n/a
 
      09-07-2006
Chris Brat wrote:

> 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.


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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using multiple file descriptors for the same file DJ Dharme C++ 2 10-20-2008 12:06 PM
how can i find lingering file descriptors? Brad Volz Ruby 6 09-14-2008 04:22 PM
syncronizing between two file descriptors open on the same file JG C Programming 5 02-08-2005 01:25 PM
closing all open file descriptors Ara.T.Howard Ruby 3 09-15-2004 06:21 PM
how to see how many open file descriptors my program has? Rex Gustavus Adolphus Perl Misc 1 03-06-2004 11:46 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57