Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linux and I/O completion ports?

Using winsock, you can configure sockets or seperate I/O operations to "overlap". This means that calls to perform I/O are returned immediately, while the actual operations are completed asynchronously by separate worker threads.

Winsock also provides "completion ports". From what I understand, a completion port acts as a multiplexer of handles (sockets). A handle can be demultiplexed if it isn't in the middle of an I/O operation, i.e. if all its I/O operations are completed.

So, on to my question... does linux support completion ports or even asynchronous I/O for sockets?

like image 412
someguy Avatar asked May 08 '10 15:05

someguy


People also ask

How do IO completion ports work?

I/O completion ports provide an efficient threading model for processing multiple asynchronous I/O requests on a multiprocessor system. When a process creates an I/O completion port, the system creates an associated queue object for threads whose sole purpose is to service these requests.

What is completion port thread?

A completion port thread will only be used briefly to mark the corresponding task in . NET as completed. If you start several FileStream instances in a loop, then the thread pool will create more IOCP threads to handle all the completing I/O request packets.

What is AIX IOCP?

Input/output completion port (IOCP) is an API for performing multiple simultaneous asynchronous input/output operations in Windows NT versions 3.5 and later, AIX and on Solaris 10 and later. An input/output completion port object is created and associated with a number of sockets or file handles.


2 Answers

If you're looking for something exactly like IOCP, you won't find it, because it doesn't exist.

Windows uses a notify on completion model (hence I/O Completion Ports). You start some operation asynchronously, and receive a notification when that operation has completed.

Linux applications (and most other Unix-alikes) generally use a notify on ready model. You receive a notification that the socket can be read from or written to without blocking. Then, you do the I/O operation, which will not block.

With this model, you don't need asynchronous I/O. The data is immediately copied into / out of the socket buffer.

The programming model for this is kind of tricky, which is why there are abstraction libraries like libevent. It provides a simpler programming model, and abstracts away the implementation differences between the supported operating systems.

There is a notify on ready model in Windows as well (select or WSAWaitForMultipleEvents), which you may have looked at before. It can't scale to large numbers of sockets, so it's not suitable for high-performance network applications.

Don't let that put you off - Windows and Linux are completely different operating systems. Something that doesn't scale well on one system may work very well on the other. This approach actually works very well on Linux, with performance comparable to IOCP on Windows.

like image 169
BlackAura Avatar answered Sep 18 '22 14:09

BlackAura


IOCP is pronounced "asynchronous I/O" on various UNIX platforms:

  • POSIX AIO is the standard
  • Kernel AIO, epoll and io_uring seem to be a Linux-specific implementations
  • Kqueue is the *BSD and Mac OSX implementation
  • Message Passing Interface (MPI) is an option for high-performance computing
  • obligatory Boost reference - Boost.Asio
like image 23
D.Shawley Avatar answered Sep 18 '22 14:09

D.Shawley