Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Speeding up external command execution

by graff (Chancellor)
on Apr 14, 2014 at 00:24 UTC ( #1082171=note: print w/ replies, xml ) Need Help??


in reply to Speeding up external command execution

While RAM limitations are rarely a concern these days, it's about the only thing I can imagine that might cause the timing difference (apart from possible environment differences hinted at by soonix above) - i.e. the java process takes 5-6 seconds, given the available RAM when it's running alone, but if your perl script is running at the same time (and if it takes up a lot of RAM), then you might lose a lot of time to memory swapping (aka page faults). BrowserUK's suggestion will show you if that's the issue.

Apart from the timing issues, the logic you're using to build the command line is strange. I would have done it something like this:

my $pathstr = join( '', $outputfiles, $invoice_data_ref{actual_invoice +_id} ); my @cmdargs = ( 'java', '-jar', '/var/ww/helper_code/svg2pdf.jar', "$pathstr/master*.svg", "$pathstr/master.pdf" ); print join( ' ', 'command_str:', @cmdargs ), "\n"; # optional - just +to check $report_failure = system( @cmdargs );
My version should yield the same behavior as yours, but if, instead of using "master*.svg", you were to use the actual list of file names (that is, the names of the svg files that were just created previously in your script), like this:
my @svg_names = ( qw/master01 master02 .../; # or whatever those names + are # … create those files ... my $pathstr = join( '', $outputfiles, $invoice_data_ref{actual_invoice +_id} ); my @cmdargs = qw/java -jar /var/ww/helper_code/svg2pdf.jar/; push @cmdargs, "$pathstr/$_.svg" for ( @svg_names ); push @cmdargs, "$pathstr/master.pdf";
then the method of execution will be slightly different. If you haven't read perldoc -f system, you might find that interesting.

I expect that after you generate all those "fairly complicated SVGs", you close those file handles (i.e. make sure all the output has been flushed) before doing the system call. If those file handles are still open, perl will flush them for you when you do the system call, which might add a bit of delay.

Your description suggests that the system call is only being done once; if you were doing a lot of similar system calls in some sort of loop, then one possible cause of delay would be the extra overhead of invoking and cleaning up after a subshell on each iteration; one way to get around that (on a *n*x system) would be:

open( SH, '|-', '/bin/sh' ) or die "Can't open a shell: $!"; for my $iterator ( @whatever_set ) { print SH "command line…\n" } close SH;
But that's probably not relevant here.


Comment on Re: Speeding up external command execution
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1082171]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (7)
As of 2014-09-30 23:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (385 votes), past polls