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

Implement oneline-output for hbal

parent 9b9a5931
No related branches found
No related tags found
No related merge requests found
...@@ -23,6 +23,7 @@ import Utils ...@@ -23,6 +23,7 @@ import Utils
data Options = Options data Options = Options
{ optShowNodes :: Bool { optShowNodes :: Bool
, optShowCmds :: Bool , optShowCmds :: Bool
, optOneline :: Bool
, optNodef :: FilePath , optNodef :: FilePath
, optInstf :: FilePath , optInstf :: FilePath
, optMaxRounds :: Int , optMaxRounds :: Int
...@@ -34,6 +35,7 @@ defaultOptions :: Options ...@@ -34,6 +35,7 @@ defaultOptions :: Options
defaultOptions = Options defaultOptions = Options
{ optShowNodes = False { optShowNodes = False
, optShowCmds = False , optShowCmds = False
, optOneline = False
, optNodef = "nodes" , optNodef = "nodes"
, optInstf = "instances" , optInstf = "instances"
, optMaxRounds = -1 , optMaxRounds = -1
...@@ -44,11 +46,12 @@ defaultOptions = Options ...@@ -44,11 +46,12 @@ defaultOptions = Options
we find a valid solution or we exceed the maximum depth. we find a valid solution or we exceed the maximum depth.
-} -}
iterateDepth :: Cluster.Table iterateDepth :: Cluster.Table -- The starting table
-> Int -- ^ Current round -> Int -- ^ Current round
-> Int -- ^ Max rounds -> Int -- ^ Max rounds
-> IO Cluster.Table -> Bool -- ^ Wheter to be silent
iterateDepth ini_tbl cur_round max_rounds = -> IO Cluster.Table -- The resulting table
iterateDepth ini_tbl cur_round max_rounds oneline =
let Cluster.Table _ ini_il ini_cv ini_plc = ini_tbl let Cluster.Table _ ini_il ini_cv ini_plc = ini_tbl
all_inst = Container.elems ini_il all_inst = Container.elems ini_il
fin_tbl = Cluster.checkMove ini_tbl all_inst fin_tbl = Cluster.checkMove ini_tbl all_inst
...@@ -58,7 +61,7 @@ iterateDepth ini_tbl cur_round max_rounds = ...@@ -58,7 +61,7 @@ iterateDepth ini_tbl cur_round max_rounds =
allowed_next = (max_rounds < 0 || cur_round < max_rounds) allowed_next = (max_rounds < 0 || cur_round < max_rounds)
in in
do do
printf " - round %d: " cur_round unless oneline $ printf " - round %d: " cur_round
hFlush stdout hFlush stdout
let msg = let msg =
if fin_cv < ini_cv then if fin_cv < ini_cv then
...@@ -71,11 +74,12 @@ iterateDepth ini_tbl cur_round max_rounds = ...@@ -71,11 +74,12 @@ iterateDepth ini_tbl cur_round max_rounds =
(fin_plc_len - ini_plc_len) (fin_plc_len - ini_plc_len)
else else
"no improvement, stopping\n" "no improvement, stopping\n"
putStr msg unless oneline $ do
hFlush stdout putStr msg
hFlush stdout
(if fin_cv < ini_cv then -- this round made success, try deeper (if fin_cv < ini_cv then -- this round made success, try deeper
if allowed_next if allowed_next
then iterateDepth fin_tbl (cur_round + 1) max_rounds then iterateDepth fin_tbl (cur_round + 1) max_rounds oneline
-- don't go deeper, but return the better solution -- don't go deeper, but return the better solution
else return fin_tbl else return fin_tbl
else else
...@@ -90,6 +94,9 @@ options = ...@@ -90,6 +94,9 @@ options =
, Option ['C'] ["print-commands"] , Option ['C'] ["print-commands"]
(NoArg (\ opts -> opts { optShowCmds = True })) (NoArg (\ opts -> opts { optShowCmds = True }))
"print the ganeti command list for reaching the solution" "print the ganeti command list for reaching the solution"
, Option ['o'] ["oneline"]
(NoArg (\ opts -> opts { optOneline = True }))
"print the ganeti command list for reaching the solution"
, Option ['n'] ["nodes"] , Option ['n'] ["nodes"]
(ReqArg (\ f opts -> opts { optNodef = f }) "FILE") (ReqArg (\ f opts -> opts { optNodef = f }) "FILE")
"the node list FILE" "the node list FILE"
...@@ -130,6 +137,7 @@ main = do ...@@ -130,6 +137,7 @@ main = do
cmd_args <- System.getArgs cmd_args <- System.getArgs
(opts, _) <- parseOpts cmd_args (opts, _) <- parseOpts cmd_args
let oneline = optOneline opts
let (node_data, inst_data) = let (node_data, inst_data) =
case optMaster opts of case optMaster opts of
"" -> (readFile $ optNodef opts, "" -> (readFile $ optNodef opts,
...@@ -140,11 +148,12 @@ main = do ...@@ -140,11 +148,12 @@ main = do
(nl, il, ktn, kti) <- liftM2 Cluster.loadData node_data inst_data (nl, il, ktn, kti) <- liftM2 Cluster.loadData node_data inst_data
printf "Loaded %d nodes, %d instances\n" unless oneline $ printf "Loaded %d nodes, %d instances\n"
(Container.size nl) (Container.size nl)
(Container.size il) (Container.size il)
let (bad_nodes, bad_instances) = Cluster.computeBadItems nl il let (bad_nodes, bad_instances) = Cluster.computeBadItems nl il
printf "Initial check done: %d bad nodes, %d bad instances.\n" unless oneline $ printf
"Initial check done: %d bad nodes, %d bad instances.\n"
(length bad_nodes) (length bad_instances) (length bad_nodes) (length bad_instances)
when (length bad_nodes > 0) $ do when (length bad_nodes > 0) $ do
...@@ -158,21 +167,21 @@ main = do ...@@ -158,21 +167,21 @@ main = do
let ini_cv = Cluster.compCV nl let ini_cv = Cluster.compCV nl
ini_tbl = Cluster.Table nl il ini_cv [] ini_tbl = Cluster.Table nl il ini_cv []
printf "Initial coefficients: overall %.8f, %s\n" unless oneline $ printf "Initial coefficients: overall %.8f, %s\n"
ini_cv (Cluster.printStats nl) ini_cv (Cluster.printStats nl)
putStrLn "Trying to minimize the CV..." unless oneline $ putStrLn "Trying to minimize the CV..."
fin_tbl <- iterateDepth ini_tbl 1 (optMaxRounds opts) fin_tbl <- iterateDepth ini_tbl 1 (optMaxRounds opts) oneline
let (Cluster.Table fin_nl _ fin_cv fin_plc) = fin_tbl let (Cluster.Table fin_nl _ fin_cv fin_plc) = fin_tbl
ord_plc = reverse fin_plc ord_plc = reverse fin_plc
printf "Final coefficients: overall %.8f, %s\n" unless oneline $ printf "Final coefficients: overall %.8f, %s\n"
fin_cv fin_cv
(Cluster.printStats fin_nl) (Cluster.printStats fin_nl)
printf "Solution length=%d\n" (length ord_plc) unless oneline $ printf "Solution length=%d\n" (length ord_plc)
let (sol_strs, cmd_strs) = Cluster.printSolution il ktn kti ord_plc let (sol_strs, cmd_strs) = Cluster.printSolution il ktn kti ord_plc
putStr $ unlines $ sol_strs unless oneline $ putStr $ unlines $ sol_strs
when (optShowCmds opts) $ when (optShowCmds opts) $
do do
putStrLn "" putStrLn ""
...@@ -187,3 +196,6 @@ main = do ...@@ -187,3 +196,6 @@ main = do
putStrLn $ Cluster.printNodes ktn fin_nl putStrLn $ Cluster.printNodes ktn fin_nl
printf "Original: mem=%d disk=%d\n" orig_mem orig_disk printf "Original: mem=%d disk=%d\n" orig_mem orig_disk
printf "Final: mem=%d disk=%d\n" final_mem final_disk printf "Final: mem=%d disk=%d\n" final_mem final_disk
when oneline $ do
printf "%.8f %d %.8f %8.3f\n"
ini_cv (length ord_plc) fin_cv (ini_cv / fin_cv)
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