A Portable, Extensible and Efficient Implementation of Proactor Pattern
Alexander Babu Arulanthu, Irfan Pyarali, Douglas C. Schmidt
The Proactor pattern (1) describes how to structure applica- tions and systems that effectively utilize asynchronous mech- anisms supported by operating systems.
Proactor模式给出了如何构造应用程序与系统, 高效的利用操作系统提供的异步机制。
When an application invokes an asynchronous operation, the OS performs the oper- ation on behalf of the application.
当一个应用程序调用一个异步操作时,操作系统来具体执行异步操作。
This allows the application to have multiple operations running simultaneously without requiring the application to have a corresponding number of threads.
这样允许应用程序同时请求多个异步操作,而不需要启动相应个数的线程。
Therefore, the Proactor pattern simplifies concurrent programming and improves performance by requiring fewer threads and leveraging OS support for asynchronous opera- tions.
综上,Proactor模式简化了并行编程,通过利用少许线程和操作系统的异步操作支持提高了性能。
The Adaptive Communications Environment (ACE) (2) has implemented a Proactor framework that encapsulates I/O Completion Ports of Windows NT operating system.
ACE实现了Proactor框架,封装了WindowsNT的完成端口。
This ACE Proactor abstraction provides an OO interface to the standard C APIs supported by Windows NT.
ACE Proactor 提供了WindowsNT的C api 的OO抽象接口。
This pa- per describes the design and implementation of this new Portable Proactor framework and explains how the de- sign and the implementation have been made so that the framework can be extensible, scalable and efficient.
本文档阐述了这个新的可移植Proactor框架设计与实现,解释了为何这个设计与实现使得框架可扩展,可伸缩,高效。
1、Proactor 模式
1.1 意图
The Proactor pattern presented in [1] supports the demultiplex-
ing and dispatching of multiple event handlers, which are trig-
gered by the completion of asynchronous events.
Proactor模式支持由异步操作完成事件触发的分解复用与多重事件分发。
This pattern simplifies asynchronous application development by integrat-
ing the demultiplexing of completion events and the dispatching of their corresponding event handlers.
正是因为该模式集成了完成事件的分解复用与之相应事件处理分发,简化了异步程序的开发。
1.2 Motivation
1.2 动机
The Proactor pattern should be applied when applications require the performance benefits of executing operations concurrently, without the constraints of synchronous multi-threaded or reactive programming.
Proactor模式可以应用在通过并行的执行操作来提升应用程序性能。而不需要额外的同步多线程程序限制或反应堆编程。
To illustrate these benefits, consider a networking application that needs to perform multiple operations concurrently.
为了展示这些益处, 考虑一下这种情况, 当一个网络应用程序需要同时处理多个操作。
For example, a high-performance Web server must concurrently process HTTP requests sent from multiple clients.
例如,一个高性能的Web服务器需要同时处理多个来自客户端的HTTP发送请求。
Figure 1 shows a typical interaction between Web browsers and a Web server.
图1. 显示了一个典型的浏览器与WEB服务器间交互
When a user instructs a browser to open a URL, the browser sends an HTTP GET request to the Web server.
当一个用户在浏览器输入打开一个网址, 浏览器会发送一个Http读取请求给服务器。
Upon receipt, the server parses and validates the request and sends the specified file(s) back to the browser.
服务器收到后,先解析和校验一个请求,发送指定的文件回给浏览器。
Developing high-performanceWeb servers requires the res-
olution of the following forces:
Concurrency – The server must perform multiple client
requests simultaneously;
Efficiency – The server must minimize latency, maximize
throughput, and avoid utilizing the CPU(s) unnecessarily.
Programming simplicity – The design of the server
should simplify the use of efficient concurrency strate-
gies;
Adaptability – Integrating new or improved transport pro-
tocols (such as HTTP 1.1 [3]) should incurminimalmain-
tenance costs.