Proactor VS Reactor

Source: Internet
Author: User
Tags epoll

both are common design patterns in concurrent programming for separating and distributing I/O events, but slightly different:

The Proactor is used for asynchronous I/O operations, while reactor is used for synchronous I/O operations.

typical reactor model (read as an example):

    • event Handler
    • socket Fd Register to the splitter ( select/epoll
    • separator wait event;
    • socket Fd get Event Handler
    • event handler< Span style= "font-family: Microsoft Jacob Black;" > processing the obtained data, if necessary, event Handler Register yourself again to the splitter.

         

and Proactor

    • event Handler
    • socket Fd Register to the splitter ( select/epoll
    • separator wait event;
    • event handler initiates an asynchronous read operation and waits for the completion event;
    • os Use a parallel kernel thread to perform the actual read operation and notify after completion event handler< Span style= "font-family: Microsoft Jacob Black;"
    • event handler processing obtained data, if necessary , event Handler

         

The process of visible reading is different.

The problem with this model is that forWindowsplatform, you can useOSmake a real asynchronous/ o(the famous completion port). andLinuxon the platform2.6.22before the kernel, it is not available for asynchronous/ oof, onlyGlibcprovides a simulated asynchronous/ o(http://www.ibm.com/developerworks/linux/library/l-async/), which is implemented by multithreading in nature, has some unbearable flaws andBug, which is highly deprecated (seeHttp://davmac.org/davpage/linux/async-io.html). 2.6.22after that, it providesKernel AIO(Http://lse.sourceforge.net/io/aio.html), is the true kernel asynchronous notification,NginxThis method has been used (Http://wiki.nginx.org/HttpCoreModule). But there are also problems with this approach: the currentKernel AIOonly supportO_direcdisk cache is not available, this is one of the ways that it requires the size and displacement of the read-write to be in chunks (typically512byte) alignment (seehttp://forum.nginx.org/read.php?2,113524,113587#msg-113587).

for this reason the Livev author has re-implemented an AIO Library(http://software.schmorp.de/pkg/libeio.html). In essence , it is simulated by thread pool + synchronous operation, similar to GLIBC . But he claims fewer bugs and less overhead .

given the breadth and reliability of support, individuals tend to be more inclined to test Linux Asynchronous I/O uses kernel AIOinstead of Libeio. The former more detailed introduction of visible http://blog.csdn.net/eroswang/article/details/4095163

 

Proactor VS Reactor

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.