From f2eb8f0f24cb5b701a5d997741ff35beed3022df Mon Sep 17 00:00:00 2001 From: Adam Amstrong Date: Tue, 3 May 2011 11:24:50 +0000 Subject: [PATCH] make poller more fair. from lenwe. git-svn-id: http://www.observium.org/svn/observer/trunk@2219 61d68cd4-352d-0410-923a-c4978735b2b8 --- poller.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/poller.php b/poller.php index 00676668b2..2cfa7f62dc 100755 --- a/poller.php +++ b/poller.php @@ -41,7 +41,15 @@ elseif ($options['h']) if (isset($options['i']) && $options['i'] && isset($options['n'])) { - $where = "AND MOD(device_id,".$options['i'].") = '" . $options['n'] . "'"; + $where = true; // FIXME + $query = 'SELECT `device_id` FROM (SELECT @rownum :=0) r, + ( + SELECT @rownum := @rownum +1 AS rownum, `device_id` + FROM `devices` + WHERE `disabled` = 0 + ORDER BY `device_id` ASC + ) temp + WHERE MOD(temp.rownum, '.$options['i'].') = '.$options['n'].';'; $doing = $options['n'] ."/".$options['i']; } @@ -79,7 +87,11 @@ if (isset($options['d'])) echo("Starting polling run:\n\n"); $polled_devices = 0; -$device_query = mysql_query("SELECT `device_id` FROM `devices` WHERE `disabled` = 0 $where ORDER BY `device_id` ASC"); +if(!isset($query)) + $device_query = mysql_query("SELECT `device_id` FROM `devices` WHERE `disabled` = 0 $where ORDER BY `device_id` ASC"); +else + $device_query = mysql_query($query); +print mysql_error(); while ($device = mysql_fetch_assoc($device_query)) {