SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Jul 2010
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    mysql works fin for the first time only??

    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

  2. #2
    SitePoint Guru
    Join Date
    Sep 2008
    Posts
    977
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'd recommend you have this moved to the perl forum. I have notified the moderator so you don't need to do anything about it.

    bazz

  3. #3
    SitePoint Evangelist
    Join Date
    Jun 2007
    Location
    North Yorkshire, UK
    Posts
    483
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Not sure IBazz was right about the move. My first thought would have been mysql or the configuration thereof.

    I am not familiar with DBAccess and can find not reference to it. Do you have any information on it?

    Are you noticing mysql or your perl app consuming CPU?

  4. #4
    SitePoint Member
    Join Date
    Jul 2010
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi all,
    Thanks for your responses.... event though i was suggested to change the forum
    Any way, the problem was that my program works as a thread in a general system...
    ans i used the same connection used in the main program. But DBI module does not accept one connection to be used in several threads. So the solution was to create a new connection inside my thread.


  5. #5
    SitePoint Guru
    Join Date
    Sep 2008
    Posts
    977
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You seem displeased Malattar.

    I suggested changing forums only because none of your post showed any MySQL.
    It was all perl and whilst it was relative to a Perl/MySQL setup, someone who specialises in MySQL wouldn't have had a baldy notion what your had written because they don't do php, let alone perl.

    I am pleased, however, you got the matter resolved, which is after all, a perl issue - the DBI::module

    bazz


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •