Commit 9bb5721c authored by Iustin Pop's avatar Iustin Pop
Browse files

htools: rework compCV so that we can use [Node] too



In some cases, we have a [Node.Node] list, instead of a Node.List
structure. Instead of converting [Node.Node] to the latter, let's
rework compCV and add a compCVNodes such that we skip this
(potentially expensive) step.

This already allows a simplification in a unittest, and will simplify
consumers of Node.computeGroups.
Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarGuido Trotter <ultrotter@google.com>
parent 2f4c951e
......@@ -52,6 +52,7 @@ module Ganeti.HTools.Cluster
, doNextBalance
, tryBalance
, compCV
, compCVNodes
, compDetailedCV
, printStats
, iMoveToJob
......@@ -283,10 +284,9 @@ detailedCVWeights :: [Double]
detailedCVWeights = map fst detailedCVInfo
-- | Compute the mem and disk covariance.
compDetailedCV :: Node.List -> [Double]
compDetailedCV nl =
compDetailedCV :: [Node.Node] -> [Double]
compDetailedCV all_nodes =
let
all_nodes = Container.elems nl
(offline, nodes) = partition Node.offline all_nodes
mem_l = map Node.pMem nodes
dsk_l = map Node.pDsk nodes
......@@ -328,8 +328,13 @@ compDetailedCV nl =
, pri_tags_score ]
-- | Compute the /total/ variance.
compCVNodes :: [Node.Node] -> Double
compCVNodes = sum . zipWith (*) detailedCVWeights . compDetailedCV
-- | Wrapper over 'compCVNodes' for callers that have a 'Node.List'.
compCV :: Node.List -> Double
compCV = sum . zipWith (*) detailedCVWeights . compDetailedCV
compCV = compCVNodes . Container.elems
-- | Compute online nodes from a 'Node.List'.
getOnline :: Node.List -> [Node.Node]
......@@ -1164,7 +1169,7 @@ printInsts nl il =
-- | Shows statistics for a given node list.
printStats :: Node.List -> String
printStats nl =
let dcvs = compDetailedCV nl
let dcvs = compDetailedCV $ Container.elems nl
(weights, names) = unzip detailedCVInfo
hd = zip3 (weights ++ repeat 1) (names ++ repeat "unknown") dcvs
formatted = map (\(w, header, val) ->
......
......@@ -810,9 +810,8 @@ prop_Score_Zero node =
(not (Node.offline node) && not (Node.failN1 node) && (count > 0) &&
(Node.tDsk node > 0) && (Node.tMem node > 0)) ==>
let fn = Node.buildPeers node Container.empty
nlst = zip [1..] $ replicate count fn::[(Types.Ndx, Node.Node)]
nl = Container.fromList nlst
score = Cluster.compCV nl
nlst = replicate count fn
score = Cluster.compCVNodes nlst
-- we can't say == 0 here as the floating point errors accumulate;
-- this should be much lower than the default score in CLI.hs
in score <= 1e-12
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment