Optimize hosts in order priority.
This commit is contained in:
parent
da0c1cec22
commit
12e0759711
@ -438,20 +438,26 @@ class PerformancePlan extends Plan {
|
|||||||
toOptimize
|
toOptimize
|
||||||
} = results
|
} = results
|
||||||
|
|
||||||
const exceededHost = searchObject(toOptimize, (a, b) => {
|
toOptimize.sort((a, b) => {
|
||||||
a = averages[a.id]
|
a = averages[a.id]
|
||||||
b = averages[b.id]
|
b = averages[b.id]
|
||||||
|
|
||||||
return (b.cpu - a.cpu) || (a.memoryFree - b.memoryFree)
|
return (b.cpu - a.cpu) || (a.memoryFree - b.memoryFree)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
for (const exceededHost of toOptimize) {
|
||||||
|
const { id } = exceededHost
|
||||||
|
|
||||||
|
debug(`Try to optimize Host (${exceededHost.id}).`)
|
||||||
|
|
||||||
// Search bests combinations for the worst host.
|
// Search bests combinations for the worst host.
|
||||||
await this._optimize({
|
await this._optimize({
|
||||||
exceededHost,
|
exceededHost,
|
||||||
hosts: filter(hosts, host => host.id !== exceededHost.id),
|
hosts: filter(hosts, host => host.id !== id),
|
||||||
hostsAverages: averages
|
hostsAverages: averages
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async _optimize ({ exceededHost, hosts, hostsAverages }) {
|
async _optimize ({ exceededHost, hosts, hostsAverages }) {
|
||||||
const vms = await this._getVms(exceededHost.id)
|
const vms = await this._getVms(exceededHost.id)
|
||||||
@ -466,6 +472,7 @@ class PerformancePlan extends Plan {
|
|||||||
const promises = []
|
const promises = []
|
||||||
|
|
||||||
const xapiSrc = this.xo.getXapi(exceededHost)
|
const xapiSrc = this.xo.getXapi(exceededHost)
|
||||||
|
let optimizationsCount = 0
|
||||||
|
|
||||||
for (const vm of vms) {
|
for (const vm of vms) {
|
||||||
// Search host with lower cpu usage.
|
// Search host with lower cpu usage.
|
||||||
@ -489,7 +496,8 @@ class PerformancePlan extends Plan {
|
|||||||
exceededAverages.memoryFree += vmAverages.memory
|
exceededAverages.memoryFree += vmAverages.memory
|
||||||
destinationAverages.memoryFree -= vmAverages.memory
|
destinationAverages.memoryFree -= vmAverages.memory
|
||||||
|
|
||||||
debug(`Migrate VM (${vm.id}) to Host (${destination.id}) from Host (${exceededHost.id})`)
|
debug(`Migrate VM (${vm.id}) to Host (${destination.id}) from Host (${exceededHost.id}).`)
|
||||||
|
optimizationsCount++
|
||||||
|
|
||||||
// promises.push(
|
// promises.push(
|
||||||
// xapiSrc.migrateVm(vm._xapiId, this.xo.getXapi(destination), destination._xapiId)
|
// xapiSrc.migrateVm(vm._xapiId, this.xo.getXapi(destination), destination._xapiId)
|
||||||
@ -497,6 +505,7 @@ class PerformancePlan extends Plan {
|
|||||||
}
|
}
|
||||||
|
|
||||||
await Promise.all(promises)
|
await Promise.all(promises)
|
||||||
|
debug(`${optimizationsCount} optimizations for Host (${exceededHost.id}).`)
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user