Asynchronous IO and assembly line programming-general Linux technology-Linux programming and kernel information. For details, see the following. The linux epoll, freebsd keyqueue, and solaris aio ports have many special io processing methods.
Boost asio encapsulates these system calls into a proactor model, which is expressed in the io_service class.
Most network programming examples are Frame Design Based on the io processing logic. Generally, I/O processing is overloaded or bound, most of which are implemented by handle_read handle_write handle_timeout.
There are some more advanced packages. For example, mina in apache is a java communication framework that breaks down io processing into concepts such as protocol, io_handler, codec, and filter. First, it converts network data to message through codec, then it is handed over to protocol for processing. I'm not talking about it anymore.
Asynchronous io is characterized by io triggering and completion, which are not synchronous or blocked, that is, triggering io. I don't know the io result, whether the read/write is successful, how many bytes, and so on.
Assembly-line programming refers to dispatch the io results (generally encapsulated into a connection class) to a thread pool. connection is always processed by one assembly line and flows from one end to the other. The status driver is generally based on the protocol logic.
One processor in the assembly line can be designed to return two States. values 1, 0, and 1 indicate switching to the next processor without waiting for asynchronous io results, 0 indicates that the asynchronous io result needs to be read and then switched to the next processor.
The pipeline processes io and separates the threads in the thread pool from the application logic. In addition, no logic code is applied when I/O is read/written. You do not need to lock resources. Therefore, the operation efficiency is very high.
Many programs program columns through network programming. threads have special roles, some are responsible for reading, some are responsible for writing, and columns must be synchronized in multiple threads, and it is best to use read/write locks, set up the launch line to prevent the queue from overflow. The thread efficiency is reduced due to synchronization, And the thread is assigned a special role, special functions, and waste.
I am not good at speaking. Here is an example.
There is a connection class that contains a buffer, which stores read and write data and status.
The thread pool runs a loop function and calls handle_events (ACE) and run_once (ASIO) to drive asynchronous io. After completing asynchronous io, place the connection in a Global Context object, such as Map . Use this context object to obtain the connection object and then perform pipeline processing. Cyclical.
Effect:
Thread Pool drives network I/O. The thread is not bound to specific code, which is public.
Io processing does not require lock synchronization, which is highly efficient.
The protocol logic is compiled into the pipeline. The pipeline is a state machine with simple programming logic.
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