加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Reactor pattern - Introduction by wiki

发布时间:2020-12-15 04:58:02 所属栏目:百科 来源:网络整理
导读:The reactor design pattern is an event handling pattern for handling service requests deliveredconcurrently to a service handler by one or more inputs. The service handler thendemultiplexes the incoming requests and dispatches them synchro

The reactor design pattern is an event handling pattern for handling service requests deliveredconcurrently to a service handler by one or more inputs. The service handler thendemultiplexes the incoming requests and dispatches them synchronously to the associated request handlers.

Contents

[hide]
  • 1Structure
  • 2Properties
    • 2.1Benefits
    • 2.2Limitations
  • 3Implementations
    • 3.1C
    • 3.2C++
    • 3.3Java
    • 3.4C#
    • 3.5Perl
    • 3.6Python
    • 3.7Ruby
    • 3.8JavaScript
    • 3.9Tcl
  • 4See also
  • 5References
  • 6External links

[edit]Structure

  • Resources: Any resource that can provide input from or output to the system.
  • Synchronous Event Demultiplexer: Uses an event loop to block on all resources. When it is possible to start a synchronous operation on a resource without blocking,the demultiplexer sends 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.

[edit]Properties

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

[edit]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. Also,due to the synchronous calling of request handlers,the reactor pattern allows for simple coarse-grain concurrency while not adding the complexity of multiple threads to the system.

[edit]Limitations

The reactor pattern can be more difficult to debug[citation needed] 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 onSMP hardware. The scalability of the reactor pattern is limited not only by calling request handlers synchronously,but also by the demultiplexer. The original Unixselect and poll calls,for instance,have a maximum number of descriptors that may be polled and have performance issues with a high number of descriptors.[1] (More recently,more scalable[citation needed] variants of these interfaces have been made available: /dev/poll in Solaris,epoll in Linux andkqueue / kevent in BSD-based systems,allowing the implementation of very high performance systems with large numbers of open descriptors.)

[edit]Implementations

[edit]C

  • libowfat

[edit]C++

  • POCO C++ Libraries
  • The ADAPTIVE Communication Environment
  • Boost.Asio

[edit]Java

  • Apache MINA
  • Apache Cocoon (for XML processing)
  • JBoss Netty
  • xSocket

[edit]C#

  • Interlace

[edit]Perl

  • AnyEvent
  • POE

[edit]Python

  • Gevent
  • Twisted

[edit]Ruby

  • EventMachine

[edit]JavaScript

  • Node.js

[edit]Tcl

  • After command and event loop

[edit]See also

  • Proactor pattern (a pattern that also demultiplexes and dispatches events,but asynchronously)

[edit]References

  1. ^Kegel,Dan, The C10K problem,retrieved 2007-07-28

[edit]External links

  • An Object Behavioral Pattern for Demultiplexing and Dispatching Handles for Synchronous Events byDouglas C. Schmidt
  • APR Networking & the Reactor Pattern
  • Architecture of a Highly Scalable NIO-Based Server

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读