Pipes and Filters
Pipes and Filters
Pipes and Filters
• There are different destinations for output data (files, network, programs)
Solution
Data
Pipe Filter Pipe Filter Pipe Data Sink
Source
Pipe
-Transfers data
-Buffers data
-Synchronizes active neighbors
Write(data)
Transform(data)
Write(data)
Transform(data)
Write(data)
Dynamic Behavior : Scenario II
Data
Pipe Filter Pipe Filter Pipe Data Sink
Source
Read
Read
Read
data
Transform(data)
data
Transform(data)
data
Dynamic Behavior : Scenario III
Data
Pipe Filter Pipe Filter Pipe Data Sink
Source
Read
Read
data
Transform(data)
data
Transform(data)
Write(data)
Dynamic Behavior : Scenario IV Buffering Pipe
Data
Pipe Filter Pipe Filter Pipe Data Sink
Source
Read Read
data
Transform(data)
Write(data)
Read data
Transform(data)
data
Transform(data) Write(data)
Write(data)
Read
data
Transform(data)
Write(data)
Implementation
• Divide the system into a sequence of processing stages
fall.txt
win.txt
Known Uses: Image Processing
Source File Known Uses: Compilers
ASCII Text
Lexical Analyzer
Token Stream
Parser
Semantic Analysis
Code Generator
Object Code
Optimizer
Object File
Consequences
• Very flexible
– Filters can be reused and recombined in arbitrary ways
– Individual filters can be easily replaced (e.g., plug in a different
kind of compression)
• No intermediate files necessary between processing stages
• Benefits from efficiencies inherent in parallel processing (multiple
active components)
• Some filters don’t produce any output until they've consumed all of
their input (e.g., sort), which is not conducive to parallelism
• Data transfer and context switching between processes and threads can
be expensive