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