I studied architecture design pattern of the code - again understood synchronous and asynchronous IO IO

First Virtual IO example of a hardware metaphor:

Synchronization IO: There is such a hardware device that can be used to store data, but the device itself does not have its own CPU, all data read and write operations by the main CPU of the computer can only be completed, such as read and write opposite it is the main CPU synchronous IO.

2 asynchronous IO: There is such a device that can be used to store various data, and 1, the apparatus is provided with its own CPU, with a certain autonomy, when the data-readable device may send events to the main CPU reading completion notification, the main CPU when a data buffer is presented to the device, the CPU can complete device write data, which is read is opposed to the main CPU asynchronous IO.

In our software design level, the read and write socket to take an example:

IO is the so-called synchronous read and write socket is completely done by the thread pool thread business, equivalent to the above example entirely complete socket read and write by the main CPU.

The so-called asynchronous IO: We do have to design a single IO thread pool dedicated to reading and writing to the socket, read socket: socket when data is read, IO thread pool thread pool to be notified to the service to read the data; write when the socket: business thread business data is ready to put the socket and associated send buffer, and then do the actual writing socket by the IO thread pool. The IO thread pool can do multiple socket read and write at the same time. In the example above corresponds to the CPU for reading and writing apparatus, the main CPU is released from the reader, which is asynchronous IO.

 

We come back next expansion, extended to non-IO operations for a long time consuming operations:

Synchronous operation is time-consuming operation to do business in the thread.

Asynchronous operation is to submit time-consuming operation to separate specialize in time-consuming operations to complete the thread pool, when the time-consuming operation is completed, the thread notifies the business in the form of news events.

 

Drawback of synchronous operations: reducing the throughput of the service processing service thread pool

The advantages of asynchronous operation: Business thread pool is not completely blocked, high throughput processing business

(Finish)

Published 63 original articles · won praise 25 · views 80000 +

Guess you like

Origin blog.csdn.net/w1857518575/article/details/86695849