Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

[OT] Software Architecture - Pipe and Filter

by trippledubs (Deacon)
on Feb 09, 2016 at 20:40 UTC ( [id://1154768]=perlquestion: print w/replies, xml ) Need Help??

trippledubs has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks,

Is "Pipe and Filter" a real thing? We are learning about it in school, but I have my doubts. It is mostly hand wavy and any questions I ask are usually answered by 'depends on implementation'. The concept seems sufficiently vague that it could mean just chaining a bunch of Unix operations together using proc1(stdout) -> stdin(proc2) OR a legitimate software pattern in use today that achieves some higher degree of concurrency OR anything else OR nothing.

The assignment leads me down the road of Java Spliterators and/or streams, but I am wondering if there is a Perl equivalent.

I think it is originally from this 3.5 star 2 cent book Software Architecture: Perspectives on an Emerging Discipline. ISBN 9780131829572

Replies are listed 'Best First'.
Re: [OT] Software Architecture - Pipe and Filter
by MidLifeXis (Monsignor) on Feb 09, 2016 at 20:51 UTC

    Immediately, map, grep, Iterators, and a couple of other things come to mind. Are those concepts what you are referring to?

    --MidLifeXis

      Data Source ->Pipe -----> Filter ----->Filter --------->DataSink
                                  |                              ^
                                  |                              |
                                  |                              |
                                  ->---------Filter--------------^
      
      

      So in Perl list context gives the ability as with Unix pipes to pass from one filter to the next, but the list is completed before it goes on to the next stage, there is no concurrency, right? Even though it seems like there should be. Trying to find a good example:  map { $_^2 } grep { isPrime($_) } grep processes the whole list before map processes the first element? Why?

      I guess the equivalent Perl5 is to create an iterator and threads and one thread pushes onto the queue and another one takes off the queue? So you have essentially a bucket brigade of threads. Each thread performs a filtering process and passes on to the next filter. So what is the approach to scale this idea so that each filter can be replaced / modified / added / deleted?

      I found this paper: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3534.html And also the Perl6 Documentation (sorry) talks about concurrency - http://doc.perl6.org/language/concurrency as in the language itself supports this paradigm of programming with Promises and Supplies -- maybe. Is there some kind of equivalent feature in Perl 5? Maybe this: https://github.com/skaji/Process-Pipeline

      Basically map and grep but acting in parallel, asynchronously, rather than in sequence.

        I guess the equivalent Perl5 is to create an iterator and threads and one thread pushes onto the queue and another one takes off the queue? So you have essentially a bucket brigade of threads. Each thread performs a filtering process and passes on to the next filter. So what is the approach to scale this idea so that each filter can be replaced / modified / added / deleted?

        Unfortunately, the overhead of Perl's implementation of shared data is such that passing individual pieces of data between threads becomes prohibitively expensive.

        This can be mitigated to some extent by batching the individual elements into chunks. This is fairly easy to do using a wrapper class over the Thread::Queue module; or better yet, a custom queue module that avoids locking contention by batching to a non-shared buffer and only locking when a buffer is ready to be exchanged.

        Another alternative it to use either pipes or sockets for the transfer of data; both of which do their own batching (buffering), but unless you carefully design the size of the elements to fit those buffers, it can lead to less than optimal transfers because of elements straddling buffer boundaries.

        The fastest, most efficient solution is to drop into C for the queue, and bypass Perl's shared memory entirely. Unfortunately, the per thread, memory allocation pool model employed by threaded perl's makes this far more difficult to realise correctly than it should be.


        With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
        In the absence of evidence, opinion is indistinguishable from prejudice.
        > Not thinking that is going to provide timely results. What kind of programming solves those kinds of problems.

        I've been told that the go-language is good in such things, but can't provide much insight.

        Cheers Rolf
        (addicted to the Perl Programming Language and ☆☆☆☆ :)
        Je suis Charlie!

Re: [OT] Software Architecture - Pipe and Filter
by LanX (Saint) on Feb 09, 2016 at 20:53 UTC
    > The concept seems sufficiently vague that it could mean just chaining a bunch ...

    Actually your question is pretty vague, but the first things that come to mind in Perl are map and grep ...

    does it help?

    Cheers Rolf
    (addicted to the Perl Programming Language and ☆☆☆☆ :)
    Je suis Charlie!

      Thanks for answering, but I think more about concurrent processing. Since I've just been introduced to it, it is difficult to really explain. One of the examples in class is like lets say you are investigating a bombing and you have 20 different camera surveillance tapes. You need to get all this data from these tapes and presumably some other kind of sensor input and then at some point compare against the bad guy catalog.
      my @suspects = grep { isBadGuy($_)} map { matchFace{$_} } @{$surveillanceTapes->{mainSt}},@{$surveillanceTapes->{oakStreet}}
      Not thinking that is going to provide timely results. What kind of programming solves those kinds of problems. Re^2: [OT] Software Architecture - Pipe and Filter
Re: [OT] Software Architecture - Pipe and Filter
by iguanodon (Priest) on Feb 09, 2016 at 21:25 UTC
    It's a real thing. At the *nix command line chaining different programs together with pipes is a common idiom. Spring Integration is an example of a Java framework that implements this pattern.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1154768]
Approved by GotToBTru
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (5)
As of 2024-03-28 11:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found