1 / 11

4061 Session 24 (4/12)

4061 Session 24 (4/12). Today. Finish up File Locking Select and Poll Asynchronous I/O. Today’s Objectives. Write single-threaded code that monitors multiple file descriptors concurrently or asynchronously. Admin. Readings: Today we’re going backwards: see Robbins 8.8 and 4.4-4.5.

randy
Download Presentation

4061 Session 24 (4/12)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 4061 Session 24 (4/12)

  2. Today • Finish up File Locking • Select and Poll • Asynchronous I/O

  3. Today’s Objectives • Write single-threaded code that monitors multiple file descriptors concurrently or asynchronously

  4. Admin • Readings: • Today we’re going backwards: see Robbins 8.8 and 4.4-4.5

  5. Reading Multiple Sources • The problem: what if we want to read from more than one FD at once? • FTP Client • Read input from terminal • Read input from network • Which one is ready? • Multiple threads? Multiple Processes? • Two more options that we’ll talk about today • Non-blocking and asynchronous I/O • Select and Poll

  6. Non-Blocking I/O • Issue a read/write call, but don’t block if the fd isn’t ready • Keep retrying (polling) the fds • Specify O_NONBLOCK flag when you call open() • Then, if you make a read/write call that would block, it instead immediately returns with errno EAGAIN

  7. Asynchronous I/O • Robbins 8.8 • One solution to the multiple I/O problem is to queue up a number of I/O requests, and have them fulfilled in the background

  8. Using Posix aio • Define an asynchronous I/O control block (aiocb) • open() a file • Register a signal handler • Call the aio_read or aio_write function to request asynchronous I/O • Continue execution until the signal arrives • After completion, call the aio_return function to retrieve completion value • close() the file

  9. Select and Poll • Robbins 4.4-4.5 • Two functions for multiplexing I/O • Simultaneously monitor multiple files • unblock when one of them is ready (for reading or for writing) • Similar in functionality and implementation, somewhat different in programmer’s interface • One is often a wrapper function for the other

  10. Select/Poll Interface • Select • Organized by event type • Poll • Organized by file

  11. Performance • Multiplexing I/O is central to the performance of networked servers • Thus, select and poll are seen as reliable standbys, but somewhat out of fashion • They don’t scale particularly well to very large n • Newer, faster, etc., include • /dev/poll • kqueue • epoll • real-time signals • Plenty of benchmarking studies out there, if you’re interested in server performance

More Related