反应堆模式最牛的那篇论文--由solidmango执笔翻译
The Reactor:An Object-Oriented Wrapper for Event-Driven Port Monitoring and Service Demultiplexing
反应堆模式:一种应用于事件驱动的端口监控和服务多路化的面向对象封装器
Douglas C. Schmidt
An earlier version of this paper appeared in the February 1993 issue of the C++ Report.
这篇文章的早期版本出现在1993年2月发表的C++ Report上。
1. Introduction
1. 绪论
This is part one of the third article in a series that describes techniques for encapsulating existing operating system (OS) interprocess communication (IPC) services within object oriented (OO) C++ wrappers.
这是描述使用C++面向对象技术封装操作系统进程间通信服务的一个系列的第三篇。
The first article explains the main principles and motivations for OO wrappers, which simplify the development of correct, concise, portable, and efficient applications.
第一篇文章解释了面向对象包装器的主要原则和动机,它简化了开发正确的,简明的,可移植的以及高效的应用程序。
The second article describes an OO wrapper called IPC SAP that encapsulates the BSD socket and System V TLI system call Application Programmatic Interfaces (APIs).
第二篇文章描述了一种被称为IPC SAP的面向对象包装器,它封装了BSD socket 和System V TLI 系统调用应用程序编程接口。
IPC SAP enables application programs to access local and remote IPC protocol families such as TCP/IP via a type-secure, object-oriented interface.
IPC SAP 使应用程序可以通过类型安全的面向对象的接口访问本地的和远程的IPC协议族,比如TCP/IP。
This third article presents an OO wrapper for the I/O port monitoring and timer-based event notification facilities provided by the select and poll system calls.
第三篇文章介绍了一种对于I/O端口监控和基于定时器的事件通知的由select 和poll系统调用提供的机制的面向对象包装器。
Both select and poll enable applications to specify a time-out interval to wait for the occurrence of different types of input and output events on one or more I/O descriptors.
select 和poll都允许应用程指定一个在一个或者多个I/O描述符上等待不同类型的输入输出事件的超时时间间隔。
Select and poll detect when certain I/O or timer events occur and demultiplex these events to the appropriate application(s).
select 和poll检测某个I/O 或者定时器事件的发生并且分发这些事件到适当的应用程序。
As with many other OS APIs, the event demultiplexing interfaces are complicated, error-prone, non-portable, and not easily extensible.
和其他许多操作系统应用程序编程接口一样,事件多路化系统非常复杂,容易出错,不易移植而且不容易扩展。
An extensible OO framework called the Reactor was developed to overcome these limitations.
一种被称为反应堆的可扩展的面向对象框架被开发出来以克服这些限制。
The Reactor provides a set of higher-level programming abstractions that simplify the design and implementation of event-driven distributed applications.
反应堆模式提供了一系列的高级的编程抽象,它简化了事件驱动的分布式系统的设计和实现。
The Reactor also shields developers from many error-prone details in the existing event demultiplexing APIs and improves application portability between different OS variants.
反应堆模式同时也将开发人员从容易出错的现存事件多路复用编程接口中解脱出来,同时改善了应用程序在不同的操作系统变种间的可移植性。
The Reactor is somewhat different than the IPC SAP class wrapper described in [2]. IPC SAP added a relatively“thin” OO veneer to the BSD socket and System V TLI APIs.
反应堆模式和IPC SAP类包装器有些不同,IPC SAP 添加了一个相对薄的面向对象封装在BSD socket and System V TLI应用程序编程接口之上。
On the other hand, the Reactor provides a significantly richer set of abstractions than those offered directly by select or poll.
另一方面,反应堆模式提供了一系列更加丰富的抽象相对于直接的select 和 poll所提供的。
In particular, the Reactor integrates I/O-based port monitoring together with timer-based event notification to provide a general framework for demultiplexing application communication services.
特别的,反应堆模式整合了基于I/O的端口监控和基于定时器的事件通知为多路化应用程序服务提供一种通用的框架。
Port monitoring is used by event-driven network servers that perform I/O on many connections simultaneously.
端口监控被用于事件驱动的同时为许多并发连接进行I/O的网络服务器。
Since these servers must handle multiple connections it is not feasible to perform blocking I/O on a single connection indefinitely.
由于这些服务器必须处理多个连接,对于单一的连接提供无限时间的阻塞I/O是不够灵活的。
Likewise, the timer-based APIs enable applications to register certain operations that are periodically or aperiodically activated via a centralized timer facility controlled by the Reactor.
同样的,基于定时器的应用程序编程接口使应用程序可以注册一些操作,它们通过一个由反应堆集中控制的定时器周期性或者非周期性的激活。
This topic is divided into two parts.
这个主题分为两部分。
Part one (presented in this article) describes a distributed logging facility that motivates the need for efficient event demultiplexing, examines several alternative solution approaches, evaluates the advantages and disadvantages of these alternatives, and compares them with the Reactor.
第一部分(在这篇文章介绍)描述一个分布式的日志系统,它激发了有效的事件多路化的需求,检查了其他的几个替代方案,评价了这些替代方案的优势和劣势,并且将他们和反应堆模式进行比较。
Part two (appearing in a subsequent issue of the C++ Report) focuses on the OO design aspects of the Reactor.
第二部分(出现在后来发表的C++ Report上)集中在反应堆模式的面向对象设计方面。
In addition, it discusses the design and implementation of the distributed logging facility.
另外,它讨论了分布式日志系统的设计和实现。
This example illustrates precisely how the Reactor simplifies the development of event-driven distributed applications.
这个例子精确的说明了反应堆模式是如何简化事件驱动的分布式应用程序的开发的。
2. Example: A Distributed Logging Facility
2. 例子:一个分布式日志系统
To motivate the utility of event demultiplexing mechanisms, this section describes the requirements and behavior of a distributed logging facility that handles event-driven I/O from multiple sources “simultaneously.”
为了演示事件多路复用机制的功能,这一节描述了一个处理从多个源头同时接收消息的事件驱动的I/O分布式日志系统。
As shown in Figure 1, the distributed logging facility offers several services to applications that operate concurrently throughout a network environment.
正如图1所示,这个分布式日志系统为应用程序提供几个服务,这些服务通过网络环境并发的操作。
First, it provides a centralized location for recording certain status information used to simplify the management and tracking of distributed application behavior.
首先,它为记录某些状态信息提供一个集中的位置以简化对于分布式应用程序行为的管理和跟踪。
To facilitate this, the client daemon time-stamps outgoing logging records to allow chronological tracing and reconstruction of the execution order of multiple concurrent processes executing on separate host machines.
为了完成这个功能,客户端的守护进程给发出去的日志记录打上时间戳从而可以按照时间顺序跟踪和重建多个并发进程在不同主机上的执行顺序。
Second, the facility also enables the prioritized delivery of logging records. These records are received and forwarded by the client daemon in the order of their importance, rather than in the order they were originally generated.
第二,这个功能也使按优先级投递日志记录称为可能。这些记录被客户端守护进程按他们的重要性接收和转发,而不是按照他们最初产生的顺序。
Centralizing the logging activities of many distributed applications within a single server is also useful since it serializes access to shared output devices such as consoles, printers, files, or network management databases.
集中多个分布式应用程序的产生日志到一个单一的服务器也是有用的,因为这使对输出设备比如控制台,打印机,文件或者网络管理数据库的访问得以串行化。
In contrast, without such a centralized facility, it becomes difficult to monitor and debug applications consisting of multiple concurrent processes.
相比之下,如果没有这样的集中设备,对于由多个并发进程组成的应用程序的监控和调试都将变得很困难。
For example, the output from ordinary C stdio library subroutines (such as fputs and printf) that are called simultaneously by multiple processes or threads is often scrambled together when it is displayed in a single window or console.
比如,一个普通的C stdio 库的子函数(比如fputs 和 printf)的输出,如果被多进程或者多线程同时调用,当显示在窗口或者控制台的时候经常会纠缠在一起。
The distributed logging facility is designed using a client/server architecture.
这个分布式日志系统被设计为使用客户端服务器架构。
The server logging daemon collects, formats, and outputs logging records forwarded from client logging daemons running on multiple hosts throughout a local and/or wide-area network.
服务器日志守护进程搜集,格式化并且输出从客户端日志守护进程转发过来的日志记录,这些客户端日志守护进程运行在多个主机上遍布于一个局域或者广域网。
Output from the logging server may be redirected to various devices such as printers, persistent storage repositories, or logging management consoles.
日志服务器的输出可能被重定向到各种设备,比如打印机,永久存储或者日志管理控制台。
As shown in Figure 1, the InterProcess Communication (IPC) structure of the logging facility involves several levels of demultiplexing.
正如图1所示,日志系统的进程间通信结构设计几个层次的多路化。
For instance, each client host in the network contains multiple application processes (such as P1 ; P2 ; andP3) that may participate with the distributed logging facility.
比如,网络上的每一个客户端主机包含多个应用程序进程(比如 P1;P2;P3),他们都可能参与分布式日志系统。
Each participating process uses the application logging API depicted in the rectangular boxes in Figure 1 to format debugging traces or error diagnostics into logging records.
每个参与进程都使用如图1的方框中所描述的应用程序日志API进行格式化调试跟踪或者错误诊断输入到日志记录系统中。
A logging record is an object containing several header fields and a payload with a maximum size of approximately 1K bytes.
一条日志记录是一个包含几个头域和一个有效载荷的最大值接近1K字节的对象。
When invoked by an application process, the Log Msg::log API prepends the current process identifier and program name to the record.
当Log Msg::log API被应用程序调用的时候, 它预先考虑将当前进程的ID和程序名字放进记录。
It then uses the “record-oriented” named pipe IPC mechanism to demultiplex these composite logging records onto a single client logging daemon running on each host machine.
然后使用基于记录的命名管道IPC机制多路化这些组合日志记录到一个单独的运行在每个主机上的日志客户端的守护进程上。
The client daemon prepends a time-stamp to the record and then employs a remote IPC service (such as TCP or RPC) to demultiplex the record into a server logging daemon running on a designated host in the network.
这个客户端守护进程为日志记录预先准备一个时间戳,然后发起一个远程的IPC服务(比如 TCP或者RPC)以多路化这个日志记录到一个运行在一个指定的网络主机上的守护进程中。
The server operates in an event-driven manner, processing logging records as they arrive from multiple client daemons.
服务器运行在一种事件驱动的方式下,同时处理来自多个客户端守护进程的日志记录。
Depending on the logging behavior of the participating applications, the logging records may be sent by arbitrary clients and arrive at the server daemon at arbitrary time intervals.
由于参与的应用程序产生日志的行为不同,日志记录可以来自于任意的客户端并且以任意的时间间隔到达服务器端。
A separate TCP stream connection is established between each client logging daemon and the designated server logging daemon.
一个单独的TCP流连接在客户端日志守护进程和指定的服务器端日志守护进程之间被创建出来。
Each client connection is represented by a unique I/O descriptor in the server.
每一个客户端的连接在服务器端以一个唯一的I/O描述符表示。
In addition, the server also maintains a dedicated I/O descriptor to accept new connection requests from client daemons that want to participate with the distributed logging facility.
另外,服务器也维护着一个专一的I/O描述符以接受从客户端守护进程发过来的想要参与分布式日志系统的连接请求。
During connection establishment the server caches the client’s host name (illustrated by the ovals in the logging server daemon), and uses this information to identify the client in the formatted records it prints to the output device(s).
在连接建立期间,服务器缓存客户端的主机名(在日志服务器守护进程的图中以椭圆说明),并且使用这些信息在格式化好的日志记录准备输出到输出设备中标识客户端。
The complete design and implementation of the distributed logging facility is described in [3].
分布式日志系统的完整的设计和实现在[3]中进行没描述。
The remainder of the current article presents the necessary background material by exploring several alternative mechanisms for handling I/O from multiple sources.
这篇文章的剩余部分通过探索几个其他的处理多路I/O的替代方案描述背景材料。
3. Operating System Event Demultiplexing
3. 操作系统事件多路化
Modern operating systems such as UNIX, Windows NT, and OS/2 offer several techniques that allow applications to perform I/O on multiple descriptors “simultaneously.”
现代操作系统比如UNIX,Windows NT, 和 OS/2都提供几种技术允许应用程序运行在多个描述符上的同时的I/O。
This section describes four alternatives and compares and contrasts their advantages and disadvantages.
这部分描述4种替代方案并且比较和对比他们的优势和劣势。
To focus the discussion, each alternative is characterized in terms of the distributed logging facility described in Section 2 above.
为了集中讨论,每个替代方案都被赋予上面第二部分中讨论的分布式日志系统的特性。
In particular, each section presents a skeletal server logging daemon implemented with the alternative being discussed.
特别的,每个部分表现为一个服务器端日志守护进程的使用替代技术的实现骨架。
To save space and increase clarity, the examples utilize the OO IPC SAP socket-wrapper library described in a previous C++ Report article [2].
为了节省空间并且是描述更加清楚,这些例子利用面向对象的IPC SAP套接字封装器库,这个库在先前的C++ Report文章中有描述。
The handle logging record function shown in Figure 2 is also invoked by all the example server daemons.
这个显示在图2中的处理日志记录的函数也被所有的服务端守护进程调用。
This function is responsible for receiving and processing the logging records and writing them to the appropriate output device.
这个函数负责接受和处理日志记录并且将他们写到适当的输出设备上。
Any synchronization mechanisms required to serialize access to the output device(s) are also performed in this function.
任何需要串行化访问输出设备的同步机制也在这个函数中进行操作。
In general, the concurrent multi-process and multi-thread approaches are somewhat more complicated to develop since output must be serialized to avoid scrambling the logging records generated from all the separate processes.
通常并发的多进程和多线程是相近的都使开发更加复杂,因为输出必须串行化以避免争夺日志记录从所有的分离的进程中产生。
To accomplish this, the concurrent server daemons cooperate by using some form of synchronization mechanisms (such as semaphores, locks, or other IPC mechanisms like FIFOs or message queues) in the handle logging record subroutine.
为了完成这个目标,这个并发服务器守护进程通过某种形式的同步机制(比如信号量,锁或者其他IPC机制比如FIFOs或者消息队列)来处理日志记录子进程。
4.Summary
4. 总结
This article presents the background material necessary to understand the behavior, advantages, and disadvantages of existing UNIX mechanisms for handling multiple sources of I/O in a network application.
这篇文章介绍了为了理解现存的UNIX处理多路网络I/O应用程序的机制的行为,优势和劣势的必要的背景资料。
An OO wrapper called the Reactor has been developed to encapsulate and overcome the limitations with the select and poll event demultiplexing system calls.
一个被称为反应堆的面向对象的封装器被开发出来以封装和克服select 和poll 事件多路化系统调用的限制。
The object-oriented design and implementation of the Reactor is explored in greater detail in part two of this article (appearing in the next C++ Report).
反应堆的面向对象设计和实现在这篇文章(在下一篇C++ Report上出现)的第二部分进行更加详细的讨论。
In addition to describing the class relationships and inheritance hierarchies, the follow-up article presents an extended example involving the distributed logging facility.
除了描述类的关系和继承层次,下一篇文章将介绍一个涉及分布式日志系统的可扩展的示例。
This example illustrates how the Reactor simplifies the development of event-driven network servers that manage multiple client connections simultaneously.
这个示例说明了反应堆是如何简化事件驱动的处理多个客户端同时连接的网络服务器开发的。
反应堆模式最牛的那篇论文--由solidmango执笔翻译的更多相关文章
- PayPal高级工程总监:读完这100篇论文 就能成大数据高手(附论文下载)
100 open source Big Data architecture papers for data professionals. 读完这100篇论文 就能成大数据高手 作者 白宁超 2016年 ...
- 反应堆模式(reactor)
在提到高性能服务器编程的时候肯定有听过reactor模式,如果只是简单的写一个服务器和客户端建立连接的程序来熟悉一下使用socket函数编程,一般这种情况都是同步方式实现的,服务器阻塞等待客户端的连接 ...
- zz2019年主动学习有哪些进展?答案在这三篇论文里
2019年主动学习有哪些进展?答案在这三篇论文里 目前推广应用的机器学习方法或模型主要解决分类问题,即给定一组数据(文本.图像.视频等),判断数据类别或将同类数据归类等,训练过程依赖于已标注类别的训练 ...
- 京东云与AI 10 篇论文被AAAI 2020 收录,京东科技实力亮相世界舞台
美国时间2月7-12日,AAAI 2020大会在纽约正式拉开序幕,AAAI作为全球人工智能领域的顶级学术会议,每年评审并收录来自全球最顶尖的学术论文,这些学术研究引领着技术的趋势和未来.京东云与AI在 ...
- TDSQL|三篇论文入选国际顶会SIGMOD,厉害了腾讯云数据库
好消息!6月13日,腾讯云数据库三篇论文再次入选数据库行业顶会SIGMOD,被SIGMOD 2022 Research Full Paper(研究类长文)收录. 本次被收录的研究成果中,新型数据结构设 ...
- 网易云安全两篇论文入选计算机视觉顶级会议ICCV
本文由 网易云发布. 10月22日至29日,全球计算机视觉顶尖专家们共聚威尼斯,参加ICCV2017国际计算机视觉大会,就领域内最新成果展开集中研讨,大会论文集也代表了计算机视觉领域最新的发展方向和 ...
- Going deeper with convolutions 这篇论文
致网友:如果你不小心检索到了这篇文章,请不要看,因为很烂.写下来用于作为我的笔记. 2014年,在LSVRC14(large-Scale Visual Recognition Challenge)中, ...
- Shachar Fleishma的论文,做点云重建的几篇论文都不错
http://www.sci.utah.edu/~shachar/ 几篇论文都不错,但貌似05年之后就没有什么动作了.
- GN算法---《Community structure in social and biological networks》这篇论文讲了什么?
用中文记下这篇论文的大致意思,以防止忘了.好记性不如烂笔头! 摘要:最近的一些研究在研究社交网络或WWW.研究者都集中于研究网络的“小世界性”,“幂率分布特性”,“网络传递性”(聚类性吧).本文提出网 ...
随机推荐
- 2013-09-22 [随笔]-Roy
不能因为一些小事情而一直影响自己的心情. 每天过得都应该有重点,无论是家庭还是工作还是其他. 要多花时间去吸取些新东西,看书,丰富自己的想法. 不能让日常的乱七八糟影响心情. bingo!
- 使用Ivy管理项目中的依赖
Ivy是什么 Ivy是一个跟踪管理项目直接以来关系的工具.Ivy具有良好的灵活性和可配置性,使其可以适应各种不同的依赖管理和构建过程要求:虽然Ivy作为依赖管理工具,其可以与Apache Ant进行紧 ...
- 一次与51aspx客服MM谈话 -- 坑是怎么发展的
GG从发布以来,我每次版本更新都会同步到51aspx源码网站,这次在同步更新GG V3.2版本到51aspx时,出了点小状况: 上传3.2版本几个小时后,我再次上去查看,发现其状态变成了“退回”,于是 ...
- linux 2.6 驱动笔记(二)
字符设备驱动 linux 2.6的字符驱动由cdev结构体描述,具体参考globalmem例子,代码主要分以下几部分: 1. 定义一个字符类型设备驱动的结构体 struct globalmem_dev ...
- zend studio 常用快捷键
zend studio是一款很棒的PHP语言编译器,强大的功能让很多程序员爱不释手,而快捷键更是程序员加快编写代码的利器,那么一起来看看有哪些好用的快捷键吧. 复制当前行:ctrl+alt+↓ 删除当 ...
- jQuery实现放大镜效果
1.1.1 摘要 相信大家都见过或使用过放大镜效果,甚至实现过该效果,它一般应用于放大查看商品图片,一些电商网站(例如:凡客,京东商城,阿里巴巴等)都有类似的图片查看效果. 在接下来的博文中,我们将向 ...
- jmx server 和jmx client
启动jmx server 和jmx client,通过jconsole进入jmx server 然后通过其中远程进程,进入jmx client: 发现,两者可用的tab页不同, MBean的数量类型也 ...
- 让DB2跑得更快——DB2内部解析与性能优化
让DB2跑得更快——DB2内部解析与性能优化 (DB2数据库领域的精彩强音,DB2技巧精髓的热心分享,资深数据库专家牛新庄.干毅民.成孜论.唐志刚联袂推荐!) 洪烨著 2013年10月出版 定价:7 ...
- 从双十一战报看传统大家电如何O2O转型?
说到大家电电商,大家都会想起天猫.京东.苏宁易购.国美在线等各大电商平台,他们这一次的双十一又实现了较大规模的增长,而各大电商平台家电辉煌战绩的背后实际上是各大品牌家电的成功. 格力今年双十一当天创下 ...
- iOS-远程推送
说到远程推送,应该用的也挺多的,今天就基于SEA的云推送服务,做一个推送的小demo,来了解一下iOS中的远程推送是怎么一回事儿,首先你得有苹果的开发者账号,好咸蛋也差不多了,主要内容走起. 一.准备 ...