Add a manpage for hbal
[ganeti-local] / hbal.1
1 .TH HBAL 2 2009-03-13 htools "Ganeti H-tools"
2 .SH NAME
3 hbal \- Cluster balancer for Ganeti
4
5 .SH SYNOPSIS
6 .B hbal
7 .B "[-C]"
8 .B "[-p]"
9 .B "[-o]"
10 .B "-l"
11 .BI "[ -m " cluster "]"
12 .BI "[-n " nodes-file " ]"
13 .BI "[ -i " instances-file "]"
14
15 .SH DESCRIPTION
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.
20
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.
26
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.
30
31 .SS ALGORITHM
32
33 The program works in indepentent steps; at each step, we compute the
34 best instance move that lowers the cluster score.
35
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:
40   - failover (f)
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)
45
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.
51
52 .SS CLUSTER SCORING
53
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
56 components:
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
61
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.
68
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.
74
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
80 anymore in this case.
81
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 :)
85
86 .SS OTHER POSSIBLE METRICS
87
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
91   - Disk IO usage
92   - Network IO
93
94 .SH OPTIONS
95 The options that can be passed to the program are as follows:
96 .TP
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.
100 .TP
101 .B -p, --print-nodes
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.
104
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
108   - the node name
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
113   - total disk
114   - free disk
115   - number of primary instances
116   - number of secondary instances
117   - percent of free memory
118   - percent of free disk
119
120 .TP
121 .B -o, --oneline
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
124 status.
125
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
131
132 .TP
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
136 .I nodes
137 file.
138
139 .TP
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
143 .I instances
144 file.
145
146 .TP
147 .BI "-m" cluster
148 Collect data not from files but directly from the
149 .I cluster
150 given as an argument via RAPI. This work for both Ganeti 1.2 and
151 Ganeti 2.0.
152
153 .TP
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.
157
158 .TP
159 .B -v, --verbose
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
162 default of zero.
163
164 .TP
165 .B -V, --version
166 Just show the program version and exit.
167
168 .SH EXIT STATUS
169
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).
172
173 .SH BUGS
174
175 The program does not check its input data for consistency, and aborts
176 with cryptic errors messages in this case.
177
178 The algorithm is not perfect.
179
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
182 input file).
183
184 .SH EXAMPLE
185
186 .SS Default output
187
188 With the default options, the program shows each individual step and
189 the improvements it brings in cluster score:
190
191 .in +4n
192 .nf
193 .RB "$" " hbal"
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
214 .fi
215 .in
216
217 In the above output, we can see:
218   - the input data (here from files) shows a cluster with 20 nodes and
219     80 instances
220   - the cluster is not initially N+1 compliant
221   - the initial score is 0.52329131
222
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).
227
228 Finally, the program shows the improvement in cluster score.
229
230 A more detailed output is obtained via the \fB-C\fR and \fB-p\fR options:
231
232 .in +4n
233 .nf
234 .RB "$" " hbal"
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
259
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
278
279 Commands to run to reach the above solution:
280   echo step 1
281   echo gnt-instance migrate instance14
282   echo gnt-instance replace-disks -n node16 instance14
283   echo gnt-instance migrate instance14
284   echo step 2
285   echo gnt-instance migrate instance54
286   echo gnt-instance replace-disks -n node16 instance54
287   echo gnt-instance migrate instance54
288   echo step 3
289   echo gnt-instance migrate instance4
290   echo gnt-instance replace-disks -n node16 instance4
291   echo step 4
292   echo gnt-instance replace-disks -n node2 instance48
293   echo gnt-instance migrate instance48
294   echo step 5
295   echo gnt-instance replace-disks -n node16 instance93
296   echo gnt-instance migrate instance93
297   echo step 6
298   echo gnt-instance replace-disks -n node2 instance89
299   echo gnt-instance migrate instance89
300   echo step 7
301   echo gnt-instance replace-disks -n node16 instance5
302   echo gnt-instance migrate instance5
303   echo step 8
304   echo gnt-instance migrate instance94
305   echo gnt-instance replace-disks -n node16 instance94
306   echo step 9
307   echo gnt-instance migrate instance44
308   echo gnt-instance replace-disks -n node15 instance44
309   echo step 10
310   echo gnt-instance replace-disks -n node16 instance62
311   echo step 11
312   echo gnt-instance replace-disks -n node16 instance13
313   echo step 12
314   echo gnt-instance replace-disks -n node7 instance19
315   echo step 13
316   echo gnt-instance replace-disks -n node1 instance43
317   echo step 14
318   echo gnt-instance replace-disks -n node4 instance1
319   echo step 15
320   echo gnt-instance replace-disks -n node17 instance58
321
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
344
345 .fi
346 .in
347
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.
352
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).
358
359 .SH SEE ALSO
360 ganeti(7), gnt-instance(8), gnt-node(8)