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