Optimizing Thread Pool Strategies for Real-Time CORBA
Total Page:16
File Type:pdf, Size:1020Kb
Evaluating and Optimizing Thread Pool Strategies for Real-Time CORBA Irfan Pyarali, Marina Spivak, and Ron Cytron Douglas C. Schmidt g firfan,marina,cytron @cs.wustl.edu [email protected] Department of Computer Science Electrical and Computer Engineering Dept. Washington University, St. Louis, MO 63130, USA University of California, Irvine, CA 92697, USA Abstract tems were not well served by middleware like CORBA due to its lack of QoS support. Strict control over the scheduling and execution of processor The recent Real-time CORBA (RT-CORBA) 1.0 specifi- resources is essential for many fixed-priority real-time appli- cation [2, 3] in the CORBA 2.4 standard is an important cations. To facilitate this common requirement, the Real-Time step towards defining standards-based, commercial-off-the- CORBA (RT-CORBA) specification defines standard middle- shelf (COTS) middleware that can deliver end-to-end QoS ware features that support end-to-end predictability for oper- support at multiple levels in DRE systems. As shown in Fig- ations in such applications. One of the most important fea- ure 1, RT-CORBA ORB endsystems1 define standard capa- tures in RT-CORBA is thread pools, which allow application developers and end-users to configure and control processor END-TO-END PRIORITY resources. PROPAGATION This paper provides two contributions to the evaluation of in args operation() techniques for improving the quality of implementation of RT- CLIENT OBJECT OBJECT CORBA thread pools. First, we describe the key patterns REF out args + return value (SERVANT) underlying common strategies for implementing RT-CORBA STUBS STANDARD SKELETON THREAD thread pools. Second, we evaluate each thread pool strategy EXPLICIT SYNCHRONIZERS POOLS in terms of its consequences on (1) feature support, such as re- BINDING OBJECT ADAPTER quest buffering and thread borrowing, (2) scalability in terms of endpoints and event demultiplexers required, (3) efficiency GIOP ORB CORE in terms of data movement, context switches, memory allo- cations, and synchronizations required, (4) optimizations in PROTOCOL PROPERTIES terms of stack and thread specific storage memory allocations, OS KERNEL OS KERNEL and (5) bounded and unbounded priority inversion incurred in each implementation. This paper also provides results that il- OS I/O SUBSYSTEM OS I/O SUBSYSTEM lustrate empirically how different thread pool implementation NETWORK ADAPTERS NETWORK ADAPTERS strategies perform in different ORB configurations. NETWORK Figure 1: Standard Features in Real-Time CORBA ORB Endsystems 1 Introduction bilities that support end-to-end predictability for operations The maturation of the CORBA specification [1] and standards- in fixed-priority CORBA applications. RT-CORBA features based CORBA implementations has simplified the devel- allow applications to configure and control the following re- opment of distributed systems with complex functional re- sources: quirements. However, next-generation distributed real-time and embedded (DRE) systems, such as command and con- Processor resources via thread pools, priority mecha- trol systems, manufacturing process control systems, video- nisms, and intraprocess mutexes conferencing, large-scale distributed interactive simulations, Communication resources via protocol properties and ex- and testbeam data acquisition systems, have complex quality plicit bindings with non-multiplexed connections and of service (QoS) requirements, such as stringent bandwidth, 1An ORB endsystem consists of network interfaces, I/O subsystem and latency, jitter, and dependability needs. Historically, DRE sys- other OS mechanisms, and ORB middleware capabilities. 1 Memory resources via buffering requests in queues and Thread pool without lanes – In this basic thread pool bounding the size of thread pools. model all threads have the same assigned priority. This model is illustrated in Figure 2. [3] presents an overview of the RT-CORBA features and [4] explains how communication resources are configured and controlled efficiently in TAO [5], which is our high- Thread Pool performance, real-time implementation of CORBA. There are two general strategies for implementing RT- CORBA thread pools. The first strategy uses the Half- PRIORITY Sync/Half-Async pattern [6], where I/O thread(s) buffer the 20 incoming requests in a queue and a different set of worker threads then process the requests. The second strategy uses Figure 2: Thread Pool without Lanes the Leader/Followers pattern [6] to demultiplex I/O events into threads in a pool without requiring additional I/O threads. Thread pool with lanes – In this more advanced model a Each strategy is optimal for certain application domains, e.g.: pool consists of subsets of threads (called lanes)thatare assigned different priorities. This model is illustrated in Internet servers may use the Half-Sync/Half-Async pat- Figure 3. tern to improve scalability, at the expense of increased average- and worst-case latency. Thread Pool with Lanes Telecom servers may tolerate some degree of priority in- version when using the Half-Sync/Half-Async pattern to support buffering and borrowing across different priority PRIORITY PRIORITY PRIORITY bands. 10 35 50 Embedded avionics control system may trade resource duplication to avoid any priority inversions by using the Figure 3: Thread Pool with Lanes Leader/Followers pattern. The remainder of this paper is organized as follows: Section 2 To create thread pools without and with lanes, developers of describes the key features in RT-CORBA thread pools; Sec- real-time applications can configure thread pools in an RT- tion 3 illustrates how patterns can be applied to implement dif- CORBA server by using either the create threadpool ferent RT-CORBA thread pool strategies; Section 4 provides or create threadpool with lanes methods, respec- empirical results that compare different thread pool imple- tively, which are defined in the standard RTORB interface. mentation strategies; Section 5 compares our work on TAO’s Each thread pool is then associated with one or more POA thread pools with related work; and Section 6 presents con- via the RTCORBA::ThreadPoolPolicy. The threads in cluding remarks. a pool perform processing of client requests targeted at its as- sociated POA(s). While a thread pool can be associated with more than one POA, a POA can be associated with only one 2 An Overview of RT-CORBA Thread thread pool. Figure 4 illustrates the creation and association of Pools thread pools in a server. When created via the create threadpool* methods Many real-time systems use multi-threading to outlined above, thread pools can be configured with the fol- lowing properties: 1. Distinguish between different types of service, such as high-priority vs. low-priority tasks [7] Static threads, which defines the number of pool threads 2. Support thread preemption to prevent unbounded priority pre-allocated at thread pool creation time. inversion and deadlock and Dynamic threads, which defines the maximum number 3. Support complex object implementations that run for of threads that can be created on-demand. If a request variable and/or long durations. arrives when all existing threads are busy, a new thread To allow real-time ORB endsystems and applications to lever- is created to handle the request if the number of dynamic age these benefits of multi-threading, while controlling the threads in the pool have not exceeded the dynamic value amount of memory and processor resources they consume, specified by the user. the RT-CORBA specification defines a server thread pool The ability to configure the number of threads allows de- model [8]. There are two types of thread pools in RT-CORBA: velopers to bound the processing resources. Also, de- 2 Default Thread Pool A Thread Pool B quest buffering resources used when all threads are busy, Thread Pool specified in number of bytes or requests. If a request ar- rives when all threads are busy and the buffering space DEFAULT PRIORITY PRIORITY PRIORITY PRIORITY PRIORITY 10 35 50 20 is exhausted, the ORB should raise a TRANSIENT ex- ception, which indicates a temporary resource shortage. POA C When a client receives this exception it can reissue the S11 S12 S13 request at a later time. Figure 5 illustrates the thread pool 20 25 15 POA A request buffering feature. S4 S5 S6 S7 10 50 50 35 POA B Thead Pool A Thead Pool B S8 S9 S10 PRIORITY 10 PRIORITY 35 PRIORITY 20 S1 S2 S3 Root POA DEFAULT DEFAULT DEFAULT I/O THREADS SERVER ORB CORE Figure 4: POA Thread Pools in Real-time CORBA I/O SERVER ORB CORE velopers can choose between dynamic and static threads THREADS to trade off (1) the jitter introduced by dynamic thread Figure 5: Buffering Requests in RT-CORBA Thread Pools creation/destruction with (2) the wastefulness of under- utilized static threads. Thread borrowing, which controls whether a lane with Priority, which defines the CORBA priority with which higher priority is allowed to “borrow” threads from a lane threads are created. There are two thread priority with lower priority when it exhausts its maximum num- schemes used in RT-CORBA: native priority and CORBA ber of threads (both static and dynamic) and requires an priority. Native priority is the Real-Time Operating additional thread to service a new invocation. The bor- System (RTOS) specific thread priority representation. rowed thread has its priority raised to that of the lane that CORBA Priority, on the other hand, is a uniform rep- requires it. When the thread is no longer required, its pri- resentation used to overcome different RTOS specific ority is lowered once again to its previous value, and it is thread priority representations. A priority mapping returned to the lower priority lane. Naturally, this prop- scheme is used to map between native and CORBA pri- erty applies only to thread pools with lanes. orities and vice versa. The valid CORBA priority range is 0 to 32767. Static threads, dynamic threads,andpriority are per-lane Depending on the policies configured in the ORB, this properties in thread pool with lanes model.