1 .TH HBAL 2 2009-03-13 htools "Ganeti H-tools"
3 hbal \- Cluster balancer for Ganeti
11 .BI "[ -m " cluster "]"
12 .BI "[-n " nodes-file " ]"
13 .BI "[ -i " instances-file "]"
16 hbal is a cluster balancer that looks at the current state of the
17 cluster (nodes with their total and free disk, memory, etc.) and
18 instance placement and computes a series of steps designed to bring
19 the cluster into a better state.
21 The algorithm to do so is designed to be stable (i.e. it will give you
22 the same results when restarting it from the middle of the solution)
23 and reasonably fast. It is not, however, designed to be a perfect
24 algorithm - it is possible to make it go into a corner from which it
25 can find no improvement, because it only look one "step" ahead.
27 By default, the program will show the solution incrementally as it is
28 computed, in a somewhat cryptic format; for getting the actual Ganeti
29 command list, use the \fB-C\fR option.
33 The program works in indepentent steps; at each step, we compute the
34 best instance move that lowers the cluster score.
36 The possible move type for an instance are combinations of
37 failover/migrate and replace-disks such that we change one of the
38 instance nodes, and the other one remains (but possibly with changed
39 role, e.g. from primary it becomes secondary). The list is:
41 - replace secondary (r)
42 - replace primary, a composite move (f, r, f)
43 - failover and replace secondary, also composite (f, r)
44 - replace secondary and failover, also composite (r, f)
46 We don't do the only remaining possibility of replacing both nodes
47 (r,f,r,f or the equivalent f,r,f,r) since these move needs an
48 exhaustive search over both candidate primary and secondary nodes, and
49 is O(n*n) in the number of nodes. Furthermore, it doesn't seems to
50 give better scores but will result in more disk replacements.
54 As said before, the algorithm tries to minimize the cluster score at
55 each step. Currently this score is computed as a sum of the following
57 - coefficient of variance of the percent of free memory
58 - coefficient of variance of the percent of reserved memory
59 - coefficient of variance of the percent of free disk
60 - percentage of nodes failing N+1 check
62 The free memory and free disk values help ensure that all nodes are
63 somewhat balanced in their resource usage. The reserved memory helps
64 to ensure that nodes are somewhat balanced in holding secondary
65 instances, and that no node keeps too much memory reserved for
66 N+1. And finally, the N+1 percentage helps guide the algorithm towards
67 eliminating N+1 failures, if possible.
69 Except for the N+1 failures, we use the coefficient of variance since
70 this brings the values into the same unit so to speak, and with a
71 restrict domain of values (between zero and one). The percentange of
72 N+1 failures, while also in this numeric range, doesn't actually has
73 the same meaning, but it has shown to work well.
75 The other alternative, using for N+1 checks the coefficient of
76 variance of (N+1 fail=1, N+1 pass=0) across nodes could hint the
77 algorithm to make more N+1 failures if most nodes are N+1 fail
78 already. Since this (making N+1 failures) is not allowed by other
79 rules of the algorithm, so the N+1 checks would simply not work
82 On a perfectly balanced cluster (all nodes the same size, all
83 instances the same size and spread across the nodes equally), all
84 values would be zero. This doesn't happen too often in practice :)
86 .SS OTHER POSSIBLE METRICS
88 It would be desirable to add more metrics to the algorithm, especially
89 dynamically-computed metrics, such as:
90 - CPU usage of instances, combined with VCPU versus PCPU count
95 The options that can be passed to the program are as follows:
97 .B -C, --print-commands
98 Print the command list at the end of the run. Without this, the
99 program will only show a shorter, but cryptic output.
102 Prints the before and after node status, in a format designed to allow
103 the user to understand the node's most important parameters.
105 The node list will contain these informations:
106 - a character denoting the N+1 status of the node, with blank
107 meaning pass and an asterisk ('*') meaning fail
109 - the total node memory
110 - the free node memory
111 - the reserved node memory, which is the amount of free memory
112 needed for N+1 compliancy
115 - number of primary instances
116 - number of secondary instances
117 - percent of free memory
118 - percent of free disk
122 Only shows a one-line output from the program, designed for the case
123 when one wants to look at multiple clusters at once and check their
126 The line will contain four fields:
127 - initial cluster score
128 - number of steps in the solution
129 - final cluster score
130 - improvement in the cluster score
133 .BI "-n" nodefile ", --nodes=" nodefile
134 The name of the file holding node information (if not collecting via
135 RAPI), instead of the default
140 .BI "-i" instancefile ", --instances=" instancefile
141 The name of the file holding instance information (if not collecting
142 via RAPI), instead of the default
148 Collect data not from files but directly from the
150 given as an argument via RAPI. This work for both Ganeti 1.2 and
154 .BI "-l" N ", --max-length=" N
155 Restrict the solution to this length. This can be used for example to
156 automate the execution of the balancing.
160 Increase the output verbosity. Each usage of this option will increase
161 the verbosity (currently more than 2 doesn't make sense) from the
166 Just show the program version and exit.
170 The exist status of the command will be zero, unless for some reason
171 the algorithm fatally failed (e.g. wrong node or instance data).
175 The program does not check its input data for consistency, and aborts
176 with cryptic errors messages in this case.
178 The algorithm is not perfect.
180 The output format is not easily scriptable, and the program should
181 feed moves directly into Ganeti (either via RAPI or via a gnt-debug
188 With the default options, the program shows each individual step and
189 the improvements it brings in cluster score:
194 Loaded 20 nodes, 80 instances
195 Cluster is not N+1 happy, continuing but no guarantee that the cluster will end N+1 happy.
196 Initial score: 0.52329131
197 Trying to minimize the CV...
198 1. instance14 node1:node10 => node16:node10 0.42109120 a=f r:node16 f
199 2. instance54 node4:node15 => node16:node15 0.31904594 a=f r:node16 f
200 3. instance4 node5:node2 => node2:node16 0.26611015 a=f r:node16
201 4. instance48 node18:node20 => node2:node18 0.21361717 a=r:node2 f
202 5. instance93 node19:node18 => node16:node19 0.16166425 a=r:node16 f
203 6. instance89 node3:node20 => node2:node3 0.11005629 a=r:node2 f
204 7. instance5 node6:node2 => node16:node6 0.05841589 a=r:node16 f
205 8. instance94 node7:node20 => node20:node16 0.00658759 a=f r:node16
206 9. instance44 node20:node2 => node2:node15 0.00438740 a=f r:node15
207 10. instance62 node14:node18 => node14:node16 0.00390087 a=r:node16
208 11. instance13 node11:node14 => node11:node16 0.00361787 a=r:node16
209 12. instance19 node10:node11 => node10:node7 0.00336636 a=r:node7
210 13. instance43 node12:node13 => node12:node1 0.00305681 a=r:node1
211 14. instance1 node1:node2 => node1:node4 0.00263124 a=r:node4
212 15. instance58 node19:node20 => node19:node17 0.00252594 a=r:node17
213 Cluster score improved from 0.52329131 to 0.00252594
217 In the above output, we can see:
218 - the input data (here from files) shows a cluster with 20 nodes and
220 - the cluster is not initially N+1 compliant
221 - the initial score is 0.52329131
223 The step list follows, showing the instance, its initial
224 primary/secondary nodes, the new primary secondary, the cluster list,
225 and the actions taken in this step (with 'f' denoting failover/migrate
226 and 'r' denoting replace secondary).
228 Finally, the program shows the improvement in cluster score.
230 A more detailed output is obtained via the \fB-C\fR and \fB-p\fR options:
235 Loaded 20 nodes, 80 instances
236 Cluster is not N+1 happy, continuing but no guarantee that the cluster will end N+1 happy.
237 Initial cluster status:
238 N1 Name t_mem f_mem r_mem t_dsk f_dsk pri sec p_fmem p_fdsk
239 * node1 32762 1280 6000 1861 1026 5 3 0.03907 0.55179
240 node2 32762 31280 12000 1861 1026 0 8 0.95476 0.55179
241 * node3 32762 1280 6000 1861 1026 5 3 0.03907 0.55179
242 * node4 32762 1280 6000 1861 1026 5 3 0.03907 0.55179
243 * node5 32762 1280 6000 1861 978 5 5 0.03907 0.52573
244 * node6 32762 1280 6000 1861 1026 5 3 0.03907 0.55179
245 * node7 32762 1280 6000 1861 1026 5 3 0.03907 0.55179
246 node8 32762 7280 6000 1861 1026 4 4 0.22221 0.55179
247 node9 32762 7280 6000 1861 1026 4 4 0.22221 0.55179
248 * node10 32762 7280 12000 1861 1026 4 4 0.22221 0.55179
249 node11 32762 7280 6000 1861 922 4 5 0.22221 0.49577
250 node12 32762 7280 6000 1861 1026 4 4 0.22221 0.55179
251 node13 32762 7280 6000 1861 922 4 5 0.22221 0.49577
252 node14 32762 7280 6000 1861 922 4 5 0.22221 0.49577
253 * node15 32762 7280 12000 1861 1131 4 3 0.22221 0.60782
254 node16 32762 31280 0 1861 1860 0 0 0.95476 1.00000
255 node17 32762 7280 6000 1861 1106 5 3 0.22221 0.59479
256 * node18 32762 1280 6000 1396 561 5 3 0.03907 0.40239
257 * node19 32762 1280 6000 1861 1026 5 3 0.03907 0.55179
258 node20 32762 13280 12000 1861 689 3 9 0.40535 0.37068
260 Initial score: 0.52329131
261 Trying to minimize the CV...
262 1. instance14 node1:node10 => node16:node10 0.42109120 a=f r:node16 f
263 2. instance54 node4:node15 => node16:node15 0.31904594 a=f r:node16 f
264 3. instance4 node5:node2 => node2:node16 0.26611015 a=f r:node16
265 4. instance48 node18:node20 => node2:node18 0.21361717 a=r:node2 f
266 5. instance93 node19:node18 => node16:node19 0.16166425 a=r:node16 f
267 6. instance89 node3:node20 => node2:node3 0.11005629 a=r:node2 f
268 7. instance5 node6:node2 => node16:node6 0.05841589 a=r:node16 f
269 8. instance94 node7:node20 => node20:node16 0.00658759 a=f r:node16
270 9. instance44 node20:node2 => node2:node15 0.00438740 a=f r:node15
271 10. instance62 node14:node18 => node14:node16 0.00390087 a=r:node16
272 11. instance13 node11:node14 => node11:node16 0.00361787 a=r:node16
273 12. instance19 node10:node11 => node10:node7 0.00336636 a=r:node7
274 13. instance43 node12:node13 => node12:node1 0.00305681 a=r:node1
275 14. instance1 node1:node2 => node1:node4 0.00263124 a=r:node4
276 15. instance58 node19:node20 => node19:node17 0.00252594 a=r:node17
277 Cluster score improved from 0.52329131 to 0.00252594
279 Commands to run to reach the above solution:
281 echo gnt-instance migrate instance14
282 echo gnt-instance replace-disks -n node16 instance14
283 echo gnt-instance migrate instance14
285 echo gnt-instance migrate instance54
286 echo gnt-instance replace-disks -n node16 instance54
287 echo gnt-instance migrate instance54
289 echo gnt-instance migrate instance4
290 echo gnt-instance replace-disks -n node16 instance4
292 echo gnt-instance replace-disks -n node2 instance48
293 echo gnt-instance migrate instance48
295 echo gnt-instance replace-disks -n node16 instance93
296 echo gnt-instance migrate instance93
298 echo gnt-instance replace-disks -n node2 instance89
299 echo gnt-instance migrate instance89
301 echo gnt-instance replace-disks -n node16 instance5
302 echo gnt-instance migrate instance5
304 echo gnt-instance migrate instance94
305 echo gnt-instance replace-disks -n node16 instance94
307 echo gnt-instance migrate instance44
308 echo gnt-instance replace-disks -n node15 instance44
310 echo gnt-instance replace-disks -n node16 instance62
312 echo gnt-instance replace-disks -n node16 instance13
314 echo gnt-instance replace-disks -n node7 instance19
316 echo gnt-instance replace-disks -n node1 instance43
318 echo gnt-instance replace-disks -n node4 instance1
320 echo gnt-instance replace-disks -n node17 instance58
322 Final cluster status:
323 N1 Name t_mem f_mem r_mem t_dsk f_dsk pri sec p_fmem p_fdsk
324 node1 32762 7280 6000 1861 1026 4 4 0.22221 0.55179
325 node2 32762 7280 6000 1861 1026 4 4 0.22221 0.55179
326 node3 32762 7280 6000 1861 1026 4 4 0.22221 0.55179
327 node4 32762 7280 6000 1861 1026 4 4 0.22221 0.55179
328 node5 32762 7280 6000 1861 1078 4 5 0.22221 0.57947
329 node6 32762 7280 6000 1861 1026 4 4 0.22221 0.55179
330 node7 32762 7280 6000 1861 1026 4 4 0.22221 0.55179
331 node8 32762 7280 6000 1861 1026 4 4 0.22221 0.55179
332 node9 32762 7280 6000 1861 1026 4 4 0.22221 0.55179
333 node10 32762 7280 6000 1861 1026 4 4 0.22221 0.55179
334 node11 32762 7280 6000 1861 1022 4 4 0.22221 0.54951
335 node12 32762 7280 6000 1861 1026 4 4 0.22221 0.55179
336 node13 32762 7280 6000 1861 1022 4 4 0.22221 0.54951
337 node14 32762 7280 6000 1861 1022 4 4 0.22221 0.54951
338 node15 32762 7280 6000 1861 1031 4 4 0.22221 0.55408
339 node16 32762 7280 6000 1861 1060 4 4 0.22221 0.57007
340 node17 32762 7280 6000 1861 1006 5 4 0.22221 0.54105
341 node18 32762 7280 6000 1396 761 4 2 0.22221 0.54570
342 node19 32762 7280 6000 1861 1026 4 4 0.22221 0.55179
343 node20 32762 13280 6000 1861 1089 3 5 0.40535 0.58565
348 Here we see, beside the step list, the initial and final cluster
349 status, with the final one showing all nodes being N+1 compliant, and
350 the command list to reach the final solution. In the initial listing,
351 we see which nodes are not N+1 compliant.
353 The algorithm is stable as long as each step above is fully completed,
354 e.g. in step 8, both the migrate and the replace-disks are
355 done. Otherwise, if only the migrate is done, the input data is
356 changed in a way that the program will output a different solution
357 list (but hopefully will end in the same state).
360 ganeti(7), gnt-instance(8), gnt-node(8)