mcogan1966 has asked for the wisdom of the Perl Monks concerning the following question:
@gets contains a list of outside perl programs that are to be called, where the response is printed back to the main program. Everything works as it should. The forked processes merrily create their children and run concurrently. But I'm running into a performance issue.$pid = open($firsh_child, "-|"); if ($pid) { while (<$first_child>) { $lines .= $_; } } else { foreach (@gets) { $i = 0; $cpid[$i] = fork; unless ($cpid[$i]) { print `perl $_`; exit; } $i++; } exit; }
If I run one program, running time is usually 1-3 seconds. However, if I pass a number of programs, the speed of each program drops dramatically, frequently double or more the time to run each program. So, instead of having a process take 1-3 seconds, it'll take 2-6, sometimes more. In fact, once the number of called programs exceeds 4, the programs called last tend to take 6-8 seconds to run.
I've considered the fact that this may be a memory related issue, but I don't know how to check the memory usage while this is running (UNIX environment). I'd prefer to have something that can print to STDERR while running so that I can check values while the main program runs.
Anyone out there with any code tuning experience that can give me some pointers here?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Code and Process Efficency
by Roger (Parson) on Dec 29, 2003 at 20:24 UTC | |
by BUU (Prior) on Dec 29, 2003 at 20:50 UTC | |
by Zaxo (Archbishop) on Dec 29, 2003 at 21:07 UTC | |
|
Re: Code and Process Efficency
by Zaxo (Archbishop) on Dec 29, 2003 at 20:51 UTC | |
by edan (Curate) on Dec 30, 2003 at 06:15 UTC | |
|
Re: Code and Process Efficency
by sgifford (Prior) on Dec 29, 2003 at 21:26 UTC | |
|
Re: Code and Process Efficency
by dominix (Deacon) on Dec 30, 2003 at 01:23 UTC | |
by mcogan1966 (Monk) on Dec 30, 2003 at 20:15 UTC | |
|
Re: Code and Process Efficency
by bl0rf (Pilgrim) on Dec 30, 2003 at 03:07 UTC | |
by mcogan1966 (Monk) on Dec 30, 2003 at 12:42 UTC |