From c9a56e248d0312568318fee0b758e8d59e0db215 Mon Sep 17 00:00:00 2001 From: Clint Armstrong Date: Fri, 17 Jul 2015 13:33:24 -0400 Subject: [PATCH] index and limit --- poller-service.py | 9 ++++----- sql-schema/065.sql | 2 ++ 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/poller-service.py b/poller-service.py index 0ca3b5cd99..bbcfa76172 100755 --- a/poller-service.py +++ b/poller-service.py @@ -199,7 +199,8 @@ dev_query = ('SELECT device_id, status, 'AND ( last_poll_attempted < DATE_SUB(NOW(), INTERVAL {2} SECOND ) ' ' OR last_poll_attempted IS NULL ) ' '{3} ' - 'ORDER BY next_poll asc ').format(poll_frequency, + 'ORDER BY next_poll asc ' + 'LIMIT 5 ').format(poll_frequency, discover_frequency, down_retry, poller_group) @@ -251,11 +252,9 @@ while True: # add queue lock, so we lock the next device against any other pollers # if this fails, the device is locked by another poller already if not getLock('queued.{}'.format(device_id)): - time.sleep(.5) continue if not lockFree('polling.{}'.format(device_id)): releaseLock('queued.{}'.format(device_id)) - time.sleep(.5) continue if next_poll and next_poll > datetime.now(): @@ -278,9 +277,9 @@ while True: # If we made it this far, break out of the loop and query again. break - # Looping with no break causes the service to be killed by init. # This point is only reached if the query is empty, so sleep half a second before querying again. time.sleep(.5) - # Make sure we're not holding any device queue locks in this connection before querying again. + # Make sure we're not holding any device queue locks in this connection before querying again + # by locking a different string. getLock('unlock.{}'.format(config['distributed_poller_name'])) diff --git a/sql-schema/065.sql b/sql-schema/065.sql index ab64beca95..4fb76d358d 100644 --- a/sql-schema/065.sql +++ b/sql-schema/065.sql @@ -1,3 +1,5 @@ DELETE n1 FROM pollers n1, pollers n2 WHERE n1.last_polled < n2.last_polled and n1.poller_name = n2.poller_name; ALTER TABLE pollers ADD PRIMARY KEY (poller_name); ALTER TABLE `devices` ADD `last_poll_attempted` timestamp NULL DEFAULT NULL AFTER `last_polled`; +ALTER TABLE `devices` ADD INDEX `last_polled` (`last_polled`); +ALTER TABLE `devices` ADD INDEX `last_poll_attempted` (`last_poll_attempted`);