Use the mingain options in the balancing algorithm
authorIustin Pop <iustin@google.com>
Wed, 1 Sep 2010 18:07:54 +0000 (20:07 +0200)
committerIustin Pop <iustin@google.com>
Fri, 3 Sep 2010 15:02:45 +0000 (17:02 +0200)
Also adds them in hbal.

Ganeti/HTools/Cluster.hs
Ganeti/HTools/QC.hs
hbal.hs

index d8e6de1..b1deac3 100644 (file)
@@ -497,8 +497,10 @@ doNextBalance ini_tbl max_rounds min_score =
 tryBalance :: Table       -- ^ The starting table
            -> Bool        -- ^ Allow disk moves
            -> Bool        -- ^ Only evacuate moves
+           -> Score       -- ^ Min gain threshold
+           -> Score       -- ^ Min gain
            -> Maybe Table -- ^ The resulting table and commands
-tryBalance ini_tbl disk_moves evac_mode =
+tryBalance ini_tbl disk_moves evac_mode mg_limit min_gain =
     let Table ini_nl ini_il ini_cv _ = ini_tbl
         all_inst = Container.elems ini_il
         all_inst' = if evac_mode
@@ -514,7 +516,7 @@ tryBalance ini_tbl disk_moves evac_mode =
         fin_tbl = checkMove node_idx disk_moves ini_tbl reloc_inst
         (Table _ _ fin_cv _) = fin_tbl
     in
-      if fin_cv < ini_cv
+      if fin_cv < ini_cv && (ini_cv > mg_limit || ini_cv - fin_cv >= min_gain)
       then Just fin_tbl -- this round made success, return the new table
       else Nothing
 
index 6cc36a8..5f3b0a8 100644 (file)
@@ -119,7 +119,7 @@ isNodeBig node size = Node.availDisk node > size * Types.unitDsk
                       && Node.availCpu node > size * Types.unitCpu
 
 canBalance :: Cluster.Table -> Bool -> Bool -> Bool
-canBalance tbl dm evac = isJust $ Cluster.tryBalance tbl dm evac
+canBalance tbl dm evac = isJust $ Cluster.tryBalance tbl dm evac 0 0
 
 -- * Arbitrary instances
 
diff --git a/hbal.hs b/hbal.hs
index 88c64dd..de1cfe6 100644 (file)
--- a/hbal.hs
+++ b/hbal.hs
@@ -70,6 +70,8 @@ options =
     , oMinScore
     , oMaxCpu
     , oMinDisk
+    , oMinGain
+    , oMinGainLim
     , oDiskMoves
     , oDynuFile
     , oExTags
@@ -91,15 +93,18 @@ iterateDepth :: Cluster.Table    -- ^ The starting table
              -> [MoveJob]        -- ^ Current command list
              -> Bool             -- ^ Whether to be silent
              -> Score            -- ^ Score at which to stop
+             -> Score            -- ^ Min gain limit
+             -> Score            -- ^ Min score gain
              -> Bool             -- ^ Enable evacuation mode
              -> IO (Cluster.Table, [MoveJob]) -- ^ The resulting table
                                               -- and commands
 iterateDepth ini_tbl max_rounds disk_moves nmlen imlen
-             cmd_strs oneline min_score evac_mode =
+             cmd_strs oneline min_score mg_limit min_gain evac_mode =
     let Cluster.Table ini_nl ini_il _ _ = ini_tbl
         allowed_next = Cluster.doNextBalance ini_tbl max_rounds min_score
         m_fin_tbl = if allowed_next
                     then Cluster.tryBalance ini_tbl disk_moves evac_mode
+                         mg_limit min_gain
                     else Nothing
     in
       case m_fin_tbl of
@@ -118,7 +123,7 @@ iterateDepth ini_tbl max_rounds disk_moves nmlen imlen
                        hFlush stdout
               iterateDepth fin_tbl max_rounds disk_moves
                            nmlen imlen upd_cmd_strs oneline min_score
-                           evac_mode
+                           mg_limit min_gain evac_mode
         Nothing -> return (ini_tbl, cmd_strs)
 
 -- | Formats the solution for the oneline display
@@ -273,7 +278,9 @@ main = do
 
   (fin_tbl, cmd_strs) <- iterateDepth ini_tbl (optMaxLength opts)
                          (optDiskMoves opts)
-                         nmlen imlen [] oneline min_cv (optEvacMode opts)
+                         nmlen imlen [] oneline min_cv
+                         (optMinGainLim opts) (optMinGain opts)
+                         (optEvacMode opts)
   let (Cluster.Table fin_nl fin_il fin_cv fin_plc) = fin_tbl
       ord_plc = reverse fin_plc
       sol_msg = if null fin_plc