Asynchronous Io, APC, Io completion port, thread pool, and high-performance server (I) asynchronous Io

Source: Internet
Author: User
Tags apc

Background: Pio DMA interrupt polling

The speed of early I/O devices is not too high compared with that of CPU. The CPU periodically polls the IO Device once to see if there are any processing requirements. If yes, it will be processed and then return to continue working. So far, the floppy disk still keeps this round robin method.
With the rapid increase in CPU performance, this inefficient way of working wastes a lot of CPU time. As a result, interruption of work has become a widely used technology. This technology enables the IO Device to generate a hardware interrupt when it needs to receive services, forcing the CPU to abandon the current processing task and enter the specific service interruption process. After the service interruption is completed, then proceed with the original processing. In this way, the IO Device and CPU can be processed at the same time, thus avoiding the CPU waiting for Io to complete.
Early data transmission modes were mainly Pio (program-controlled Io. Data is transmitted by programming the I/O address. For example, the software writes a byte of data to the serial port each time. After the serial port device completes the transmission task, an interruption occurs, and the software repeats until all the data is sent. Hardware devices with better performance provide a FIFO (first-in-first-out buffer), allowing the software to transmit more bytes at a time.
Obviously, the PIO method still takes too much CPU time for high-speed IO devices (because the transmission needs to be controlled through CPU programming ). However, the DMA (Direct Memory Access) method can greatly reduce the CPU processing time. The CPU only needs to tell the starting address and size of the data block of the DMA controller. Later, the DMA controller can transmit data between the memory and the device, and the CPU can process other tasks. After data transmission is completed, an interruption occurs.

Synchronous file IO and asynchronous file IO

The following is an excerpt from msdn synchronous file I/O and asynchronous file I/O.
There are two types of file IO synchronization: Synchronous file IO and asynchronous file IO. Asynchronous file IO, that is, overlapping Io.
In file I/O synchronization, the thread starts an I/O operation and immediately enters the waiting state until the I/O operation is complete. In asynchronous file I/O mode, the thread sends an I/O Request to the kernel and continues to process other things. After the kernel completes the I/O request, it will notify the thread that the I/O operation is completed.



If I/O requests require a large amount of time for execution, the asynchronous file I/O method can significantly improve the efficiency, because during the waiting period, the CPU will schedule other threads for execution, if no other thread needs to be executed, this time will be wasted (the operating system's zero-page thread may be scheduled ). If I/O requests are operated quickly, asynchronous I/O is still inefficient. It is better to use synchronous I/O.
Synchronous Io allows only one Io operation at a time, that is, Io operations on the same file handle are serialized, even if you use two threads, you cannot simultaneously perform read/write operations on the same file handle. Overlapping Io allows one or more threads to send IO requests at the same time.
When the asynchronous Io request is complete, the application is notified by setting the file handle to a signal state, or the application can check whether the IO request is completed through getoverlappedresult, you can also use an event object to notify the application.

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.