Skip to content
Snippets Groups Projects
Commit d5ccec02 authored by Iustin Pop's avatar Iustin Pop
Browse files

Allocation routines: return list of resource stats


Currently, the allocation routines (iterateAlloc and tieredAlloc)
return only the final state of the cluster and the list of allocated
instances. For better visibility in how the cluster resources change,
we compute and return a list of cluster resources at each step, which
should be a good indicator of the cluster state. The cost of the
computation for the new resource when not used is undetectable (< 1%).

Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarBalazs Lecz <leczb@google.com>
parent f52dadb2
No related branches found
No related tags found
No related merge requests found
...@@ -748,9 +748,10 @@ iterateAlloc :: Node.List ...@@ -748,9 +748,10 @@ iterateAlloc :: Node.List
-> Instance.Instance -> Instance.Instance
-> Int -> Int
-> [Instance.Instance] -> [Instance.Instance]
-> [CStats]
-> Result (FailStats, Node.List, Instance.List, -> Result (FailStats, Node.List, Instance.List,
[Instance.Instance]) [Instance.Instance], [CStats])
iterateAlloc nl il newinst nreq ixes = iterateAlloc nl il newinst nreq ixes cstats =
let depth = length ixes let depth = length ixes
newname = printf "new-%d" depth::String newname = printf "new-%d" depth::String
newidx = length (Container.elems il) + depth newidx = length (Container.elems il) + depth
...@@ -759,10 +760,11 @@ iterateAlloc nl il newinst nreq ixes = ...@@ -759,10 +760,11 @@ iterateAlloc nl il newinst nreq ixes =
Bad s -> Bad s Bad s -> Bad s
Ok (AllocSolution { asFailures = errs, asSolutions = sols3 }) -> Ok (AllocSolution { asFailures = errs, asSolutions = sols3 }) ->
case sols3 of case sols3 of
[] -> Ok (collapseFailures errs, nl, il, ixes) [] -> Ok (collapseFailures errs, nl, il, ixes, cstats)
(xnl, xi, _, _):[] -> (xnl, xi, _, _):[] ->
iterateAlloc xnl (Container.add newidx xi il) iterateAlloc xnl (Container.add newidx xi il)
newinst nreq $! (xi:ixes) newinst nreq (xi:ixes)
(totalResources xnl:cstats)
_ -> Bad "Internal error: multiple solutions for single\ _ -> Bad "Internal error: multiple solutions for single\
\ allocation" \ allocation"
...@@ -772,17 +774,18 @@ tieredAlloc :: Node.List ...@@ -772,17 +774,18 @@ tieredAlloc :: Node.List
-> Instance.Instance -> Instance.Instance
-> Int -> Int
-> [Instance.Instance] -> [Instance.Instance]
-> [CStats]
-> Result (FailStats, Node.List, Instance.List, -> Result (FailStats, Node.List, Instance.List,
[Instance.Instance]) [Instance.Instance], [CStats])
tieredAlloc nl il newinst nreq ixes = tieredAlloc nl il newinst nreq ixes cstats =
case iterateAlloc nl il newinst nreq ixes of case iterateAlloc nl il newinst nreq ixes cstats of
Bad s -> Bad s Bad s -> Bad s
Ok (errs, nl', il', ixes') -> Ok (errs, nl', il', ixes', cstats') ->
case Instance.shrinkByType newinst . fst . last $ case Instance.shrinkByType newinst . fst . last $
sortBy (comparing snd) errs of sortBy (comparing snd) errs of
Bad _ -> Ok (errs, nl', il', ixes') Bad _ -> Ok (errs, nl', il', ixes', cstats')
Ok newinst' -> Ok newinst' ->
tieredAlloc nl' il' newinst' nreq ixes' tieredAlloc nl' il' newinst' nreq ixes' cstats'
-- | Compute the tiered spec string description from a list of -- | Compute the tiered spec string description from a list of
-- allocated instances. -- allocated instances.
......
...@@ -708,10 +708,11 @@ prop_ClusterCanTieredAlloc node inst = ...@@ -708,10 +708,11 @@ prop_ClusterCanTieredAlloc node inst =
==> ==>
let nl = makeSmallCluster node count let nl = makeSmallCluster node count
il = Container.empty il = Container.empty
in case Cluster.tieredAlloc nl il inst rqnodes [] of in case Cluster.tieredAlloc nl il inst rqnodes [] []of
Types.Bad _ -> False Types.Bad _ -> False
Types.Ok (_, _, il', ixes) -> not (null ixes) && Types.Ok (_, _, il', ixes, cstats) -> not (null ixes) &&
IntMap.size il' == length ixes IntMap.size il' == length ixes &&
length ixes == length cstats
-- | Checks that on a 4-8 node cluster, once we allocate an instance, -- | Checks that on a 4-8 node cluster, once we allocate an instance,
-- we can also evacuate it -- we can also evacuate it
...@@ -752,9 +753,9 @@ prop_ClusterAllocBalance node = ...@@ -752,9 +753,9 @@ prop_ClusterAllocBalance node =
il = Container.empty il = Container.empty
rqnodes = 2 rqnodes = 2
i_templ = createInstance Types.unitMem Types.unitDsk Types.unitCpu i_templ = createInstance Types.unitMem Types.unitDsk Types.unitCpu
in case Cluster.iterateAlloc nl' il i_templ rqnodes [] of in case Cluster.iterateAlloc nl' il i_templ rqnodes [] [] of
Types.Bad _ -> False Types.Bad _ -> False
Types.Ok (_, xnl, il', _) -> Types.Ok (_, xnl, il', _, _) ->
let ynl = Container.add (Node.idx hnode) hnode xnl let ynl = Container.add (Node.idx hnode) hnode xnl
cv = Cluster.compCV ynl cv = Cluster.compCV ynl
tbl = Cluster.Table ynl il' cv [] tbl = Cluster.Table ynl il' cv []
......
...@@ -276,7 +276,7 @@ main = do ...@@ -276,7 +276,7 @@ main = do
let bad_nodes = fst $ Cluster.computeBadItems nl il let bad_nodes = fst $ Cluster.computeBadItems nl il
stop_allocation = length bad_nodes > 0 stop_allocation = length bad_nodes > 0
result_noalloc = ([(FailN1, 1)]::FailStats, nl, il, []) result_noalloc = ([(FailN1, 1)]::FailStats, nl, il, [], [])
-- utility functions -- utility functions
let iofspec spx = Instance.create "new" (rspecMem spx) (rspecDsk spx) let iofspec spx = Instance.create "new" (rspecMem spx) (rspecDsk spx)
...@@ -295,11 +295,11 @@ main = do ...@@ -295,11 +295,11 @@ main = do
(case optTieredSpec opts of (case optTieredSpec opts of
Nothing -> return () Nothing -> return ()
Just tspec -> do Just tspec -> do
(_, trl_nl, trl_il, trl_ixes) <- (_, trl_nl, trl_il, trl_ixes, _) <-
if stop_allocation if stop_allocation
then return result_noalloc then return result_noalloc
else exitifbad (Cluster.tieredAlloc nl il (iofspec tspec) else exitifbad (Cluster.tieredAlloc nl il (iofspec tspec)
req_nodes []) req_nodes [] [])
let spec_map' = Cluster.tieredSpecMap trl_ixes let spec_map' = Cluster.tieredSpecMap trl_ixes
printAllocationMap verbose "Tiered allocation map" trl_nl trl_ixes printAllocationMap verbose "Tiered allocation map" trl_nl trl_ixes
...@@ -316,10 +316,10 @@ main = do ...@@ -316,10 +316,10 @@ main = do
-- Run the standard (avg-mode) allocation -- Run the standard (avg-mode) allocation
(ereason, fin_nl, fin_il, ixes) <- (ereason, fin_nl, fin_il, ixes, _) <-
if stop_allocation if stop_allocation
then return result_noalloc then return result_noalloc
else exitifbad (Cluster.iterateAlloc nl il reqinst req_nodes []) else exitifbad (Cluster.iterateAlloc nl il reqinst req_nodes [] [])
let allocs = length ixes let allocs = length ixes
sreason = reverse $ sortBy (comparing snd) ereason sreason = reverse $ sortBy (comparing snd) ereason
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment