What
is I/O multiplexing?
The capacity to tell the kernel that we
want to be notified if one or more I/O conditions are ready (e.g. input is
ready to be read, or the buffer is capable of taking more output) Provided by
select and poll functions.
Why
Multiplexing?
When an application needs to handle
multiple I/O descriptors at the same time
E.g. file and socket descriptors, multiple
socket descriptors
Scenarios for I/O multiplexing in C/S
–
I/O
multiplexing: to be notified, by kernel, if one or more I/O conditions are
ready.
–
A client
handles multiple descriptors, or sockets
–
A server
handles both a listening socket and its connected sockets
–
A server
handles both TCP and UDP
–
A server
handles multiple services and protocols
–
It is
possible, but rare, for a client to handle multiple sockets at the same time.
I/O Models
•
There are
five I/O models under Unix
–
Blocking
I/O
–
Nonblocking
I/O
–
I/O
multiplexing (select and poll)
–
Signal
driven I/O (SIGIO)
–
Asynchronous
I/O
•
Two
distinct phases for an input operation
–
Waiting
for the data to be ready
–
Copying
the data from the kernel to the process
•
Definition
of “data being ready”
–
For UDP,
an entire datagram has been received
–
For TCP,
data received passed the low-water mark
Blocking I/O
•
Process is
put to sleep if blocked
Non
Blcoking IO
•
When an
I/O cannot be completed, the process is not put to sleep, but returns with an
error (EWOULDBLOCK) and Waste of CPU time.
I/O Multiplexing
•
Use select or poll to report if some descriptor is readable or writable. select may be blocked if no
descriptor is readable or writable.
•
Signal driven I/O:
If a descriptor is ready, notify the process with the SIGIO signal. Non
blocked in wait but blocked in copy
(signaled when I/O can be initiated)
Asynchronous I/O
The process initiates an I/O operation. When it is complete, the process is notified.
Comparison of I/O models:
No comments:
Post a Comment