increasing FD_SETSIZE under Sun

increasing FD_SETSIZE under Sun

Post by Rolan » Tue, 17 Nov 1998 04:00:00



Hi,

I am developing a server application running under Sun Unix and I would like
to override the default value of FD_SETSIZE (which is 1024) because I need
my process to support more than 1024 simultaneous TCP connections and I
would like to be able to call select() on the whole pile at once.

It is documented in both the Sun man pages and in the system include headers
that you can change FD_SETSIZE simply by #define'ing it before #include'ing
<sys/types.h>, thusly:

#define FD_SETSIZE    2048
#include <sys/types.h>

In practice, however, I am finding that I cannot set FD_SETSIZE to any value
larger than 1250.  If I do, calls to select() on a fd_set of that size fail
with errno 9 (EBADF).  The man pages for select( ) state that if select()
fails with EBADF it means that "One of the I/O file descriptor sets
specified an invalid I/O file descriptor."

I'm in big trouble if I can't support more than 1250 simultaneous TCP
connections...can anyone help with this?  How can I support larger values
for FD_SETSIZE in my server without having select() fail?

Thanks in advance for any help you can provide.

Sincerely,
Roland Vilett

 
 
 

increasing FD_SETSIZE under Sun

Post by Eric Levene » Wed, 18 Nov 1998 04:00:00


 > I am developing a server application running under Sun Unix and I would like
 > to override the default value of FD_SETSIZE (which is 1024) because I need
 > my process to support more than 1024 simultaneous TCP connections and I
 > would like to be able to call select() on the whole pile at once.

Try to use poll() in place of select().

--
--------------------------------------------------------------------
ric Lvnez              "Felix qui potuit rerum cognoscere causas"

(NeXTMail, MIME)                                   Georgica, II-489
--------------------------------------------------------------------
 "We are Microsoft. You will be assimilated. Resistance is futile."

 
 
 

increasing FD_SETSIZE under Sun

Post by Marc Slemk » Wed, 18 Nov 1998 04:00:00



Quote:>Hi,
>I am developing a server application running under Sun Unix and I would like
>to override the default value of FD_SETSIZE (which is 1024) because I need
>my process to support more than 1024 simultaneous TCP connections and I
>would like to be able to call select() on the whole pile at once.

Sorry, out of luck.  Have to use poll() or something.

Quote:>It is documented in both the Sun man pages and in the system include headers
>that you can change FD_SETSIZE simply by #define'ing it before #include'ing
><sys/types.h>, thusly:
>#define FD_SETSIZE    2048
>#include <sys/types.h>

Look at the select() man page more closely (2.6 only; if you are
on 2.5.1, tough luck the man page is wrong):

     The default value for FD_SETSIZE (currently 1024) is  larger
     than  the  default limit on the number of open files.  It is
     not possible to increase the size of the  fd_set  data  type
     when used with select().

This is yet another arbitrary Solaris limitation.

In your case, you may well be able to just use poll() instead, but
that really isn't any excuse to have such arbitrary restrictions
in Solaris.

 
 
 

increasing FD_SETSIZE under Sun

Post by Casper H.S. Dik - Network Security Engine » Wed, 18 Nov 1998 04:00:00


