In the last column, I talked about how to read and write from multiple file
descriptors seemingly simultaneously with the select() function call. Using multiplexed I/O
lets programs block while waiting for notification that some file descriptors are ready for reading
or writing.
In the last column, I talked about how to read and write from multiple file descriptors seemingly simultaneously with the select() function call. Using multiplexed I/O lets programs block while waiting for notification that some file descriptors are ready for reading or writing.
Using multiplexed I/O of this form is quite common. High-performance network servers — including mail, workgroup, and Web servers — all must handle multiple simultaneous connections, often thousands of connections. While select() looks like it would handle this kind of load just fine, it has a fatal flaw that limits its performance. Figure 1 shows the prototype of select().
Figure 1: A Prototype of the select() Function Call
Think about what happens when a program wants to use select() to block until either file descriptor 1000 or 1001 is ready to be read from. It will have to call select() with a numfd of 1002 and the appropriate value of readfds. Easy enough, right?
The Problem with select()
Now try to think about things from the kernel’s point of view. The kernel gets a request from a user-space program to monitor some file descriptors for reading. It knows that the file descriptors are smaller than 1002, but that’s all it knows. To figure out…
Please log in to view this content.
Not Yet a Member?
Register with LinuxMagazine.com and get free access to the entire archive, including: