Applying the Proactor Pattern to High-Performance Web Servers
Total Page:16
File Type:pdf, Size:1020Kb
APPLYING THE PROACTOR PATTERN TO HIGH-PERFORMANCE WEB SERVERS James Hu Irfan Pyarali Douglas C. Schmidt [email protected],edu [email protected] [email protected] Department of Computer Science, Washington University St. Louis, MO 63130, USA This paper is a revised and expanded version of the paper 1 INTRODUCTION that will appear in the 10th International Conference on Par- allel and Distributed Computing and Systems, IASTED, Las Computing power and network bandwidth on the Internet Vegas, Nevada, October 28-31, 1998. has increased dramatically over the past decade. High-speed networks (such as ATM and Gigabit Ethernet) and high- performance I/O subsystems (such as RAID) are becoming ABSTRACT ubiquitous. In this context, developing scalable Web servers that can exploit these innovations remains a key challenge Modern operating systems provide multiple concurrency for developers. Thus, it is increasingly important to allevi- mechanisms to develop high-performance Web servers. Syn- ate common Web server bottlenecks, such as inappropriate chronous multi-threading is a popular mechanism for devel- choice of concurrency and dispatching strategies, excessive oping Web servers that must perform multiple operations si- filesystem access, and unnecessary data copying. multaneously to meet their performance requirements. In ad- Our research vehicle for exploring the performance impact dition, an increasing number of operating systems support of applying various Web server optimization techniques is the asynchronous mechanisms that provide the benefits of concur- JAWS Adaptive Web Server (JAWS) [1]. JAWS is both an rency, while alleviating much of the performance overhead of adaptive Web server and a development framework for Web synchronous multi-threading. servers that runs on multiple OS platforms including Win32, This paper provides two contributions to the study of most versions of UNIX, and MVS Open Edition. high-performance Web servers. First, it examines how syn- Our experience [2] building Web servers on multiple OS chronous and asynchronous event dispatching mechanisms platforms demonstrates that the effort required to optimize impact the design and performance of JAWS, which is our performance can be simplified significantly by leveraging OS- high-performance Web server framework. The results reveal specific features. For example, an optimized file I/O sys- significant performance improvements when a proactive con- tem that automatically caches open files in main memory currency model is used to combine lightweight concurrency via mmap greatly reduces latency on Solaris. Likewise, sup- with asynchronous event dispatching. port for asynchronous event dispatching on Windows NT can In general, however, the complexity of the proactive con- substantially increase server throughput by reducing context currency model makes it harder to program applications that switching and synchronization overhead incurred by multi- can utilize asynchronous concurrency mechanisms effectively. threading. Therefore, the second contribution of this paper describes how Unfortunately, the increase in performance obtained to reduce the software complexity of asynchronous concurrent through the use of asynchronous event dispatching on exist- applications by applying the Proactor pattern. This pattern ing operating systems comes at the cost of increased software describes the steps required to structure object-oriented ap- complexity. Moreover, this complexity is further compounded plications that seamlessly combine concurrency with asyn- when asynchrony is coupled with multi-threading. This style chronous event dispatching. The Proactor pattern simpli- of programming, i.e., proactive programming, is relatively un- fies concurrent programming and improves performance by familiar to many developers accustomed to the synchronous allowing concurrent application to have multiple operations event dispatching paradigm. This paper describes how the running simultaneously without requiring a large number of Proactor pattern can be applied to improve both the perfor- threads. mance and the design of high-performance communication applications, such as Web servers. This work was supported in part by Microsoft, Siemens Med, and A pattern represents a recurring solution to a software de- Siemens Corporate Research. velopment problem within a particular context [3]. Patterns 1 identify the static and dynamic collaborations and interactions and frameworks are guided by a family of patterns, which are between software components. In general, applying patterns listed along the borders in Figure 1. An outline of the key to complex object-oriented concurrent applications can signif- frameworks, components, and patterns in JAWS is presented icantly improve software quality, increase software maintain- below; Section 4 then focuses on the Proactor pattern in de- ability, and support broad reuse of components and architec- tail.1 tural designs [4]. In particular, applying the Proactor pattern Event Dispatcher: This component is responsible for coordi- to JAWS simplifies asynchronous application development by nating JAWS’ Concurrency Strategy with its I/O Strategy.The structuring the demultiplexing of completion events and the passive establishment of connection events with Web clients dispatching of their corresponding completion routines. follows the Acceptor pattern [6]. New incoming HTTP re- The remainder of this paper is organized as follows: Sec- quest events are serviced by a concurrency strategy. As events tion 2 provides an overview of the JAWS server framework de- are processed, they are dispatched to the Protocol Handler, sign; Section 3 discusses alternative event dispatching strate- which is parameterized by an I/O strategy. JAWS ability to gies and their performance impacts; Section 4 explores how to dynamically bind to a particular concurrency strategy and I/O leverage the gains of asynchronous event dispatching through strategy from a range of alternatives follows the Strategy pat- application of the Proactor pattern; and Section 5 presents tern [3]. concluding remarks. Concurrency Strategy: This framework implements con- currency mechanisms (such as single-threaded, thread-per- 2 JAWS FRAMEWORK OVERVIEW request, or thread pool) that can be selected adaptively at run-time using the State pattern [3] or pre-determined at Figure 1 illustrates the major structural components and de- initialization-time. The Service Configurator pattern [7] is sign patterns that comprise the JAWS framework [1]. JAWS used to configure a particular concurrency strategy into a Web server at run-time. When concurrency involves multi- Reactor/Proactor Strategy Singleton Memento ple threads, the strategy creates protocol handlers that follow I/O Strategy Cached Virtual Framework Filesystem the Active Object pattern [8]. State I/O Strategy: This framework implements various I/O mech- anisms, such as asynchronous, synchronous and reactive I/O. Asynchronous Completion Token Tilde ~ Multiple I/O mechanisms can be used simultaneously. In Expander /home/... Protocol Acceptor JAWS, asynchronous I/O is implemented using the Proactor Handler Event Dispatcher pattern [9], while reactive I/O is accomplished through the Protocol Reactor pattern [10]. These I/O strategies may utilize the Me- Filter mento [3] and Asynchronous Completion Token [11] patterns Service Configurator to capture and externalize the state of a request so that it can Service Configurator Adapter be restored at a later time. Concurrency Protocol Handler: This framework allows system develop- Protocol Pipeline Strategy ers to apply the JAWS framework to a variety of Web system Framework Framework State Pipes and Filters Active Object Strategy applications. A Protocol Handler is parameterized by a con- currency strategy and an I/O strategy. These strategies are decoupled from the protocol handler using the Adapter pat- Figure 1: Architectural Overview of the JAWS Framework tern [3]. In JAWS, this component implements the parsing and handling of HTTP/1.0 request methods. The abstraction is designed to allow the customization of various Web server allows for other protocols (such as HTTP/1.1, DICOM, and strategies in response to environmental factors. These factors SFP [12]) to be incorporated easily into JAWS. To add a new include static factors (e.g., number of available CPUs, sup- protocol, developers simply write a new Protocol Handler im- port for kernel-level threads, and availability of asynchronous plementation, which is then configured into the JAWS frame- I/O in the OS), as well as dynamic factors (e.g., Web traffic work. patterns and workload characteristics). Protocol Pipeline: This framework allows filter operations to JAWS is structured as a framework of frameworks.The be incorporated easily with the data being processed by the overall JAWS framework contains the following components Protocol Handler. This integration is achieved by employing and frameworks: an Event Dispatcher, Concurrency Strat- the Adapter pattern. Pipelines follow the Pipes and Filters egy, I/O Strategy, Protocol Pipeline, Protocol Handlers,and pattern [13] for input processing. Pipeline components can be Cached Virtual Filesystem. Each framework is structured as a 1Due to space limitations it is not possible to describe all the patterns set of collaborating objects implemented using components mentioned below in detail. The references provide complete coverage of each in ACE [5]. The collaborations among JAWS components pattern, however. 2 linked dynamically