Hi,
I am using perl 5.10.0 to get information from a log file and insert it into mysql 5.1.47 database. For the first execution of the program after rebooting my computer, the insertion of about 700 rows into two tables do not take more than 30 seconds. For the next execution, each row insertion take about 1minute.
Also, sometimes after several mysqld service restart, the execution return fast for only one execution.
Any idea…? please
This is the code:
sub connectDB {
my $dbaccess = DBAccess->new();
my ($driver,$db,$hostname,$user,$password) = $dbaccess->getDBInfo();
$dbops = DBOps->new($driver,$db,$hostname,$user,$password,“cbox”);
$dbh = $dbops->createHandler();
$dbh ? &printOK : &printNOK;
}
sub intilizeGettingLogs{
open (FILE,‘/var/log/OLSR.log’) or die “I could not open OLSR logs” ;
my $sth;
while(1){
my $line=<FILE>;
#36.1578s 0 [NODE 0] [10.0.0.1] 2-HOP Neighbour Set: [10.0.0.2->10.0.0.4 | 10.0.0.2->10.0.0.3]
if($line =~ /(\d{0,}\.\d{0,})(.)\[(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\]\s2-HOP Neighbour Set:\s\[(.)\]/)
{
$current_time= $1;
$nodeIP= $3;
$neighborPair=$4;
if($neighborPair eq ‘’)
{
$sth = $dbh-> prepare(“insert into OLSR_2hop_Neighbors(node_ip, n1_ip, n2_ip, time) values (?,?,?,?)”);
$sth->execute($nodeIP,‘’,‘’,$current_time);
}
else{
while ($neighborPair =~ /(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\-\>(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/g)
{
$n1= $1;
$n2= $2;
$sth= $dbh-> prepare(“insert into OLSR_2hop_Neighbors(node_ip, n1_ip, n2_ip, time) values (?,?,?,?)”);
$sth->execute($nodeIP,$n1,$n2,$current_time);
}
}
}#end if
#36.1578s 0 [NODE 0] [10.0.0.1] Computed MPR set for node 10.0.0.1: [10.0.0.2]
elsif ($line =~ /(\d{0,}\.\d{0,})(.)\[(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\]\sComputed MPR set for node\s(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}):\s\[(.*)\]/)
{
$current_time= $1 ;
$nodeIP= $3;
$MPR= $5;
if ($MPR eq ‘’)
{
$sth= $dbh-> prepare(“insert into OLSR_MPR_Info(node_ip, mpr_ip, time) values (?,?,?)”);
$sth->execute($nodeIP,‘’,$current_time);
}
else{
while ($MPR =~ /(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/g)
{
$sth = $dbh-> prepare(“insert into OLSR_MPR_Info(node_ip, mpr_ip, time) values (?,?,?)”);
$sth->execute($nodeIP,$1,$current_time);
}
}
}#end if
}# end while