use latest big cty.dat
[spider.git] / perl / cluster.pl
index 2cf7173f9c5cea358c8267670f27d029c07f0cf4..745ad1dd09217a5465d59240309d4efadea24ec5 100755 (executable)
@@ -123,7 +123,7 @@ use vars qw(@inqueue $systime $starttime $lockfn @outstanding_connects
                        $zombies $root @listeners $lang $myalias @debug $userfn $clusteraddr
                        $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
+                       $can_encode $maxconnect_user $maxconnect_node $idle_interval
                   );
 
 @inqueue = ();                                 # the main input queue, an array of hashes
@@ -138,16 +138,16 @@ $maxconnect_user = 3;                     # the maximum no of concurrent connections a user can ha
 $maxconnect_node = 0;                  # Ditto but for nodes. In either case if a new incoming connection
                                                                # takes the no of references in the routing table above these numbers
                                                                # then the connection is refused. This only affects INCOMING connections.
+$idle_interval = 0.100;                        # the wait between invocations of the main idle loop processing.
 
 # send a message to call on conn and disconnect
 sub already_conn
 {
        my ($conn, $call, $mess) = @_;
 
-       $conn->disable_read(1);
        dbg("-> D $call $mess\n") if isdbg('chan');
+       $conn->disable_read(1);
        $conn->send_now("D$call|$mess");
-       sleep(2);
        $conn->disconnect;
 }
 
@@ -301,6 +301,8 @@ sub cease
        }
 
        LogDbg('cluster', "DXSpider V$version, build $subversion.$build (git: $gitversion) ended");
+       dbg("bye bye everyone - bye bye");
+
        dbgclose();
        Logclose();
 
@@ -372,6 +374,8 @@ sub idle_loop
                AGWMsg::process();
                BPQMsg::process();
 
+               Timer::handler();
+
                if (defined &Local::process) {
                        eval {
                                Local::process();       # do any localised processing
@@ -491,6 +495,8 @@ my ($sigint, $sigterm);
 unless ($DB::VERSION) {
        $sigint = AnyEvent->signal(signal=>'INT', cb=> sub{$decease->send});
        $sigterm = AnyEvent->signal(signal=>'TERM', cb=> sub{$decease->send});
+#      $sigint = AnyEvent->signal(signal=>'INT', cb=> sub{AnyEvent->unloop});
+#      $sigterm = AnyEvent->signal(signal=>'TERM', cb=> sub{AnyEvent->unloop});
 }
 
 unless ($is_win) {
@@ -579,8 +585,7 @@ $script->run($main::me) if $script;
 
 #open(DB::OUT, "|tee /tmp/aa");
 
-my $idle_loop = AnyEvent->idle(cb => &idle_loop);
-
+my $per_sec = AnyEvent->timer(after => 0, interval => $idle_interval, cb => sub{idle_loop()});
 
 # main loop
 $decease->recv;