Search code examples
performanceperlsystemparent-child

perl script performance misbehave while calling another script


I have a perlscript 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.


Solution

  • 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;