数据流体系结构风格4

上传人:夏** 文档编号:574066600 上传时间:2024-08-15 格式:PPT 页数:51 大小:1.38MB
返回 下载 相关 举报
数据流体系结构风格4_第1页
第1页 / 共51页
数据流体系结构风格4_第2页
第2页 / 共51页
数据流体系结构风格4_第3页
第3页 / 共51页
数据流体系结构风格4_第4页
第4页 / 共51页
数据流体系结构风格4_第5页
第5页 / 共51页
点击查看更多>>
资源描述

《数据流体系结构风格4》由会员分享,可在线阅读,更多相关《数据流体系结构风格4(51页珍藏版)》请在金锄头文库上搜索。

1、软件体系结构及应用软件体系结构及应用4 4 数据流体系结构风格数据流体系结构风格2021/8/141主要内容n4.1 数据流体系结构风格的基本特征n4.2 管道-过滤器(pipe-and-filter)n4.3 批处理(batch sequential)n4.4 批处理与管道-过滤器的比较2021/8/1424.1 数据流体系结构风格的基本特征2021/8/143数据流风格的直观理解nA data flow system is one in which the availability of data controls the omputation (数据的可用性决定着处理是否执行) the

2、structure of the design is dominated by orderly motion of data from process to process (系统结构:数据在各处理之间的有序移动) in a pure data flow system, there is no other interaction between processes (在纯数据流系统中,处理之间除了数据交换,没有任何其他的交互)2021/8/144数据流风格的基本构件(COMPONENT)nComponents: data processing components(基本构件:数据处理) Int

3、erfaces are input ports and output ports ( Interfaces are input ports and output ports (构件接口:构件接口:输入端口和输出端口输入端口和输出端口) ) Input ports read data; output ports write data ( Input ports read data; output ports write data (从输入从输入端口读取数据,向输出端口写入数据端口读取数据,向输出端口写入数据) ) Computational model: read data from input

4、 ports, Computational model: read data from input ports, compute, write data to output ports (compute, write data to output ports (计算模型:从输入端计算模型:从输入端口读数,经过计算口读数,经过计算/ /处理,然后写到输出端口处理,然后写到输出端口) )2021/8/145数据流风格的连接件(CONNECTOR)nConnectors: data flow (data stream) (连接件:数据流) Uni-directional, usually async

5、hronous, buffered (单向、单向、通常是异步、有缓冲通常是异步、有缓冲) Interfaces are reader and writer roles (接口角色:接口角色:readerreader和和writerwriter) Computational model (计算模型计算模型: : 把数据从一个处理的输出把数据从一个处理的输出端口传送到另一个处理的输入端口端口传送到另一个处理的输入端口)2021/8/146数据流风格的拓扑结构(TOPOLOGY)2021/8/147数据流VS. 控制流n在von Neumann的计算机体系结构中,有控制流与数据流之分; 控制流(Co

6、ntrol flow) 数据流(Data flow)n讨论:二者有什么区别和联系?能否分别举出几个例子?二者有什么区别和联系?能否分别举出几个例子?2021/8/148两种典型的数据流风格nPipe-and-Filter (管道-过滤器)nBatch Sequential (批处理)2021/8/1494.2 管道与过滤器风格PIPE-AND-FILTER2021/8/1410从“自来水管道系统”看Pipe-And-Filter2021/8/1411基本定义n语境:数据源源不断的产生,系统需要对这些数据进行若干处理(分析、计算、转换等)。n解决方案: 把系统分解为几个序贯的处理步骤,这些步骤之

7、间通过数据流连接,一个步骤的输出是另一个步骤的输入; 每个处理步骤由一个过滤器构件(Filter)实现; 处理步骤之间的数据传输由管道(Pipe)负责。n每个处理步骤(过滤器)都有一组输入和输出,过滤器从管道中读取输入的数据流,经过内部处理,然后产生输出数据流并写入管道中。2021/8/1412Pipe-And-Filter风格的基本构成nComponents: Filters process data streams (构件:过滤器,处理数据流) A filter encapsulates a processing step (algorithm or computation) (一个过滤器

8、封装了一个处理步骤) Data source and data sink are particular filters (数据源点和数据终止点可以看作是特殊的过滤器)nConnectors: A pipe connects a source and a sink filter (连接件:管道,连接一个源和一个目的过滤器) Pipes move data from a filter output to a filter input (转发数据流) Data is a stream of “objects” (数据是特定类型的“对象”流)nTopology: Connectors define d

9、ata flow graph (连接器定义了数据流图,形成拓扑结构)2021/8/14131 过滤器(Filter)nIncrementally transform some of the source data into sink data(目标:将源数据变换成目标数据)nStream to stream transformation (从“数据流” “数据流”的变换) enrich data by computation and adding information (通过计算和增加信息来丰富数据) refine by distilling data or removing irrelev

