Chapter 5 (New)
Chapter 5 (New)
-123 U
Validated Sorted
Transaction File
transaction transaction
222 U
222 U 111 I
111 I
Validate 111 I sort 222 U
333 D
333 D 333 D
-123 U
100 ----
Update
111 ----
200 ----
222 ----
Generate Report 444 ----
Master file
Batch Sequential Architecture
• Applicable Design Domains
– Data are batched.
– Intermediate file is a sequential access file.
– Each sub-system reads related input files and writes output files.
• Benefits:
– Simple divisions on sub-systems.
– Each sub-system can be a stand-alone program working on input data and
producing output data.
• Limitations:
– Implementation requires external control.
– Does no provide interactive interface.
– Concurrency is not supported and hence throughput remains low
– High latency.
Pipe & Filter Architecture
• Is another type of data flow architecture where the flow is
driven by data.
• This architecture decomposes the whole system into
components of
– Data source
– Filters
– Pipes
– Data sinks
• The connections between components are data streams.
+read() +write()
Pipe and Filter Block Diagram and Sequence Diagram
read
Filter1
W
Filter2
R
write
pipe
Fig Pipelined Pipe and Filter
e
a
b
c
e
A2
c Upper Case ECBAE DEF Matching (A , E ) AE (Sort * Count )
def ac E2
a Conversion Filter Filter Filter
f
e
d
Data Source
Data Sink
• The conversion filter converts all
characters from lower case to upper case
and the matching filter selects character
“A” and “E” in the stream.
• They are working concurrently; the
matching filter can start its job before
conversion completes its transformation of
the whole input stream.
• The sort and count filter counts the number
of occurrences of “A” and “E” and sort
them in alphabetical order.
• It can take its input before the matching
filter finishes the job but cannot output data
until it gets all data in.
Pipe and Filter Sequence Diagram
Pipe & Filter in Unix
• The pipe operator “|” moves the stdout from its
predecessor to the stdin of its successor.
• The successor can start data transformation
over the data stream before the predecessor
completes its transformation or processing.
• For example, the pipeline of Unix commands
reports the number of users who are logged on
the system currently.
who | wc –l
Pipe & Filter in Java
• The Java API provides the PipedWriter
and PipedReader classes in the java.io
package
– allows for filters to push data into downstream
or to pull data from the upstream.
• Filters
– can run in separate threads
– can be synchronized in a parallel manner by
PipedWriter and PipedReader.
Filter1.java:
package pf;
import java.io.*;
public class Filter1 extends Thread {
PipedWriter myPw;
public Filter1(PipedWriter pw) { myPw=pw; }
public void run() {
int j;
try {
for (int j = 1; j<100; j++) pw.write(j);
pw.write(-1);
}
catch(Exception e){. . .}
}
}
Filter2.java:
package pf;
import java.io.*;
class Filter2 extends Thread {
PipedReader myPr;
public Filter2(PipedReader pr) { myPr = pr; }
public void run() {
int j;
try {
while (myPr.read()!= -1){ . . . }
}
catch(Exception e){. . .}
}
}
Contd…..
pipeFilter.java:
import pf.*;
import java.io.*;
public class pipeFilter {
public static void main(String[] args) {
try {
PipedWriter pw = new PipedWriter();
PipedReader pr = new PipedReader(pw);
Filter1 f1 = new Filter1(pw);
Filter2 f2 = new Filter2(pr);
f2.start();
f1.start();
}
catch(Exception e){ . . . }
}
}
• The pipeFilter Java main program runs two threads in
addition to itself: Filter1 and Filter2.
• They are connected by a synchronized pipe (PipedWriter
and PipedReader).
• Filter1 writes to the pipe and Filter2 reads from the pipe.
Do we need to start Filter1 before starting Filter2? The
answer is No.
• You can see that the main program actually starts Filter2
before Filter1.
• It works perfectly. This example demonstrates that the
order of filters in the sequence is not important as long as
the synchronization is taken care of.
Pipe & Filter Architecture
• Applicable Design Domain
– Whenever the system can be broken into a series of
processing steps over data streams
• in each step filters consume and move data incrementally.
– Whenever the data format on the data streams is
• simple and stable,
• and easy to be adapted if it is necessary.
– Whenever there is significant work
• Which can be pipelined to gain increased performance
– Suitable for producer/consumer type of problems.
Pipe & Filter Architecture
• Benefits of Pipe & Filter
– Concurrency: High overall throughput for excessive
data processing
– Reusability: Encapsulation of filters makes it easy to
plug and play and to substitute.
– Modifiability: Low coupling between filters, less impact
from adding new filters and modifying the
implementation of any existing filters as long as the
I/O interfaces are unchanged.
– Simplicity: Clear division between any two filters
connected by a pipe.
– Flexibility: It supports both sequential and parallel
execution.
Pipe & Filter Architecture
• Limitations of Pipe & Filter
– Not suitable for dynamic interactions.
– Low Common Denominator
• Is required for data transmission in the ASCII formats
– since filters may need to handle data streams in different
formats such as record type or XML type rather than character
type.
– Overhead of data transformation among filters such
as parsing repeated in two consecutive filters.
– Difficult to configure a P&F system dynamically.
Process-Control Architecture
• Is suitable for the embedded system software
design
– where the system is manipulated by a process
control variable data.
• Decomposes the whole system into
– sub-systems (modules) and
– connections between sub-systems.
• 2 types of sub-systems:
– executor processing unit for changing process
control variables
– controller unit for calculating the amounts of the
changes.
A process control system must have the following process
control data:
• Controlled variable: target controlled variable such as
speed in a cruise control system or the temperature in an
auto H/A system. It has a set point which is the goal to
reach. The controlled variable data should be measured by
sensors as a feedback reference to re-calculate
manipulated variables.
• Input variable: measured input data such as the
temperature of return air in a temperature control system.
• Manipulated variable: can be adjusted by the controller.
• The input variables and manipulated variables
are applied to the execution processor which
results in a controlled variable.
• The set point and controlled variables are the
input data to the controller, the difference of the
controlled variable value from the set point value
is used to get a new manipulated value.
• Cars cruise-control systems and building
temperature control systems are good examples
of this process control software architecture type
of applications.
Data Flow in the Process Control
Architecture.
Input variables
C ontroller Process
Manipulated C ontrolled
Set Point ( s )
variables ( m) variable (c )
Æ= s Ğ c, m = f(Æ)
Process Control Architecture
• Applicable Domains
– Embedded software system involving
continuing actions.
– The system needs to maintain an output data
at a stable level.
– The system can have a set point which is the
goal the system will reach and stay at that
level.
• Benefits ( loop-back architecture )
– Better solution to the control system where no
precise formula can be used to decide the
manipulated variable.
– The software can be completely embedded in
the devices.
Summary
• The data flow architecture decomposes a system into a fixed sequence of
transformations and computations.
– There is no direct interaction between any two consecutive sub-systems except
for the exchange of data through data flow links.
– There is no data sharing among sub-systems in data flow architecture.
– It is not suitable for interactive business processing.
• 3 types of data flow architectures were discussed.
– Reading and writing I/O files drive the data flow in batch sequential architecture;
its control flow is thus explicit.
– The batch sequential architecture may cause bottlenecks because it requires
batched data as input and output.
– The pipe & filter is an incremental data transformation processing model and
runs concurrently.
– The data flow and the control flow in pipe & filter are implicit.
– The process control architecture is another type of data flow architecture where
the data is neither batched sequential nor pipelined streamed.
– The mechanism to drive the data flow comes from a set of variables that controls
the process execution.
The design guidelines for a data flow based
software system is listed here:
• Decompose the system into series of process
steps; each step takes the output of its previous
step.
• Define the output and input data formats for
each step.
• Define the data transformation in each step.
• Design pipelines if concurrency is necessary.