Boost application performance using asynchronous I/O-ref
副标题[/!--empirenews.page--]
Linux asynchronous I/O is a relatively recent addition to the Linux kernel. It's a standard feature of the 2.6 kernel,but you can find patches for 2.4. The basic idea behind AIO is to allow a process to initiate a number of I/O operations without having to block or wait for any to complete. At some later time,or after being notified of I/O completion,the process can retrieve the results of the I/O. Before digging into the AIO API,let's explore the different I/O models that are available under Linux. This isn't intended as an exhaustive review,but rather aims to cover the most common models to illustrate their differences from asynchronous I/O. Figure 1 shows synchronous and asynchronous models,as well as blocking and non-blocking models. A process that is I/O bound is one that performs more I/O than processing. A CPU-bound process does more processing than I/O. The Linux 2.6 scheduler actually favors I/O-bound processes because they commonly initiate an I/O and then block,which means other work can be efficiently interlaced between them. One of the most common models is the synchronous blocking I/O model. In this model,the user-space application performs a system call that results in the application blocking. This means that the application blocks until the system call is complete (data transferred or error). The calling application is in a state where it consumes no CPU and simply awaits the response,so it is efficient from a processing perspective. Figure 2 illustrates the traditional blocking I/O model,which is also the most common model used in applications today. Its behaviors are well understood,and its usage is efficient for typical applications. When the? read ?call spans a long duration. But,in fact,the application is actually blocked while the read is multiplexed with other work in the kernel.
A less efficient variant of synchronous blocking is synchronous non-blocking I/O. In this model,a device is opened as non-blocking. This means that instead of completing an I/O immediately,a? read ?to return it can reduce the overall data throughput.
Another blocking paradigm is non-blocking I/O with blocking notifications. In this model,non-blocking I/O is configured,and then the blocking
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |