From d6be077541068d63e237ff673a799b1a0155514d Mon Sep 17 00:00:00 2001
From: Iustin Pop <iustin@google.com>
Date: Wed, 11 Mar 2009 09:08:31 +0100
Subject: [PATCH] Add two new variables in the cluster score

This patch adds two new variables to the cluster score:
  - variance of the failN1 attribute
  - variance of the reserved memory percentage

The variance of the failN1 helps make the cluster N+1 happy, whereas the
reserved memory percentage helps balance the unused memory for
redundancy on the nodes.
---
 src/Cluster.hs | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/src/Cluster.hs b/src/Cluster.hs
index 2919d638a..bef7cb616 100644
--- a/src/Cluster.hs
+++ b/src/Cluster.hs
@@ -572,7 +572,7 @@ printNodes ktn nl =
     in unlines $ map (uncurry helper) snl'
 
 -- | Compute the mem and disk covariance.
-compDetailedCV :: NodeList -> (Double, Double)
+compDetailedCV :: NodeList -> (Double, Double, Double, Double)
 compDetailedCV nl =
     let
         nodes = Container.elems nl
@@ -580,18 +580,23 @@ compDetailedCV nl =
         dsk_l = map Node.p_dsk nodes
         mem_cv = varianceCoeff mem_l
         dsk_cv = varianceCoeff dsk_l
-    in (mem_cv, dsk_cv)
+        n1_l = map (\n -> if Node.failN1 n then 1 else 0) nodes
+        n1_cv = varianceCoeff n1_l
+        res_l = map Node.p_rem nodes
+        res_cv = varianceCoeff res_l
+    in (mem_cv, dsk_cv, n1_cv, res_cv)
 
 -- | Compute the 'total' variance.
 compCV :: NodeList -> Double
 compCV nl =
-    let (mem_cv, dsk_cv) = compDetailedCV nl
-    in mem_cv + dsk_cv
+    let (mem_cv, dsk_cv, n1_score, res_cv) = compDetailedCV nl
+    in mem_cv + dsk_cv + n1_score + res_cv
 
 printStats :: NodeList -> String
 printStats nl =
-    let (mem_cv, dsk_cv) = compDetailedCV nl
-    in printf "mem=%.8f, dsk=%.8f" mem_cv dsk_cv
+    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
 
 -- Balancing functions
 
-- 
GitLab