Select() on more than 256 filedescriptors???

Select() on more than 256 filedescriptors???

Post by Daniel Walt » Sat, 04 Oct 1997 04:00:00



How can I setup FreeBSD 2.2.x to allow a single process to call
select() with more than 256 fd?  This is for a chat server and I need
to keep constant connections and select() for descriptors ready to
read/write.  In the past I have run Linux systems and have had to hack
the kernel to accomplish this.

This is my first FreeBSD system to setup and I find the performance as
a server to be somewhat better than Linux so far especially in the
area of disk access.  I looked through the FreeBSD kernel source
briefly but nothing jumped out and bit me.

Is there an easy way (or pre-existing way) to get select() to work
with more than 256 fd?

Also, are there any known drawbacks to running a server in this
manner?  Each connection is generally only transferring about 70 bytes
per second so the connections are pretty "light".  I guess I'm asking
if there are any lower level TCP/IP stack issues I should be concerned
with or keeping in mind.

Thanks!

Daniel Walton

 
 
 

Select() on more than 256 filedescriptors???

Post by Marc Slemk » Sat, 04 Oct 1997 04:00:00



Quote:>How can I setup FreeBSD 2.2.x to allow a single process to call
>select() with more than 256 fd?  This is for a chat server and I need
>to keep constant connections and select() for descriptors ready to
>read/write.  In the past I have run Linux systems and have had to hack
>the kernel to accomplish this.
>This is my first FreeBSD system to setup and I find the performance as
>a server to be somewhat better than Linux so far especially in the
>area of disk access.  I looked through the FreeBSD kernel source
>briefly but nothing jumped out and bit me.
>Is there an easy way (or pre-existing way) to get select() to work
>with more than 256 fd?

Recompile your program with FD_SETSIZE redefined to whatever you want.
It has to be redefined before including any header files.

The occasional thing (like some DNS resolver functions) will
cry if you try to use FDs above 256 with them.  This can be
resolved by either keeping some low FDs free (see the ap_slack
code in Apache 1.2.4 for an example of how) or recompiling libc
with an increased FD_SETSIZE.  This only applies, of course, if you
have to use those particular functions.

Quote:>Also, are there any known drawbacks to running a server in this
>manner?  Each connection is generally only transferring about 70 bytes
>per second so the connections are pretty "light".  I guess I'm asking
>if there are any lower level TCP/IP stack issues I should be concerned
>with or keeping in mind.

Compile your kernel right, high enough maxusers, enough mbufs.
Shouldn't be a big problem.  You may need to take care that you
don't let some sockets starve others if they have lots of traffic, but
that shouldn't be a problem with low traffic.

 
 
 

Select() on more than 256 filedescriptors???

Post by Gary Howlan » Sat, 04 Oct 1997 04:00:00



> How can I setup FreeBSD 2.2.x to allow a single process to call
> select() with more than 256 fd?  This is for a chat server and I need
> to keep constant connections and select() for descriptors ready to
> read/write.  In the past I have run Linux systems and have had to hack
> the kernel to accomplish this.

I did this once (well over a year ago), but soon changed it back since
it broke my window manager.  I think you will find many applications
that break if you go over 256, so think carefully before you make this
decision.

I can't remember exactly how I did it, but I think it was just a simple
change to the kernel config file.

Gary
--

Key fingerprint =  0C FB 60 61 4D 3B 24 7D  1C 89 1D BE 1F EE 09 06

 
 
 

Select() on more than 256 filedescriptors???

Post by Theo de Raad » Sat, 04 Oct 1997 04:00:00



> The occasional thing (like some DNS resolver functions) will
> cry if you try to use FDs above 256 with them.  This can be
> resolved by either keeping some low FDs free (see the ap_slack
> code in Apache 1.2.4 for an example of how) or recompiling libc
> with an increased FD_SETSIZE.  This only applies, of course, if you
> have to use those particular functions.

One would hope their vendor has fixed their libc code to work in the
presence of large file descriptor sets.

Another alternative is missed:

Don't use

        fd_set fdsr;

        FD_ZERO(&fdsr);

        FD_SET(fd, &fdsr);
        ...
        select(whatever, ...
        ...

Instead use

        fd_set *fdsrp;

        fdsrp = calloc(howmany(maxfd+1, NFDBITS, sizeof(fd_mask));

        FD_SET(fd, fdsrp);
        ...
        select(maxfd+1, ...
        ...
        free(fdsrp);

Suddenly you can have as large an fd_set as you like.  Of course this
assumes your kernel's select() can handle large nfds parameters.  Some
kernels can, some cannot.

By the way, it gets even worse if you use RPC code in the same
programs...  Fixing libc/rpc to handle > FD_SETSIZE descriptors is
(_was_) really hard.  When I say "RPC code", I mean something like YP.

--

www.OpenBSD.org -- We're fixing security problems so you can sleep at night.
(If it wasn't so fascinating I might get some sleep myself...)

 
 
 

Select() on more than 256 filedescriptors???

Post by Marc Slemk » Sat, 04 Oct 1997 04:00:00




>> The occasional thing (like some DNS resolver functions) will
>> cry if you try to use FDs above 256 with them.  This can be
>> resolved by either keeping some low FDs free (see the ap_slack
>> code in Apache 1.2.4 for an example of how) or recompiling libc
>> with an increased FD_SETSIZE.  This only applies, of course, if you
>> have to use those particular functions.
>One would hope their vendor has fixed their libc code to work in the
>presence of large file descriptor sets.

The problem is fixed in -current, just not in 2.2 last I checked.

Looking further, it appears like it was fixed in 2.2-stable in late June.
Must have missed it.  

 
 
 

1. Select() on filedescriptor directory

Hi,

The following must be possible but I just can't figure it out.

What I need is a routine that waits for files to appear in a
certain directory and if they do, transmit them to a remote system.

What I don't want is constantly having to scan the directory, this
eats CPU cycles. I would like to put a SIGIO in the FileDesciptor
for the directory but that is not possible on a non streaming FD.

Then I tried the following:
 - opening the directory (opendir())
 - makeing the FileDescriptor blocking (fcntl())
 - reading all the entries (readdir())
 - calling select() hoping it would block until another file is
   added to the directory.  This didn't work. The FileDescriptor
   just doesn't block.

Can someone give me a hint on how this can be solved??

Thanks!

///Greetings, Eelco

2. Please help...can't get SuSE 6.2 installed.

3. SPiDER 256-CACHE and X.

4. Need a keyboard for system to function

5. GUS + BusLogic BT-445S + STB Pegasus + DX2/66 + 256 kB cache = trouble

6. Linksys Etherfast on Linux RH7.0

7. NCSA httpd: group file lines only 256 chars?

8. DAT and 8mm: practical experiences

9. ET6000 graphic w/4mb + X (>256 cols?)

10. CL 5430 settings for >256 colors

11. more than 256 colors under linux ppc?

12. ? More than 256 colors in X ?

13. How can i increase STREAM_MAX > 256 on solaris 2.8