From 01eea3422449c6c61643715d3c2e8c71c38ae6b3 Mon Sep 17 00:00:00 2001
From: Iustin Pop <iustin@google.com>
Date: Thu, 17 Jan 2013 13:04:13 +0100
Subject: [PATCH] Change the polling thread sleep behaviour

Currently, the polling thread sleeps at the end of its body; the
original reason was that when the thread initially starts, we want to
load the config immediately (in the old-style config load model).

However, now we explicitly load the config, so we can make this thread
behave like the watcher thread: sleep first, then do the work. This
model improves for example the startup of the thread, by not redoing a
config check immediately after switching to polling mode.

We also increase the max idle poll rounds interval from 2 to 3; the
new behaviour means that we revert from polling to inotify after
around one second of no changes.

Signed-off-by: Iustin Pop <iustin@google.com>
Reviewed-by: Guido Trotter <ultrotter@google.com>
---
 src/Ganeti/Confd/Server.hs | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/src/Ganeti/Confd/Server.hs b/src/Ganeti/Confd/Server.hs
index d5e1b02f5..a56c1ec4d 100644
--- a/src/Ganeti/Confd/Server.hs
+++ b/src/Ganeti/Confd/Server.hs
@@ -33,7 +33,7 @@ module Ganeti.Confd.Server
 
 import Control.Concurrent
 import Control.Exception
-import Control.Monad (forever, liftM, when, unless)
+import Control.Monad (forever, liftM, unless)
 import Data.IORef
 import Data.List
 import qualified Data.Map as M
@@ -90,7 +90,7 @@ data ServerState = ServerState
 
 -- | Maximum no-reload poll rounds before reverting to inotify.
 maxIdlePollRounds :: Int
-maxIdlePollRounds = 2
+maxIdlePollRounds = 3
 
 -- | Reload timeout in microseconds.
 configReloadTimeout :: Int
@@ -373,12 +373,12 @@ onTimeoutInner path cref state  = do
 -- notification.
 onReloadTimer :: IO Bool -> FilePath -> CRef -> MVar ServerState -> IO ()
 onReloadTimer inotiaction path cref state = do
+  threadDelay configReloadRatelimit
   logDebug "Reload timer fired"
   continue <- modifyMVar state (onReloadInner inotiaction path cref)
-  when continue $
-    do threadDelay configReloadRatelimit
-       onReloadTimer inotiaction path cref state
-  -- the inotify watch has been re-established, we can exit
+  if continue
+    then onReloadTimer inotiaction path cref state
+    else logDebug "Inotify watch active, polling thread exiting"
 
 -- | Inner onReload handler.
 --
-- 
GitLab