10、ant data (通过浓缩和删减来精炼数据) transform data by changing its representation (通过改变数据表现方式来转化数据) decompose data to multiple streams (将一个数据流分解为多个数据流) merge multiple streams into one stream (将多个数据流合并为一个数据流)2021/8/1414过滤器对数据流的五种变换类型2021/8/1415过滤器读取与处理数据流的方式nIncrementally transform data from the source to the si

11、nk (递增的读取和消费数据流) 在输入被完全消费之前,输出便产生了。2021/8/1416过滤器的一些基本特征nFilters are independent entities, i.e., no context in processing streams (无上下文信息) no state preservation between instantiations (不保留状态) no knowledge of upstream/downstream filters (对其他过滤器无任何了解) collections can be used to buffer the data passed

12、through pipes: files,arrays, dictionaries, trees, etc. (可使用数据缓冲区临时保存数据流) 蓄水池2021/8/14172 管道(Pipe)nMove data from a filters output to a Move data from a filters output to a filters input (or to a device or file)(filters input (or to a device or file)(作用:作用:在过滤器之间传送数据在过滤器之间传送数据) ) One way flow from on

13、e data source to one data sink (单向流) A pipe may implement a buffer (可能具有缓冲区) Pipes form data transmission graph (管道形成传输图)n不同的管道中流动的数据流,具有不同的数据格式不同的管道中流动的数据流,具有不同的数据格式(Data format)(Data format)。n原因:数据在流过每一个过滤器时,被过滤器进行了原因:数据在流过每一个过滤器时,被过滤器进行了丰富、精练、转换、融合、分解丰富、精练、转换、融合、分解等操作,因而发生了等操作,因而发生了变化。变化。2021/8/1

14、418管道中流动的数据类型nPipe between two threads of a single process (e.g., Java Streams) Stream may contain references to shared language objectsnPipe between two processes on a single host computer (e.g., UNIX Named Pipes) stream may contain references to shared OS objects (e.g., files)nPipe between two pro

15、cesses in a distributed system (e.g., Internet Sockets) Stream contents limited to raw bytes Protocols implement high-level abstractions (e.g., pass pipes as reference, pass COBA object references)2021/8/1419管道中流动的数据类型nTradeoffTradeoff compatibility and reusability everything is a stream vs. type sa

16、fety stream of Persons, stream of TextsnPopular stream data formatsPopular stream data formats raw byte stream stream of ASCII text lines with line separator record stream (record attributes are strings, separated by tabulator or comma) nested record stream (record attribute is in turn a sequence) s

17、tream representing a tree traversal (inner nodes / leaf nodes enumerated in preorder, postorder, inorder) typed stream with a header containing its type information (e.g., column headings) event streams (event name and event arguments)2021/8/1420管道-过滤器风格的一些变化形式2021/8/1421数据流的分类:推式与拉式nQuestion: what

18、is the force that make data flow? (是什么力量推动数据在管道中流动?)nThree choice, all with force emanating from filters: Push: data source pushes data in downstream direction (推式:前面的过滤器把新产生的数据推入管道) Pull: data sink pulls data from upstream direction (拉式:随后的过滤器从管道中拉出所需数据) Push/pull: a filter is actively pulling from

19、 upstream, computing, and pushing downstream (推拉式:过滤器以循环的方式,从管道中拉出其输入数据,并将其处理产生的数据压入后续管道)2021/8/1422过滤器的分类:主动与被动nActive filter: drivers the data flow on the pipes. (主动过滤器:驱动数据流动, pull+push)nPassive filter: is driven by the data flow on the (input/output)pipes. (被动过滤器:被管道中的输入或输出数据流所驱动)nAttention:系统中至

20、少有一个主动过滤器(可以来自外部环境,如用户输入)2021/8/1423被动过滤器所采用的两种策略nPull Strategy: The filter is a passive object that is driven by the subsequent pipeline element that pulls output data from the filter; (采用拉式策略的被动过滤器: 该过滤器不会主动执行,而是在后续 过滤器的“拉”动作的驱动下才执行)nPush Strategy: The filter is a passive object that is driven by

21、the previous pipeline element that pushes input data into the filter. (采用推式策略的被动过滤器:该过滤 器不会主动执行,而是在前续过滤器 的“推”动作的驱动下才执行)2021/8/1424采用推式策略的被动过滤器2021/8/1425采用拉式策略的被动过滤器2021/8/1426一个混合型的管道-过滤器系统2021/8/1427一个混合型的管道-过滤器系统2021/8/1428带有缓冲区的混合型管道-过滤器系统2021/8/1429带有缓冲区的混合型管道-过滤器系统2021/8/1430过滤器的状态n停止状态:表示过滤器处

