Handle correctly offline nodes in cluster scoring
authorIustin Pop <iustin@google.com>
Sat, 21 Mar 2009 14:48:12 +0000 (15:48 +0100)
committerIustin Pop <iustin@google.com>
Sat, 21 Mar 2009 14:48:12 +0000 (15:48 +0100)
This patch changes two things with regard to offline nodes:
  - first, it only calculates the various coefficients across online
nodes
  - second, it adds a new score denoting the percentage of instances
which live on such nodes

The first change allows correct score computation in presence of offline
nodes (whose properties we don't need to take into account), while the
second change actively evacuates offline nodes.

Ganeti/HTools/Cluster.hs

index ba32d4c..b44cc3b 100644 (file)
@@ -646,10 +646,11 @@ printNodes ktn nl =
     in unlines $ (header:map (uncurry helper) snl')
 
 -- | Compute the mem and disk covariance.
-compDetailedCV :: NodeList -> (Double, Double, Double, Double)
+compDetailedCV :: NodeList -> (Double, Double, Double, Double, Double)
 compDetailedCV nl =
     let
-        nodes = Container.elems nl
+        all_nodes = Container.elems nl
+        (offline, nodes) = partition Node.offline all_nodes
         mem_l = map Node.p_mem nodes
         dsk_l = map Node.p_dsk nodes
         mem_cv = varianceCoeff mem_l
@@ -658,19 +659,25 @@ compDetailedCV nl =
         n1_score = (fromIntegral n1_l) / (fromIntegral $ length nodes)
         res_l = map Node.p_rem nodes
         res_cv = varianceCoeff res_l
-    in (mem_cv, dsk_cv, n1_score, res_cv)
+        offline_inst = sum . map (\n -> (length . Node.plist $ n) +
+                                        (length . Node.slist $ n)) $ offline
+        online_inst = sum . map (\n -> (length . Node.plist $ n) +
+                                       (length . Node.slist $ n)) $ nodes
+        off_score = (fromIntegral offline_inst) /
+                    (fromIntegral $ online_inst + offline_inst)
+    in (mem_cv, dsk_cv, n1_score, res_cv, off_score)
 
 -- | Compute the 'total' variance.
 compCV :: NodeList -> Double
 compCV nl =
-    let (mem_cv, dsk_cv, n1_score, res_cv) = compDetailedCV nl
-    in mem_cv + dsk_cv + n1_score + res_cv
+    let (mem_cv, dsk_cv, n1_score, res_cv, off_score) = compDetailedCV nl
+    in mem_cv + dsk_cv + n1_score + res_cv + off_score
 
 printStats :: NodeList -> String
 printStats nl =
-    let (mem_cv, dsk_cv, n1_score, res_cv) = compDetailedCV nl
-    in printf "f_mem=%.8f, r_mem=%.8f, f_dsk=%.8f, n1=%.3f"
-       mem_cv res_cv dsk_cv n1_score
+    let (mem_cv, dsk_cv, n1_score, res_cv, off_score) = compDetailedCV nl
+    in printf "f_mem=%.8f, r_mem=%.8f, f_dsk=%.8f, n1=%.3f, uf=%.3f"
+       mem_cv res_cv dsk_cv n1_score off_score
 
 -- Balancing functions