Reduce READ_FREQ and TIMEOUT for watch-file

The watch-file option currently relies on pyinotify which makes
use of select.poll. This is eventlet incompatible so it blocks
the whole thread for TIMEOUT milliseconds every READ_FREQ seconds.

This meant that an agent/service using this option is blocked for
500 milliseconds every 1 second.

Until a non-blocking alternative can be found, this adjusts the
READ_FREQ and TIMEOUT params on the FastWatchedFileHandler to
3 and 5 respectively. So every 3 seconds, it will block for 5
milliseconds so only 0.16% of time is lost instead of 50%.

Change-Id: I6fdc0a3f1eaae39eb86440c6c4b07ca8d91f2462
Partial-Bug: #1583270
This commit is contained in:
Kevin Benton 2016-05-13 01:52:59 -07:00
parent ed582b1087
commit 6a36cffd9f
2 changed files with 4 additions and 4 deletions

View File

@ -848,13 +848,13 @@ class FastWatchedFileHandlerTestCase(BaseTestCase):
log_path = self._config()
os_level_dst, log_path_dst = tempfile.mkstemp()
os.rename(log_path, log_path_dst)
time.sleep(2)
time.sleep(6)
self.assertTrue(os.path.exists(log_path))
def test_remove(self):
log_path = self._config()
os.remove(log_path)
time.sleep(2)
time.sleep(6)
self.assertTrue(os.path.exists(log_path))

View File

@ -61,12 +61,12 @@ class FastWatchedFileHandler(logging.handlers.WatchedFileHandler, object):
Watching thread sleeps max(0, READ_FREQ - (TIMEOUT / 1000)) seconds.
"""
READ_FREQ = 1
READ_FREQ = 5
"""Poll timeout in milliseconds.
See https://docs.python.org/2/library/select.html#select.poll.poll"""
TIMEOUT = 500
TIMEOUT = 5
def __init__(self, logpath, *args, **kwargs):
self._log_file = os.path.basename(logpath)