我已经尝试过 Perl fork manager 和 DBI 。但我收到错误DBD::mysql::st execute failed: Lost connection to MySQL server during query 。
这里是示例代码:我想在低值到高值之间进行查询(我已经吐出 int 10k 记录)
use Parallel::ForkManager;
my $pm = new Parallel::ForkManager(50);
my $db = krish::DB->new or die $!; # its has all connection details
while ( $low < $high ) {
# Some value manipulation
my $pid = $pm->start and next;
#db_execution returns execution
while ( my $sth = db_execution ( $db, $low , $high ) ) {
...
#fetch row operation
...
}
$pm->finish;
}
sub db_execution {
...
my $dbh = $db->connect( 'students' ) or die $!;
my $sth = $dbh->prepare( $sql ) or die "$!:" . $dbh->errstr;
$sth->execute or die "$!:" . $sth->errstr;
...
}
相同的代码在没有并行处理的情况下执行。问题是什么?这是怎么解决的?