1 .TH HBAL 1 2009-03-23 htools "Ganeti H-tools"
3 hbal \- Cluster balancer for Ganeti
7 .B "[backend options...]"
8 .B "[algorithm options...]"
9 .B "[reporting options...]"
16 .BI "[ -m " cluster " ]"
18 .BI "[ -L[" path "] [-X]]"
20 .BI "[ -n " nodes-file " ]"
21 .BI "[ -i " instances-file " ]"
25 .BI "[ --max-cpu " cpu-ratio " ]"
26 .BI "[ --min-disk " disk-ratio " ]"
27 .BI "[ -l " limit " ]"
28 .BI "[ -e " score " ]"
29 .BI "[ -O " name... " ]"
30 .B "[ --no-disk-moves ]"
31 .BI "[ -U " util-file " ]"
35 .BI "[ -C[" file "] ]"
37 .B "[ --print-instances ]"
43 hbal is a cluster balancer that looks at the current state of the
44 cluster (nodes with their total and free disk, memory, etc.) and
45 instance placement and computes a series of steps designed to bring
46 the cluster into a better state.
48 The algorithm to do so is designed to be stable (i.e. it will give you
49 the same results when restarting it from the middle of the solution)
50 and reasonably fast. It is not, however, designed to be a perfect
51 algorithm - it is possible to make it go into a corner from which it
52 can find no improvement, because it only look one "step" ahead.
54 By default, the program will show the solution incrementally as it is
55 computed, in a somewhat cryptic format; for getting the actual Ganeti
56 command list, use the \fB-C\fR option.
60 The program works in independent steps; at each step, we compute the
61 best instance move that lowers the cluster score.
63 The possible move type for an instance are combinations of
64 failover/migrate and replace-disks such that we change one of the
65 instance nodes, and the other one remains (but possibly with changed
66 role, e.g. from primary it becomes secondary). The list is:
76 replace primary, a composite move (f, r, f)
79 failover and replace secondary, also composite (f, r)
82 replace secondary and failover, also composite (r, f)
85 We don't do the only remaining possibility of replacing both nodes
86 (r,f,r,f or the equivalent f,r,f,r) since these move needs an
87 exhaustive search over both candidate primary and secondary nodes, and
88 is O(n*n) in the number of nodes. Furthermore, it doesn't seems to
89 give better scores but will result in more disk replacements.
93 As said before, the algorithm tries to minimise the cluster score at
94 each step. Currently this score is computed as a sum of the following
99 coefficient of variance of the percent of free memory
102 coefficient of variance of the percent of reserved memory
105 coefficient of variance of the percent of free disk
108 percentage of nodes failing N+1 check
111 percentage of instances living (either as primary or secondary) on
115 coefficent of variance of the ratio of virtual-to-physical cpus (for
116 primary instaces of the node)
119 coefficients of variance of the dynamic load on the nodes, for cpus,
120 memory, disk and network
123 The free memory and free disk values help ensure that all nodes are
124 somewhat balanced in their resource usage. The reserved memory helps
125 to ensure that nodes are somewhat balanced in holding secondary
126 instances, and that no node keeps too much memory reserved for
127 N+1. And finally, the N+1 percentage helps guide the algorithm towards
128 eliminating N+1 failures, if possible.
130 Except for the N+1 failures and offline instances percentage, we use
131 the coefficient of variance since this brings the values into the same
132 unit so to speak, and with a restrict domain of values (between zero
133 and one). The percentage of N+1 failures, while also in this numeric
134 range, doesn't actually has the same meaning, but it has shown to work
137 The other alternative, using for N+1 checks the coefficient of
138 variance of (N+1 fail=1, N+1 pass=0) across nodes could hint the
139 algorithm to make more N+1 failures if most nodes are N+1 fail
140 already. Since this (making N+1 failures) is not allowed by other
141 rules of the algorithm, so the N+1 checks would simply not work
142 anymore in this case.
144 The offline instances percentage (meaning the percentage of instances
145 living on offline nodes) will cause the algorithm to actively move
146 instances away from offline nodes. This, coupled with the restriction
147 on placement given by offline nodes, will cause evacuation of such
150 The dynamic load values need to be read from an external file (Ganeti
151 doesn't supply them), and are computed for each node as: sum of
152 primary instance cpu load, sum of primary instance memory load, sum of
153 primary and secondary instance disk load (as DRBD generates write load
154 on secondary nodes too in normal case and in degraded scenarios also
155 read load), and sum of primary instance network load. An example of
156 how to generate these values for input to hbal would be to track "xm
157 list" for instance over a day and by computing the delta of the cpu
158 values, and feed that via the \fI-U\fR option for all instances (and
159 keep the other metrics as zero). For the algorithm to work, all that
160 is needed is that the values are consistent for a metric across all
161 instances (e.g. all instances use cpu% to report cpu usage, but they
162 could represent network bandwith in Gbps).
164 On a perfectly balanced cluster (all nodes the same size, all
165 instances the same size and spread across the nodes equally), all
166 values would be zero. This doesn't happen too often in practice :)
168 .SS OFFLINE INSTANCES
170 Since current Ganeti versions do not report the memory used by offline
171 (down) instances, ignoring the run status of instances will cause
172 wrong calculations. For this reason, the algorithm subtracts the
173 memory size of down instances from the free node memory of their
174 primary node, in effect simulating the startup of such instances.
176 .SS OTHER POSSIBLE METRICS
178 It would be desirable to add more metrics to the algorithm, especially
179 dynamically-computed metrics, such as:
183 CPU usage of instances
193 The options that can be passed to the program are as follows:
195 .B -C, --print-commands
196 Print the command list at the end of the run. Without this, the
197 program will only show a shorter, but cryptic output.
199 Note that the moves list will be split into independent steps, called
200 "jobsets", but only for visual inspection, not for actually
201 parallelisation. It is not possible to parallelise these directly when
202 executed via "gnt-instance" commands, since a compound command
203 (e.g. failover and replace-disks) must be executed serially. Parallel
204 execution is only possible when using the Luxi backend and the
207 The algorithm for splitting the moves into jobsets is by accumulating
208 moves until the next move is touching nodes already touched by the
209 current moves; this means we can't execute in parallel (due to
210 resource allocation in Ganeti) and thus we start a new jobset.
214 Prints the before and after node status, in a format designed to allow
215 the user to understand the node's most important parameters.
217 The node list will contain these informations:
221 a character denoting the status of the node, with '-' meaning an
222 offline node, '*' meaning N+1 failure and blank meaning a good node
228 the total node memory
231 the memory used by the node itself
234 the memory used by instances
237 amount memory which seems to be in use but cannot be determined why or
238 by which instance; usually this means that the hypervisor has some
239 overhead or that there are other reporting errors
245 the reserved node memory, which is the amount of free memory needed
255 the number of physical cpus on the node
258 the number of virtual cpus allocated to primary instances
261 number of primary instances
264 number of secondary instances
267 percent of free memory
273 ratio of virtual to physical cpus
276 the dynamic CPU load (if the information is available)
279 the dynamic memory load (if the information is available)
282 the dynamic disk load (if the information is available)
285 the dynamic net load (if the information is available)
290 Prints the before and after instance map. This is less useful as the
291 node status, but it can help in understanding instance moves.
295 Only shows a one-line output from the program, designed for the case
296 when one wants to look at multiple clusters at once and check their
299 The line will contain four fields:
304 initial cluster score
307 number of steps in the solution
313 improvement in the cluster score
319 This option (which can be given multiple times) will mark nodes as
320 being \fIoffline\fR. This means a couple of things:
325 instances won't be placed on these nodes, not even temporarily;
326 e.g. the \fIreplace primary\fR move is not available if the secondary
327 node is offline, since this move requires a failover.
330 these nodes will not be included in the score calculation (except for
331 the percentage of instances on offline nodes)
333 Note that hbal will also mark as offline any nodes which are reported
334 by RAPI as such, or that have "?" in file-based input in any numeric
339 .BI "-e" score ", --min-score=" score
340 This parameter denotes the minimum score we are happy with and alters
341 the computation in two ways:
346 if the cluster has the initial score lower than this value, then we
347 don't enter the algorithm at all, and exit with success
350 during the iterative process, if we reach a score lower than this
351 value, we exit the algorithm
353 The default value of the parameter is currently \fI1e-9\fR (chosen
358 .BI "--no-disk-moves"
359 This parameter prevents hbal from using disk move (i.e. "gnt-instance
360 replace-disks") operations. This will result in a much quicker
361 balancing, but of course the improvements are limited. It is up to the
362 user to decide when to use one or another.
366 This parameter specifies a file holding instance dynamic utilisation
367 information that will be used to tweak the balancing algorithm to
368 equalise load on the nodes (as opposed to static resource usage). The
369 file is in the format "instance_name cpu_util mem_util disk_util
370 net_util" where the "_util" parameters are interpreted as numbers and
371 the instance name must match exactly the instance as read from
372 Ganeti. In case of unknown instance names, the program will abort.
374 If not given, the default values are zero for all metrics and thus
375 dynamic utilisation has no effect on the balancing algorithm.
378 .BI "-n" nodefile ", --nodes=" nodefile
379 The name of the file holding node information (if not collecting via
380 RAPI), instead of the default \fInodes\fR file (but see below how to
381 customize the default value via the environment).
384 .BI "-i" instancefile ", --instances=" instancefile
385 The name of the file holding instance information (if not collecting
386 via RAPI), instead of the default \fIinstances\fR file (but see below
387 how to customize the default value via the environment).
391 Collect data not from files but directly from the
393 given as an argument via RAPI. If the argument doesn't contain a colon
394 (:), then it is converted into a fully-built URL via prepending
395 https:// and appending the default RAPI port, otherwise it's
396 considered a fully-specified URL and is used as-is.
400 Collect data not from files but directly from the master daemon, which
401 is to be contacted via the luxi (an internal Ganeti protocol). An
402 optional \fIpath\fR argument is interpreted as the path to the unix
403 socket on which the master daemon listens; otherwise, the default path
404 used by ganeti when installed with "--localstatedir=/var" is used.
408 When using the Luxi backend, hbal can also execute the given
409 commands. The execution method is to execute the individual jobsets
410 (see the \fI-C\fR option for details) in separate stages, aborting if
411 at any time a jobset doesn't have all jobs successful. Each step in
412 the balancing solution will be translated into exactly one Ganeti job
413 (having between one and three OpCodes), and all the steps in a jobset
414 will be executed in parallel. The jobsets themselves are executed
418 .BI "-l" N ", --max-length=" N
419 Restrict the solution to this length. This can be used for example to
420 automate the execution of the balancing.
423 .BI "--max-cpu " cpu-ratio
424 The maximum virtual-to-physical cpu ratio, as a floating point number
425 between zero and one. For example, specifying \fIcpu-ratio\fR as
426 \fB2.5\fR means that, for a 4-cpu machine, a maximum of 10 virtual
427 cpus should be allowed to be in use for primary instances. A value of
428 one doesn't make sense though, as that means no disk space can be used
432 .BI "--min-disk " disk-ratio
433 The minimum amount of free disk space remaining, as a floating point
434 number. For example, specifying \fIdisk-ratio\fR as \fB0.25\fR means
435 that at least one quarter of disk space should be left free on nodes.
439 Increase the output verbosity. Each usage of this option will increase
440 the verbosity (currently more than 2 doesn't make sense) from the
445 Decrease the output verbosity. Each usage of this option will decrease
446 the verbosity (less than zero doesn't make sense) from the default of
451 Just show the program version and exit.
455 The exist status of the command will be zero, unless for some reason
456 the algorithm fatally failed (e.g. wrong node or instance data).
460 If the variables \fBHTOOLS_NODES\fR and \fBHTOOLS_INSTANCES\fR are
461 present in the environment, they will override the default names for
462 the nodes and instances files. These will have of course no effect
467 The program does not check its input data for consistency, and aborts
468 with cryptic errors messages in this case.
470 The algorithm is not perfect.
472 The output format is not easily scriptable, and the program should
473 feed moves directly into Ganeti (either via RAPI or via a gnt-debug
478 Note that this example are not for the latest version (they don't have
483 With the default options, the program shows each individual step and
484 the improvements it brings in cluster score:
489 Loaded 20 nodes, 80 instances
490 Cluster is not N+1 happy, continuing but no guarantee that the cluster will end N+1 happy.
491 Initial score: 0.52329131
492 Trying to minimize the CV...
493 1. instance14 node1:node10 => node16:node10 0.42109120 a=f r:node16 f
494 2. instance54 node4:node15 => node16:node15 0.31904594 a=f r:node16 f
495 3. instance4 node5:node2 => node2:node16 0.26611015 a=f r:node16
496 4. instance48 node18:node20 => node2:node18 0.21361717 a=r:node2 f
497 5. instance93 node19:node18 => node16:node19 0.16166425 a=r:node16 f
498 6. instance89 node3:node20 => node2:node3 0.11005629 a=r:node2 f
499 7. instance5 node6:node2 => node16:node6 0.05841589 a=r:node16 f
500 8. instance94 node7:node20 => node20:node16 0.00658759 a=f r:node16
501 9. instance44 node20:node2 => node2:node15 0.00438740 a=f r:node15
502 10. instance62 node14:node18 => node14:node16 0.00390087 a=r:node16
503 11. instance13 node11:node14 => node11:node16 0.00361787 a=r:node16
504 12. instance19 node10:node11 => node10:node7 0.00336636 a=r:node7
505 13. instance43 node12:node13 => node12:node1 0.00305681 a=r:node1
506 14. instance1 node1:node2 => node1:node4 0.00263124 a=r:node4
507 15. instance58 node19:node20 => node19:node17 0.00252594 a=r:node17
508 Cluster score improved from 0.52329131 to 0.00252594
512 In the above output, we can see:
513 - the input data (here from files) shows a cluster with 20 nodes and
515 - the cluster is not initially N+1 compliant
516 - the initial score is 0.52329131
518 The step list follows, showing the instance, its initial
519 primary/secondary nodes, the new primary secondary, the cluster list,
520 and the actions taken in this step (with 'f' denoting failover/migrate
521 and 'r' denoting replace secondary).
523 Finally, the program shows the improvement in cluster score.
525 A more detailed output is obtained via the \fB-C\fR and \fB-p\fR options:
530 Loaded 20 nodes, 80 instances
531 Cluster is not N+1 happy, continuing but no guarantee that the cluster will end N+1 happy.
532 Initial cluster status:
533 N1 Name t_mem f_mem r_mem t_dsk f_dsk pri sec p_fmem p_fdsk
534 * node1 32762 1280 6000 1861 1026 5 3 0.03907 0.55179
535 node2 32762 31280 12000 1861 1026 0 8 0.95476 0.55179
536 * node3 32762 1280 6000 1861 1026 5 3 0.03907 0.55179
537 * node4 32762 1280 6000 1861 1026 5 3 0.03907 0.55179
538 * node5 32762 1280 6000 1861 978 5 5 0.03907 0.52573
539 * node6 32762 1280 6000 1861 1026 5 3 0.03907 0.55179
540 * node7 32762 1280 6000 1861 1026 5 3 0.03907 0.55179
541 node8 32762 7280 6000 1861 1026 4 4 0.22221 0.55179
542 node9 32762 7280 6000 1861 1026 4 4 0.22221 0.55179
543 * node10 32762 7280 12000 1861 1026 4 4 0.22221 0.55179
544 node11 32762 7280 6000 1861 922 4 5 0.22221 0.49577
545 node12 32762 7280 6000 1861 1026 4 4 0.22221 0.55179
546 node13 32762 7280 6000 1861 922 4 5 0.22221 0.49577
547 node14 32762 7280 6000 1861 922 4 5 0.22221 0.49577
548 * node15 32762 7280 12000 1861 1131 4 3 0.22221 0.60782
549 node16 32762 31280 0 1861 1860 0 0 0.95476 1.00000
550 node17 32762 7280 6000 1861 1106 5 3 0.22221 0.59479
551 * node18 32762 1280 6000 1396 561 5 3 0.03907 0.40239
552 * node19 32762 1280 6000 1861 1026 5 3 0.03907 0.55179
553 node20 32762 13280 12000 1861 689 3 9 0.40535 0.37068
555 Initial score: 0.52329131
556 Trying to minimize the CV...
557 1. instance14 node1:node10 => node16:node10 0.42109120 a=f r:node16 f
558 2. instance54 node4:node15 => node16:node15 0.31904594 a=f r:node16 f
559 3. instance4 node5:node2 => node2:node16 0.26611015 a=f r:node16
560 4. instance48 node18:node20 => node2:node18 0.21361717 a=r:node2 f
561 5. instance93 node19:node18 => node16:node19 0.16166425 a=r:node16 f
562 6. instance89 node3:node20 => node2:node3 0.11005629 a=r:node2 f
563 7. instance5 node6:node2 => node16:node6 0.05841589 a=r:node16 f
564 8. instance94 node7:node20 => node20:node16 0.00658759 a=f r:node16
565 9. instance44 node20:node2 => node2:node15 0.00438740 a=f r:node15
566 10. instance62 node14:node18 => node14:node16 0.00390087 a=r:node16
567 11. instance13 node11:node14 => node11:node16 0.00361787 a=r:node16
568 12. instance19 node10:node11 => node10:node7 0.00336636 a=r:node7
569 13. instance43 node12:node13 => node12:node1 0.00305681 a=r:node1
570 14. instance1 node1:node2 => node1:node4 0.00263124 a=r:node4
571 15. instance58 node19:node20 => node19:node17 0.00252594 a=r:node17
572 Cluster score improved from 0.52329131 to 0.00252594
574 Commands to run to reach the above solution:
576 echo gnt-instance migrate instance14
577 echo gnt-instance replace-disks -n node16 instance14
578 echo gnt-instance migrate instance14
580 echo gnt-instance migrate instance54
581 echo gnt-instance replace-disks -n node16 instance54
582 echo gnt-instance migrate instance54
584 echo gnt-instance migrate instance4
585 echo gnt-instance replace-disks -n node16 instance4
587 echo gnt-instance replace-disks -n node2 instance48
588 echo gnt-instance migrate instance48
590 echo gnt-instance replace-disks -n node16 instance93
591 echo gnt-instance migrate instance93
593 echo gnt-instance replace-disks -n node2 instance89
594 echo gnt-instance migrate instance89
596 echo gnt-instance replace-disks -n node16 instance5
597 echo gnt-instance migrate instance5
599 echo gnt-instance migrate instance94
600 echo gnt-instance replace-disks -n node16 instance94
602 echo gnt-instance migrate instance44
603 echo gnt-instance replace-disks -n node15 instance44
605 echo gnt-instance replace-disks -n node16 instance62
607 echo gnt-instance replace-disks -n node16 instance13
609 echo gnt-instance replace-disks -n node7 instance19
611 echo gnt-instance replace-disks -n node1 instance43
613 echo gnt-instance replace-disks -n node4 instance1
615 echo gnt-instance replace-disks -n node17 instance58
617 Final cluster status:
618 N1 Name t_mem f_mem r_mem t_dsk f_dsk pri sec p_fmem p_fdsk
619 node1 32762 7280 6000 1861 1026 4 4 0.22221 0.55179
620 node2 32762 7280 6000 1861 1026 4 4 0.22221 0.55179
621 node3 32762 7280 6000 1861 1026 4 4 0.22221 0.55179
622 node4 32762 7280 6000 1861 1026 4 4 0.22221 0.55179
623 node5 32762 7280 6000 1861 1078 4 5 0.22221 0.57947
624 node6 32762 7280 6000 1861 1026 4 4 0.22221 0.55179
625 node7 32762 7280 6000 1861 1026 4 4 0.22221 0.55179
626 node8 32762 7280 6000 1861 1026 4 4 0.22221 0.55179
627 node9 32762 7280 6000 1861 1026 4 4 0.22221 0.55179
628 node10 32762 7280 6000 1861 1026 4 4 0.22221 0.55179
629 node11 32762 7280 6000 1861 1022 4 4 0.22221 0.54951
630 node12 32762 7280 6000 1861 1026 4 4 0.22221 0.55179
631 node13 32762 7280 6000 1861 1022 4 4 0.22221 0.54951
632 node14 32762 7280 6000 1861 1022 4 4 0.22221 0.54951
633 node15 32762 7280 6000 1861 1031 4 4 0.22221 0.55408
634 node16 32762 7280 6000 1861 1060 4 4 0.22221 0.57007
635 node17 32762 7280 6000 1861 1006 5 4 0.22221 0.54105
636 node18 32762 7280 6000 1396 761 4 2 0.22221 0.54570
637 node19 32762 7280 6000 1861 1026 4 4 0.22221 0.55179
638 node20 32762 13280 6000 1861 1089 3 5 0.40535 0.58565
643 Here we see, beside the step list, the initial and final cluster
644 status, with the final one showing all nodes being N+1 compliant, and
645 the command list to reach the final solution. In the initial listing,
646 we see which nodes are not N+1 compliant.
648 The algorithm is stable as long as each step above is fully completed,
649 e.g. in step 8, both the migrate and the replace-disks are
650 done. Otherwise, if only the migrate is done, the input data is
651 changed in a way that the program will output a different solution
652 list (but hopefully will end in the same state).
655 .BR hspace "(1), " hscan "(1), " hail "(1), "
656 .BR ganeti "(7), " gnt-instance "(8), " gnt-node "(8)"
660 Copyright (C) 2009 Google Inc. Permission is granted to copy,
661 distribute and/or modify under the terms of the GNU General Public
662 License as published by the Free Software Foundation; either version 2
663 of the License, or (at your option) any later version.
665 On Debian systems, the complete text of the GNU General Public License
666 can be found in /usr/share/common-licenses/GPL.