Search code examples
cnetwork-programmingselectfile-descriptor

can starvation happen due to select serving few fd while other fd starve?


Here is the scenario, one server handling multiple clients using select() few of the fds are very active(there are very much data coming on few) while other are normal active. Then will other fds starve, as select will be busy serving very active fds ?


Solution

  • can starvation happen due to select serving few fd while other fd starve?

    No, select() reports on all ready file descriptors (from the specified interest sets) at each return. It is the caller's responsibility to service them all to avoid starvation, and that is facilitated by select() -- the program can avoid both (i) blocking trying to read or write file descriptors that are unready and (ii) wasting time on non-blocking I/O requests that are unproductive. Ordinarily, the program would service all ready file descriptors before select()ing again. Details vary.

    From comments:

    What I meant was say fd x, has lots of data coming to read while other fds not getting enough chance to read data.

    It is to a large extent within the control of the program that is multiplexing I/O with the help of select() to ensure that all clients are serviced. There is a variety of ways it can approach that problem, and facilitating that is the point of using select() in the first place.

    Nevertheless, every machine has limits on its I/O and processing capabilities. Even with effective use of select(), it is possible for a program to be overwhelmed with more data and processing requests than it can keep up with. In that case, which streams it fails to service in a timely manner is largely a matter of the program's implementation details and the relevant communication patterns. It is not necessarily lower-volume streams.