Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

Pipeline Architecture Implementation

I have two designs in mind for constructing a set of generalized classes for
building pipelined systems. I would be interested in your thoughts about the
two approaches.

First, I'm considering create an abstract Stage class that would accept an
input and output "stream". Each concrete Stage class would implement the
Stage's abstract methods which would do the actual work on the message. The
stage would have a single thead waiting for changes to the input stream.
Each stage would be chained together via the Stream objects. Once the stage
extracts a message from the input stream, then the message would be passed
down to the actual processing unit. The processing unit will populate an
output message. The output message would be inserted into the output stream
for further processing down stream.

or...

The second approach would still maintain a Stage class that would be the
actual message processing unit however this Stage class would not be waiting
on changes to an input stream. Therefore their would not be a thread per
stage. In place of the thread per Stage, I would create a pipeline controler
that would accept new messages into the pipeline. Once the controller
receives a message, the message would become a pipeline job that would be
assigned a thread from a thread pool. That thread would then execute each
stage of the pipeline.

I know there are lot's of details to consider with either approach, I'm
really curious about other experiences or possibly other approaches I could
consider.

Thanks,
Mike
[1698 byte] By [marsigme] at [2007-11-11 8:13:48]
# 1 Re: Pipeline Architecture Implementation
The real question is whether the results of stage N+1 depend on the results of stage N. If not, I would create a different object in a dedicated thread, and let the thread manage the transition from stage N to N+1 within the same object. Otherwise, you will need some synchronization primitives to inform each operation of the completion of the previous operation/stage. Anyway, a thread per stage seesm like overkill.
Danny at 2007-11-11 21:01:30 >
# 2 Re: Pipeline Architecture Implementation
Thanks for the feedback...

Yes, Stage N+1 is dependent on the results of Stage N. Stage N+1 would wait on the input stream, which is the output stream of Stage N. The i/o stream I've been referring to are simple queues. I have been concerned about, as you point out, is the thread explosion within the server that could occur by having too many stages. On top of too many stages there would be numerous queues which could introduce too much queuing delay.

I'm not sure which direction to go just yet...

Thanks again,
Mike M
marsigme at 2007-11-11 21:02:35 >