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

MCE and DBI - [SOLVED]

by pmamatsis (Initiate)
on May 26, 2015 at 12:51 UTC ( [id://1127823]=perlquestion: print w/replies, xml ) Need Help??

pmamatsis has asked for the wisdom of the Perl Monks concerning the following question:

Hello everybody, i would like to seek some advice for the MCE parallel library.
I have an assignment at the office that i need to use it along with one database connection per worker process.
What i am doing is...i am creating a database connection into the "main" body of my perl script in order to construct an array and then i am passing this array into the 'worker' sub.
The problem rises when into the 'worker' sub i am trying to connect to the database again in order to execute a stored procedure based on the arguments provided by the main process...i am getting a series of errors about re-defining some functions from the DBI. One of the errors is the following:

Subroutine DBI::st::ora_stmt_type redefined at C:/Perl64/site/lib/DBI. +pm line 1405, <__ANONIO__> line 2.

What am i missing about the use of the MCE library ? Any kind of advice of what i am doing wrong ?

Best regards and
thank you in advance,
Panos.

Replies are listed 'Best First'.
Re: MCE and DBI
by marioroy (Prior) on May 27, 2015 at 13:07 UTC

    Hi Panos,

    Thank you for providing a code sample. I added user_begin and user_end options. In MCE, workers call user_begin and user_end one time (before and after running). Thus, reconnecting to the DB each time is not necessary.

    e.g. { user_begin } { user_func chunk_1 } { user_func chunk_2 } ... { user_func chunk_N } { user_end }

    #!/usr/bin/perl -w use strict; use MCE; use DBD::Oracle; use DBI; sub myBegin { my ($mce) = @_; $mce->{db} = DBI->connect( "dbi:Oracle:<SERVER_NAME>", "<USERID>", "<PASSWORD>" ) || die($DBI::errstr . "\n"); return; } sub myEnd { my ($mce) = @_; $mce->{db}->disconnect; return; } sub mySub { my ($mce, $chunk_ref, $chunk_id) = @_; my $db = $mce->{db}; return; } my (@array, $mceObj, $db); $db = DBI->connect( "dbi:Oracle:<SERVER_NAME>", "<USERID>", "<PASSWORD>" ) || die($DBI::errstr . "\n"); ...do some work with the database in order to fill up ...the @array variable... $db->disconnect; $mceObj = MCE->new(max_workers => 4, input_data => \@array, user_begin => \&myBegin, user_func => \&mySub, user_end => \&myEnd); $mceObj->run;

    From reading your code, am still not sure the reason for the ora_stmt_type redefined errors stated in the initial post. Connecting one time may solve the issue.

      Hi @marioroy,
      let me thank you once more for your quick reply and assistance.
      I have tried your suggestion and it works like a charm! I am also not quite sure about the 'why' the perl runtime complaints about the DBI ora_stmt_type redefined errors but anyway...for the time being this solution is perfect !

      Best regards,
      Panos.

        That is great, especially no more DBI ora_stmt_type redefined errors.

Re: MCE and DBI
by marioroy (Prior) on May 26, 2015 at 15:17 UTC

    Without a code sample in question am not sure what to suggest other than MCE includes DBI examples (MCE-1.608/examples/sampledb/) which may be helpful.

      Hi @marioroy,
      thank you so much for your quick reply. I am sorry for not posting any code online but i didn't want for people to think that i just need somebody else to resolve my problem. :)
      The full source code for my little program is as following:

      #!/usr/bin/perl -w use strict;<br> use MCE; use DBD::Oracle; use DBI; sub mySub { my $db; $db=DBI->connect("dbi:Oracle:<SERVER_NAME>", "<USERID>", "<PASSWOR +D>") || die($DBI::errstr . "\n"); $db->disconnect; return; } my (@array, $mceObj, $db); $db=DBI->connect("dbi:Oracle:<SERVER_NAME>", "<USERID>", "<PASSWORD>") + || die($DBI::errstr . "\n");<br> ...do some work with the database in order to fill up the @array varia +ble... $db->disconnect;<br> $mceObj = MCE->new(max_workers => 4, input_data => \@array, user_func => \&mySub); $mceObj->run;
      Best regards,
      and thank you in advance
      Panagiotis Mamatsis.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1127823]
Approved by ww
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (2)
As of 2024-04-26 01:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found