Reactor pattern
   HOME

TheInfoList



OR:

The reactor design pattern is an
event handling In programming and software design, an event is an action or occurrence recognized by software, often originating asynchronously from the external environment, that may be handled by the software. Computer events can be generated or triggere ...
pattern for handling service requests delivered concurrently to a service handler by one or more inputs. The service handler then
demultiplex In telecommunications and computer networking, multiplexing (sometimes contracted to muxing) is a method by which multiple analog or digital signals are combined into one signal over a shared medium. The aim is to share a scarce resource - a ...
es the incoming requests and dispatches them synchronously to the associated request handlers.


Structure

;Resources: Any resource that can provide input to or consume output from the system. ;Synchronous Event Demultiplexer: Uses an
event loop In computer science, the event loop is a programming construct or design pattern that waits for and dispatches events or messages in a program. The event loop works by making a request to some internal or external "event provider" (that generally ...
to block on all resources. The demultiplexer sends the resource to the dispatcher when it is possible to start a synchronous operation on a resource without blocking (''Example:'' a synchronous call to read() will block if there is no data to read. The demultiplexer uses select() on the resource, which blocks until the resource is available for reading. In this case, a synchronous call to read() won't block, and the demultiplexer can send the resource to the dispatcher.) ;Dispatcher: Handles registering and unregistering of request handlers. Dispatches resources from the demultiplexer to the associated request handler. ;Request Handler: An application defined request handler and its associated resource.


Properties

All reactor systems are single-threaded by definition, but can exist in a multithreaded environment.


Benefits

The reactor pattern completely separates application-specific code from the reactor implementation, which means that application components can be divided into modular, reusable parts.


Limitations

The reactor pattern can be more difficult to debug than a procedural pattern due to the inverted flow of control. Also, by only calling request handlers synchronously, the reactor pattern limits maximum concurrency, especially on
symmetric multiprocessing Symmetric multiprocessing or shared-memory multiprocessing (SMP) involves a multiprocessor computer hardware and software architecture where two or more identical processors are connected to a single, shared main memory, have full access to all ...
hardware. The scalability of the reactor pattern is limited not only by calling request handlers synchronously, but also by the demultiplexer.


See also

*
Proactor pattern Proactor is a software design pattern for event handling in which long running activities are running in an asynchronous part. A ''completion handler'' is called after the asynchronous part has terminated. The proactor pattern can be considered to ...
(a pattern that also demultiplexes and dispatches events, but asynchronously) *
Application server An application server is a server that hosts applications or software that delivers a business application through a communication protocol. An application server framework is a service layer model. It includes software components available to a ...
*
C10k problem The C10k problem is the problem of optimizing network sockets to handle a large number of clients at the same time. The name C10k is a numeronym for concurrently handling ten thousand connections. Handling many concurrent connections is a differe ...


References


External links


An Object Behavioral Pattern for Demultiplexing and Dispatching Handles for Synchronous Events
by
Douglas C. Schmidt Douglas C. Schmidt (born July 18, 1962) is a computer scientist and author in the fields of object-oriented programming, distributed computing and design patterns. Biography In August 1994 he joined the faculty of Washington University, St. Lo ...

APR Networking & the Reactor Pattern

Architecture of a Highly Scalable NIO-Based Server


{{Design Patterns patterns Concurrent computing Events (computing) Software design patterns