in reply to Perl threads loss of performance with system call

What is the real command that you want to call via qx or system? And did you consider IPC::Run? See Re: Cheapest way for multiple external commands for some hints.

For further experiments you may consider this variation of my MCE::Hobo example:

#!/usr/bin/env perl use strict; use warnings; use threads; use MCE::Hobo; use feature qw(say); # use constant AMOUNT => 0.0001; # use constant AMOUNT => 0.001; # use constant AMOUNT => 0.01; use constant AMOUNT => 1; use Time::HiRes qw (clock_gettime CLOCK_REALTIME); my $cores = MCE::Util::get_ncpu(); MCE::Hobo->init( max_workers => $cores ); for my $id ( 1 .. 50 ) { my $hobo = MCE::Hobo->create( \&mysub, $id ); my $realtime = clock_gettime(CLOCK_REALTIME); say qq($realtime $id ) . $hobo -> pid(); } # MCE::Hobo->wait_all(); sub mysub { # my $id = shift; # say $id; for ( 1 .. 10 ) { # qx( sleep @{[ AMOUNT ]};) sleep (AMOUNT); } } __END__

Moreover, I am of the opinion that a pure Perl solution would be best.

«The Crux of the Biscuit is the Apostrophe»

Replies are listed 'Best First'.
Re^2: Perl threads loss of performance with system call
by daniel85 (Novice) on Jul 13, 2021 at 20:41 UTC
    What "a pure perl solution" would be? Cause the program I have to call is a program that performs a very specific analysis, and I cannot just rewrite it in Perl. Also, if you take my code, and replace the backticks with qx or system, the result is always the same.

      I guess you are a little bit resistant to advice. «Beratungsresistent» as we say in German. Please provide more details. Else I abandon all hope. Best regards, Karl

      «The Crux of the Biscuit is the Apostrophe»

        I do not understand what the importance of the "exact program" is, as other commands (such as echo) replicate the issue. But that said, this is the program: RNAfold from the ViennaRNA suite (https://www.tbi.univie.ac.at/RNA/).