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 ?
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 ?
Share Improve this question asked 18 hours ago anandanand 2851 gold badge3 silver badges16 bronze badges 7 | Show 2 more comments1 Answer
Reset to default 1can 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.
select
you get a set of ready FDs. It is up to you which one you handle first. You can handle all available FDs before you callselect
again. – Gerhardh Commented 17 hours agoselect
function returns a list of all descriptors that are "ready" (e.g. for reading it means that aread
orrecv
call will not immediately block). There's no "starvation" from that point of view. The main problem is your applications processing of the "ready" descriptors, which will affect the polling interval (how oftenselect
is called). – Some programmer dude Commented 17 hours agoselect
. One client callsselect
once at a time. Do you mean totally different applications using completely unrelated file descriptors with different level of CPU utilization and amount of generated data? – Gerhardh Commented 14 hours agoselect()
does after determining which FDs are ready. Yes, it is possible for an application to be overwhelmed by more incoming data than it can handle in a timely manner, but that's not a situation caused byselect()
. Indeed,select()
, used appropriately, often improves an application's bandwidth vs the old-style approach of assigning a child process to each logical data stream. – John Bollinger Commented 12 hours ago