[[ PLEASE DON'T SEND ME EMAIL COPIES OF POSTINGS ]]


>Sorry, out of luck.  Have to use poll() or something.

Or Solaris 7.

Quote:>This is yet another arbitrary Solaris limitation.

There are really not all that many arbitrary limits.

It's  the people who designed select who are to blame; lifting the
restriction isn't as easy as recoding select.

Some parts of the libraries used global fd_set variables (rpc,
this was fixed in 2.6 which now uses poll)

Quote:>In your case, you may well be able to just use poll() instead, but
>that really isn't any excuse to have such arbitrary restrictions
>in Solaris.

Use poll, it is much better.  The restriction is also lifted in
later releases.

(Ok, so it was replaced with the next arbitrary restriction: you can't have
more than 64 K)

Casper
--
Expressed in this posting are my opinions.  They are in no way related
to opinions held by my employer, Sun Microsystems.
Statements on Sun products included here are not gospel and may
be fiction rather than truth.

 
 
 

increasing FD_SETSIZE under Sun

Post by Marc Slemk » Wed, 18 Nov 1998 04:00:00




>>Sorry, out of luck.  Have to use poll() or something.
>Or Solaris 7.

Impressive.

Quote:>>This is yet another arbitrary Solaris limitation.
>There are really not all that many arbitrary limits.

Mmm.  Maybe not, but that doesn't explain why I keep running into them
over and over.

Quote:>It's  the people who designed select who are to blame; lifting the
>restriction isn't as easy as recoding select.

Sure it is.  Fix the userland, fix the kernel, select() is fixed to
not have an arbitrary 1024 descriptor maximum that can't be increased.

Quote:>Some parts of the libraries used global fd_set variables (rpc,
>this was fixed in 2.6 which now uses poll)

That is a somewhat unrelated issue; a lot of the time, being
able to change your own select()s is enough and you can ensure that
there are enough low descriptors free that other libraries you may
use are happy.

Quote:>>In your case, you may well be able to just use poll() instead, but
>>that really isn't any excuse to have such arbitrary restrictions
>>in Solaris.
>Use poll, it is much better.  The restriction is also lifted in
>later releases.
>(Ok, so it was replaced with the next arbitrary restriction: you can't have
>more than 64 K)

So, where does the "Solaris 2.7 supports 15,000 times as many open
socket connections" on http://www.sun.com/solaris/cover/ come from?   <g>

(actually, I am curious about what that is supposed to be 15,000 times
as many as)

 
 
 

increasing FD_SETSIZE under Sun

Post by Rolan » Wed, 18 Nov 1998 04:00:00


Thanks to everyone for your suggestions!  I have now pretty much finished
re-coding my server to use poll() and it seems to work well.  What a relief!
Thought I was in big trouble for a moment there...

FYI I am on 2.5.1, and someone pointed out the man pages are wrong under
that release...well that at least partially explains my confusion. ;-)

Quote:>That is a somewhat unrelated issue; a lot of the time, being
>able to change your own select()s is enough and you can ensure that
>there are enough low descriptors free that other libraries you may
>use are happy.

Could someone post a brief example of how you might go about reserving
low-numbered descriptors for use by the libraries?  Another problem I am
having in my server is that with so many descriptors in use the stdio stream
functions (fopen(), etc.) often don't work, and I assume this is because of
the lack of available descriptors under 256 or something like that.

Thanks again,
Roland

 
 
 

increasing FD_SETSIZE under Sun

Post by Marc Slemk » Wed, 18 Nov 1998 04:00:00



Quote:>>That is a somewhat unrelated issue; a lot of the time, being
>>able to change your own select()s is enough and you can ensure that
>>there are enough low descriptors free that other libraries you may
>>use are happy.
>Could someone post a brief example of how you might go about reserving
>low-numbered descriptors for use by the libraries?  Another problem I am
>having in my server is that with so many descriptors in use the stdio stream
>functions (fopen(), etc.) often don't work, and I assume this is because of
>the lack of available descriptors under 256 or something like that.

Right, that is another arbitrary Solaris limitation, although at least
this one is founded in history and ABI compatibility, so it was just a
silly decision years ago.

stdio() can't deal with more than 256 descriptors in 2.6 and lower.
In Solaris 7, it can but only for 64-bit programs from what I know.

Check out what the HIGH_SLACK_LINE define in recent versions of Apache
does, in particular the ap_slack function.   It dups most descriptors
that it opens which are below a specified number so that they are now
above that number, then closes the low one.  That keeps the low space
free.

Note that Solaris 2.5.1 and below have another bug related to this that
is worked around by the WORKAROUND_SOLARIS_BUG define.  Essentially,
you have to do the dup on a socket after you listen() on it, otherwise
it will get confused.

 
 
 

increasing FD_SETSIZE under Sun

Post by Bas de Bakke » Thu, 19 Nov 1998 04:00:00


    Roland> Could someone post a brief example of how you might go
    Roland> about reserving low-numbered descriptors for use by the
    Roland> libraries?

You can move any file descriptor you create yourself (using socket(),
accept() etc.) to a high one using fcntl(F_DUPFD), e.g.

fd = accept(listenfd, NULL, NULL);
if (fd < 0) ...;
highfd = fcntl(fd, F_DUPFD, 256);
if (highfd < 0) ...;
close(fd);
/* Use highfd like you would have used fd */

    Roland> Another problem I am having in my server is
    Roland> that with so many descriptors in use the stdio stream
    Roland> functions (fopen(), etc.) often don't work, and I assume
    Roland> this is because of the lack of available descriptors under
    Roland> 256 or something like that.

Correct.

Regards,
Bas.

 
 
 

1. increasing FD_SETSIZE

Hi All .
---------

I need to redefine FD_SETSIZE on Solaris 2.5 to a size bigger than 1024
.
I tried :

#ifdef FD_SETSIZE
#undef  FD_SETSIZE
#define  FD_SETSIZE 2048
#endif

#include <sys/select>

But  when I try to use the function select() I get the error number :
Invalid argument .

If any one had that problem before and can help me I'll appreciate it .

Please replay to :

  vcard.vcf
< 1K Download

2. REQUEST FOR SUGGESTIONS (RFS) to stop linux getting locked up

3. Increasing the FD_SETSIZE

4. S3Virge + X11

5. How to increase FD_SETSIZE in FreeBSD 3.4

6. add new list_splice_init()

7. Increasing FD_SETSIZE in 2.2.2

8. slurp for Linux existing ?

9. Best way of increasing FD_SETSIZE for select()?

10. increasing FD_SETSIZE on apache

11. Sun dbx: How can I increase the size of the stack?

12. Shared Memory size increase: Suns

13. SUN O/S 4.1.1 Increasing # File Descriptors