22、于待启动状态,当外部启动过滤器后,过滤器处于处理状态。n处理状态:表示过滤器正处理输入数据队列中的数据。n等待状态:表示过滤器的输入数据队列为空,此时过滤器等待,当有新的数据输入时,过滤器处于处理状态。2021/8/1431Pipe-And-Filter风格的典型应用2021/8/1432Pipe-And-Filter风格的典型应用nComplier (scan, parse, generate code, .) (Complier (scan, parse, generate code, .) (编译器编译器) )nUnix pipes (Unix pipes (UnixUnix管道管道)

23、)nImage processing (Image processing (图像处理图像处理) )nSignal processing (Signal processing (信号处理信号处理) )nVoice and video streaming (Voice and video streaming (声音与图像处理声音与图像处理) )n2021/8/1433管道-过滤器风格的例子2021/8/1434管道-过滤器风格的例子:Unix Shell2021/8/1435管道-过滤器风格的例子: Unix Shell2021/8/1436管道-过滤器风格的例子:编译器(1)2021/8/143

24、7管道-过滤器风格的例子:编译器(2)2021/8/1438管道-过滤器风格的优点n使得系统中的构件具有良好的使得系统中的构件具有良好的隐蔽性和高内聚、低耦隐蔽性和高内聚、低耦合合的特点;的特点;n允许设计者将整个系统的输入允许设计者将整个系统的输入/ /输出行为看成是多个输出行为看成是多个过滤器的行为的过滤器的行为的简单合成简单合成;n支持软件复用支持软件复用: 只要提供适合在两个过滤器之间传送的数据,任何两个只要提供适合在两个过滤器之间传送的数据,任何两个过滤器都可被连接起来;过滤器都可被连接起来;n系统维护和增强系统性能简单系统维护和增强系统性能简单: 新的过滤器可以添加到现有系统中来,

25、旧的可以被改进新的过滤器可以添加到现有系统中来,旧的可以被改进的过滤器替换掉;的过滤器替换掉;n允许对一些如吞吐量、死锁等属性的分析允许对一些如吞吐量、死锁等属性的分析;n支持并行执行支持并行执行: 每个过滤器是作为一个单独的任务完成,因此可与其它每个过滤器是作为一个单独的任务完成,因此可与其它任务并行执行。任务并行执行。2021/8/1439管道-过滤器风格的缺点n通常导致进程成为批处理的结构 这是因为虽然过滤器可增量式地处理数据,但它们是独立的,所以设计者必须将每个过滤器看成一个完整的从输入到输出的转换;n不适合处理交互的应用 当需要增量地显示改变时,这个问题尤为严重;n因为在数据传输上没

26、有通用的标准,每个过滤器都增加了解析和合成数据的工作,这样就导致了系统性能下降,并增加了编写过滤器的复杂性。 绝大部分处理时间消耗在格式转换上2021/8/14404.3 顺序批处理风格Batch Sequential Style2021/8/1441批处理风格的直观结构将用户输入的纸带上的数据写入磁带将磁带作为计算设备的输入,进行计算,得到输出结果打印计算结果2021/8/1442批处理风格的直观结构2021/8/1443基本定义nProcessing steps are independent programs(每个处理步骤是一个独立的程序)nEach step runs to compl

27、etion before next step starts(每一步必须在前一步结束后才能开始)nData transmitted as a whole between steps(数据必须是完整的,以整体的方式传递)nTypical applications(典型应用): classical data processing (传统的数据处理) program compilation/computer aided software engineering (程序编译/CASE工具)2021/8/1444基本构成nComponents (processing steps) are independ

28、ent programs(基本构件:独立的应用程序)nConnectors are some type of media - traditionally magnetic tape(连接件:某种类型的媒质)nTopology: Connectors define data flow graph (连接件定义了相应的数据流图,表达拓扑结构)nEach step runs to completion before the next step begins (每一步骤必须在前一步骤完全结束之后方能开始)2021/8/1445示例:批处理风格的系统数据流图(Data Flow Diagram,DFD图

29、)2021/8/14464.4 批处理与管道-过滤器的比较2021/8/1447批处理与管道-过滤器的比较n相似点: Decompose task into fixed sequence of computations (把任务分解成为一系列固定顺序的计算单元) Interact only through data passed from one to another (彼此间只通过数据传递交互)2021/8/1448批处理与管道-过滤器的比较n不同点:Batch SequentialPipe-and-Filtertotal(整体传递数据整体传递数据)coarse grained(构件粒度较大

30、构件粒度较大)high latency (延迟高,实时性差延迟高,实时性差)no concurrency (无并发无并发)incremental(增量增量)fine grained (构件粒度较小构件粒度较小) results starts processing (实时性实时性好好)concurrency possible (可并发可并发)2021/8/1449归纳:选择数据流风格的一些原则nTask is dominated by the availability of data (任务由数据的可用性来主导)nData can be moved predictably from process to process (事先知道数据的确切流向)nThere may be a performance penalty in data flow styles,however this depends on many factors (数据的流动带来性能损耗)2021/8/1450部分资料从网络收集整理而来,供大家参考,感谢您的关注!

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 资格认证/考试 > 自考

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号