Re: Timings for optimised poll(2) (fwd)

Darren Reed (darrenr@cyber.com.au)
Wed, 27 Aug 1997 23:33:05 +1000 (EST)


In some mail I received from Jim Nance, sie wrote
>
> Forwarded message:
>
> > Hm. Perhaps a simple and cheap alternative is to use find_first_bit on
> > each fd_set, then take the minimum index of the three, and start
> > normal scanning from there. Of course, it won't help in the case where
> > you are selecting on descriptors 100,200,300,400,500,600,700,800,900
> > or some other such sparse set.
>
> One thing I have been thinking about since this thread appeared is
> having the application rearange the contents of the pollfd[] array in
> response to the results of the last call to poll(). If you know some
> statistics about the application it might be possible get all the
> active connections moved to the front of the array, which would allow
> you to bail out of the loop early. Whether this would help you or not
> depends on your application though.

Another trick you can use is to keep track of the highest fd in use and
whenever a "middle" fd is free'd, use dup2 to move the highest fd into
the hole, close the highest fd and adjust your "highest" fd number.

Darren