Commit a3eee4ad authored by Iustin Pop's avatar Iustin Pop

Parallelize the balancing computations

This small patch changes the balancing computation to work in
parallel, if possible.

While the normal linking is against the single-threaded runtime, if
the code is linked against the multi-threaded one, the balancing will
get a significant speedup (80% efficiency at 4 cores, 60% at 12 cores,
and with GC tweaks it can reach 70%+).

On the single-threaded runtime, due to the fact that we only use the
weak head normal form, it doesn't introduce any extra penalties,
neither in space nor in CPU time (or if there are, they are too small
to detect easily).
Signed-off-by: default avatarIustin Pop <>
Reviewed-by: default avatarBalazs Lecz <>
parent d5ccec02
......@@ -75,6 +75,7 @@ import Data.List
import Data.Ord (comparing)
import Text.Printf (printf)
import Control.Monad
import Control.Parallel.Strategies
import qualified Ganeti.HTools.Container as Container
import qualified Ganeti.HTools.Instance as Instance
......@@ -492,13 +493,18 @@ checkMove :: [Ndx] -- ^ Allowed target node indices
-> Table -- ^ The new solution
checkMove nodes_idx disk_moves ini_tbl victims =
let Table _ _ _ ini_plc = ini_tbl
-- we're using rwhnf from the Control.Parallel.Strategies
-- package; we don't need to use rnf as that would force too
-- much evaluation in single-threaded cases, and in
-- multi-threaded case the weak head normal form is enough to
-- spark the evaluation
tables = parMap rwhnf (checkInstanceMove nodes_idx disk_moves ini_tbl)
-- iterate over all instances, computing the best move
best_tbl =
(\ step_tbl em ->
compareTables step_tbl $
checkInstanceMove nodes_idx disk_moves ini_tbl em)
ini_tbl victims
(\ step_tbl new_tbl -> compareTables step_tbl new_tbl)
ini_tbl tables
Table _ _ _ best_plc = best_tbl
in if length best_plc == length ini_plc
then ini_tbl -- no advancement
......@@ -91,6 +91,7 @@ installed manually:
- `json <>`_
- `curl <>`_
- `network <>`_
- `parallel <>`_, version 1.x
Once these are installed, just typing *make* in the top-level directory
should be enough. If you edit the documentation sources, you will need
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