fix SysVar.pm problems (maybe)
[spider.git] / perl / cluster.pl
index d82dd2e73bbd8d67aa68538a39dd19e49f6ae00e..ca73a8249e81017c3705c34689f156294d7afff8 100755 (executable)
@@ -19,6 +19,12 @@ use warnings;
 BEGIN {
        umask 002;
 
+       # take into account any local::lib that might be present
+       eval {
+               require local::lib;
+       };
+       import local::lib unless ($@);
+
        # root of directory tree for this system
        $root = "/spider";
        $root = $ENV{'DXSPIDER_ROOT'} if $ENV{'DXSPIDER_ROOT'};
@@ -59,12 +65,11 @@ BEGIN {
        $systime = time;
 }
 
-                       
-use Mojo::IOLoop;
-
 use DXVars;
 use SysVar;
 
+use Mojo::IOLoop;
+
 use Msg;
 use IntMsg;
 use Internet;
@@ -135,7 +140,7 @@ use vars qw(@inqueue $systime $starttime $lockfn @outstanding_connects
                        $clusterport $mycall $decease $is_win $routeroot $me $reqreg $bumpexisting
                        $allowdxby $dbh $dsn $dbuser $dbpass $do_xml $systime_days $systime_daystart
                        $can_encode $maxconnect_user $maxconnect_node $idle_interval $log_flush_interval
-                       $broadcast_debug
+                       $broadcast_debug 
                   );
 
 @inqueue = ();                                 # the main input queue, an array of hashes
@@ -155,6 +160,8 @@ $log_flush_interval = 2;            # interval to wait between log flushes
 
 our $ending;                                   # signal that we are ending;
 our $broadcast_debug;                  # allow broadcasting of debug info down "enhanced" user connections
+our $clssecs;                                  # the amount of cpu time the DXSpider process have consumed
+our $cldsecs;                                  # the amount of cpu time any child processes have consumed
 
 
 # send a message to call on conn and disconnect
@@ -350,77 +357,6 @@ sub AGWrestart
        AGWMsg::init(\&new_channel);
 }
 
-our $io_disconnected;
-
-sub idle_loop
-{
-       my $timenow = time;
-
-       BPQMsg::process();
-#      DXChannel::process();
-
-       #      $DB::trace = 0;
-
-       # do timed stuff, ongoing processing happens one a second
-       if ($timenow != $systime) {
-               reap() if $zombies;
-               $systime = $timenow;
-               my $days = int ($systime / 86400);
-               if ($systime_days != $days) {
-                       $systime_days = $days;
-                       $systime_daystart = $days * 86400;
-               }
-               IsoTime::update($systime);
-               DXCron::process();      # do cron jobs
-               DXCommandmode::process(); # process ongoing command mode stuff
-               DXXml::process();
-               DXProt::process();              # process ongoing ak1a pcxx stuff
-               DXConnect::process();
-               DXMsg::process();
-               DXDb::process();
-               DXUser::process();
-               DXDupe::process();
-               DXCron::process();                      # do cron jobs
-               IsoTime::update($systime);
-               DXProt::process();                      # process ongoing ak1a pcxx stuff
-               DXConnect::process();
-               DXUser::process();
-               AGWMsg::process();
-               
-               Timer::handler();
-               DXLog::flushall();
-       }
-
-       if (defined &Local::process) {
-               eval {
-                       Local::process();       # do any localised processing
-               };
-               dbg("Local::process error $@") if $@;
-       }
-
-       while ($ending) {
-               my $dxchan;
-
-               dbg("DXSpider Ending $ending");
-
-               unless ($io_disconnected++) {
-
-                       # disconnect users
-                       foreach $dxchan (DXChannel::get_all_users) {
-                               $dxchan->disconnect;
-                       }
-
-                       # disconnect nodes
-                       foreach $dxchan (DXChannel::get_all_nodes) {
-                               next if $dxchan == $main::me;
-                               $dxchan->disconnect(2);
-                       }
-                       $main::me->disconnect;
-               }
-
-               Mojo::IOLoop->stop if --$ending <= 0;
-       }
-}
 
 sub setup_start
 {
@@ -646,11 +582,112 @@ sub setup_start
        #open(DB::OUT, "|tee /tmp/aa");
 }
 
+our $io_disconnected;
+
+sub idle_loop
+{
+       BPQMsg::process();
+
+       if (defined &Local::process) {
+               eval {
+                       Local::process();       # do any localised processing
+               };
+               dbg("Local::process error $@") if $@;
+       }
+
+       while ($ending) {
+               my $dxchan;
+
+               dbg("DXSpider Ending $ending");
+
+               unless ($io_disconnected++) {
+
+                       # disconnect users
+                       foreach $dxchan (DXChannel::get_all_users) {
+                               $dxchan->disconnect;
+                       }
+
+                       # disconnect nodes
+                       foreach $dxchan (DXChannel::get_all_nodes) {
+                               next if $dxchan == $main::me;
+                               $dxchan->disconnect(2);
+                       }
+                       $main::me->disconnect;
+               }
+
+               Mojo::IOLoop->stop if --$ending <= 0;
+       }
+}
+
+sub per_sec
+{
+       my $timenow = time;
+
+       reap() if $zombies;
+       $systime = $timenow;
+       my $days = int ($systime / 86400);
+       if ($systime_days != $days) {
+               $systime_days = $days;
+               $systime_daystart = $days * 86400;
+       }
+       IsoTime::update($systime);
+       DXCron::process();      # do cron jobs
+       DXCommandmode::process(); # process ongoing command mode stuff
+       DXXml::process();
+       DXProt::process();              # process ongoing ak1a pcxx stuff
+       DXConnect::process();
+       DXMsg::process();
+       DXDb::process();
+       DXUser::process();
+       DXDupe::process();
+       DXCron::process();                      # do cron jobs
+       IsoTime::update($systime);
+       DXProt::process();                      # process ongoing ak1a pcxx stuff
+       DXConnect::process();
+       DXUser::process();
+       AGWMsg::process();
+       
+       Timer::handler();
+       DXLog::flushall();
+}
+
+sub per_10_sec
+{
+
+}
+
+
+sub per_minute
+{
+
+}
+
+sub per_10_minute
+{
+
+}
+
+sub per_hour
+{
+
+}
+
+sub per_day
+{
+
+}
 
 setup_start();
 
 my $main_loop = Mojo::IOLoop->recurring($idle_interval => \&idle_loop);
 my $log_flush_loop = Mojo::IOLoop->recurring($log_flush_interval => \&DXLog::flushall);
+my $cpusecs_loop = Mojo::IOLoop->recurring(5 => sub {my @t = times; $clssecs = $t[0]+$t[1]; $cldsecs = $t[2]+$t[3]});
+my $persec =  Mojo::IOLoop->recurring(1 => \&per_sec);
+my $per10sec =  Mojo::IOLoop->recurring(10 => \&per_10_sec);
+my $permin =  Mojo::IOLoop->recurring(60 => \&per_minute);
+my $per10min =  Mojo::IOLoop->recurring(600 => \&per_10_minute);
+my $perhour =  Mojo::IOLoop->recurring(3600 => \&per_hour);
+my $perday =  Mojo::IOLoop->recurring(86400 => \&per_day);
 
 Web::start_node();