S
SSS Develop
Hello,
I am working on some data crunching/migration of data. Data is in postgresql database.
The rows of data from where I am reading are more than 20 milions.
While working on this data with normal (linear way) it is taking more than 2 days time to handle this data
I thought of using Parrallel::ForkManager Perl module. Please help me optimize/improve following program.
-------------
use strict;
use warnings
use DBI;
use Parallel::ForkManager;
my $MAX = 100;
my $pm = Parallel::ForkManager->new($MAX);
my $dbh = DBI->connect( "DBI
g:dbname=" . 'postgres' . ";host=" . '192.168.1.1', "postgres", "postgres" ) or die DBI->errstr;
my $query = $dbh->prepare("select id from secrete_records");
$query->execute();
while ( my $record = $query->fetchrow_hashref() ) {
my $pid = $pm->start and next;
# creating new Database connection
my $dbh_internal = DBI->connect( "DBI
g:dbname=" . 'postgres' . ";host=" . '192.168.1.1', "postgres", "postgres" ) or die DBI->errstr;
my $query_internal = $dbh_internal("select id, record_one, record_two from secrete_records where id=?")
$query_internal->execute($record);
//
// do some activity (includes insert, update in secrete_records_archives and other relavent tables from same database
$dbh_internal->disconnect()
$pm->finish()
}
$dbh->disconnect();
------------
Note:
I am creating multiple connections with Database ($dbh, $dbh_internal). Not sure if that's required. I tried to use one connection but it trows error. Its related to SSL
though I am not using database connection in SSL mode.
Any other ways to handle such large number of data in Perl?
thank you,
---SSS
I am working on some data crunching/migration of data. Data is in postgresql database.
The rows of data from where I am reading are more than 20 milions.
While working on this data with normal (linear way) it is taking more than 2 days time to handle this data
I thought of using Parrallel::ForkManager Perl module. Please help me optimize/improve following program.
-------------
use strict;
use warnings
use DBI;
use Parallel::ForkManager;
my $MAX = 100;
my $pm = Parallel::ForkManager->new($MAX);
my $dbh = DBI->connect( "DBI
my $query = $dbh->prepare("select id from secrete_records");
$query->execute();
while ( my $record = $query->fetchrow_hashref() ) {
my $pid = $pm->start and next;
# creating new Database connection
my $dbh_internal = DBI->connect( "DBI
my $query_internal = $dbh_internal("select id, record_one, record_two from secrete_records where id=?")
$query_internal->execute($record);
//
// do some activity (includes insert, update in secrete_records_archives and other relavent tables from same database
$dbh_internal->disconnect()
$pm->finish()
}
$dbh->disconnect();
------------
Note:
I am creating multiple connections with Database ($dbh, $dbh_internal). Not sure if that's required. I tried to use one connection but it trows error. Its related to SSL
Any other ways to handle such large number of data in Perl?
thank you,
---SSS