[vhffs-dev] [2288] vhffscron: fixed randomness in poller period

[ Thread Index | Date Index | More vhffs.org/vhffs-dev Archives ]


Revision: 2288
Author:   gradator
Date:     2015-09-06 12:59:27 +0200 (Sun, 06 Sep 2015)
Log Message:
-----------
vhffscron: fixed randomness in poller period

Main loop heartbeat is a select() which returns on incoming data, therefore
running rand() on each data input event, making rand() not random at all.

Fixed by calling rand() once and saving the result.

Modified Paths:
--------------
    trunk/vhffs-cron/src/vhffscron.pl

Modified: trunk/vhffs-cron/src/vhffscron.pl
===================================================================
--- trunk/vhffs-cron/src/vhffscron.pl	2015-08-09 12:37:17 UTC (rev 2287)
+++ trunk/vhffs-cron/src/vhffscron.pl	2015-09-06 10:59:27 UTC (rev 2288)
@@ -30,6 +30,7 @@
 # POSSIBILITY OF SUCH DAMAGE.
 
 use strict;
+use warnings;
 use utf8;
 use POSIX;
 use Fcntl ':mode';
@@ -88,6 +89,7 @@
 my %fd2jobs;
 my $read_set = new IO::Select();
 my $prevrun = 0;
+my $nextrun = time();
 
 while(1)  {
 
@@ -97,7 +99,7 @@
 		next;
 	}
 
-	if( time() - $prevrun > int(rand 10)+5 )  {
+	if( time() >= $nextrun )  {
 
 		# new jobs ?
 		my $crons = Vhffs::Robots::Cron::get_runnable_jobs( $vhffs );
@@ -118,6 +120,7 @@
 		}
 
 		$prevrun = time();
+		$nextrun = time() + int(rand 10) + 5;
 	}
 
 	foreach ( keys %jobs )  {


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/