简体   繁体   中英

perl script performance misbehave while calling another script

I have a perl script which calls another perl script which functions normal database queries.

But sometimes when the inner script calling is so frequent then it will not inserting proper values in database, in debug I found that it was not able to fetch all the records from database which is most important before inserting the new calculated values.

I used system() method to call child script. this will wait till the child process end but then how it is possible to misbehave while the calling of child is frequently. In normal scenario main script will hold for 30 seconds which results proper executions of child script.

can anyone have any suggestion for debugging my code or any solution for this kind of issue.

Running Perl scripts for every DB insert is very ineffective.

You should notice that Perl will first compile called script (every time it has been called) - so it creates significant overhead.

Much better to use OOP and to put DB handling code into separate class - it will be compiled only once - at run time. Or you can use modules and put DB code into functions, they will be compiled only once too. Look at "use" pragma.

For example: simple programm with module

main_file.pl

use strict;
use DB_code;
DB_code::insert($data);

DB_code.pm

package DB_code;
use strict;

sub insert {
    my $data = shift;
    print "Your data has been inserted!";
}

1;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM