in reply to Problem with [mod://Fork::Manager]
They say that “there’s more than one way to do it,” and I think that in the case of multiprogramming there is definitely a right way and a not-right way. Instead of launching processes and then having one parent process looking over their shoulders, launch one or more pools of processes and make each one the master of its own affairs.
For example, you could have a pool of x stage-one processes and y stage-two processes, such that both x and y are tunable parameters. A stage-one process pulls a unit of work off of some queue, performs it, and then writes a completion message to another queue. Stage-two processes are listening to that queue. And so on, right down the line.
What you have now built is a production-line. Each worker at each station does one task and does it independently. Buffered queues hold a variable amount of work-in-process. Having launched all of the processes, the parent process might have absolutely nothing further to do except to watch for termination-signals coming in from the children.: the parent does not have to “do the right thing at the right time” to keep the whole machine running smoothly. It is unpredictable from one moment to the next what task(s) will be underway and at what point of completion, but eventually all of it will come to an orderly point of conclusion.
It should of course go without saying that there are numerous complete frameworks within CPAN for implementing scenarios such as this one. You don’t have to write much; you merely have to select what works best for you and for this project. “Actum Ne Agas: Do Not Do A Thing Already Done.”
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Problem with [mod://Fork::Manager]
by Anonymous Monk on May 30, 2012 at 14:53 UTC |