Search destination host per pool. (Performance mode)

This commit is contained in:
wescoeur
2016-04-06 15:24:34 +02:00
parent 627227f2f9
commit 3e285d6131
4 changed files with 31 additions and 32 deletions
@@ -34,8 +34,8 @@
"cron": "^1.1.0", "cron": "^1.1.0",
"event-to-promise": "^0.6.0", "event-to-promise": "^0.6.0",
"lodash.clonedeep": "^4.3.1", "lodash.clonedeep": "^4.3.1",
"lodash.differenceby": "^4.2.1",
"lodash.filter": "^4.2.0", "lodash.filter": "^4.2.0",
"lodash.find": "^4.3.0",
"lodash.includes": "^4.1.0", "lodash.includes": "^4.1.0",
"lodash.intersection": "^4.1.0", "lodash.intersection": "^4.1.0",
"lodash.map": "^4.2.0", "lodash.map": "^4.2.0",
@@ -1,10 +1,21 @@
import filter from 'lodash.filter' import filter from 'lodash.filter'
import find from 'lodash.find'
import Plan from './plan' import Plan from './plan'
import { import { debug } from './utils'
debug,
searchObject // Compare a list of objects and give the best.
} from './utils' function searchBestObject (objects, fun) {
let object = objects[0]
for (let i = 1; i < objects.length; i++) {
if (fun(object, objects[i]) > 0) {
object = objects[i]
}
}
return object
}
// =================================================================== // ===================================================================
@@ -74,11 +85,16 @@ export default class PerformancePlan extends Plan {
const xapiSrc = this.xo.getXapi(exceededHost) const xapiSrc = this.xo.getXapi(exceededHost)
let optimizationsCount = 0 let optimizationsCount = 0
const searchFunction = (a, b) => hostsAverages[b.id].cpu - hostsAverages[a.id].cpu
for (const vm of vms) { for (const vm of vms) {
// Search host with lower cpu usage. // Search host with lower cpu usage in the same pool first. In other pool if necessary.
const destination = searchObject(hosts, (a, b) => let destination = searchBestObject(find(hosts, host => host.$poolId === vm.$poolId), searchFunction)
hostsAverages[b.id].cpu - hostsAverages[a.id].cpu
) if (!destination) {
destination = searchBestObject(hosts, searchFunction)
}
const destinationAverages = hostsAverages[destination.id] const destinationAverages = hostsAverages[destination.id]
const vmAverages = vmsAverages[vm.id] const vmAverages = vmsAverages[vm.id]
+4 -8
View File
@@ -1,4 +1,3 @@
import differenceBy from 'lodash.differenceby'
import filter from 'lodash.filter' import filter from 'lodash.filter'
import includes from 'lodash.includes' import includes from 'lodash.includes'
import { default as mapToArray } from 'lodash.map' import { default as mapToArray } from 'lodash.map'
@@ -188,15 +187,12 @@ export default class Plan {
// Compute hosts for each pool. They can change over time. // Compute hosts for each pool. They can change over time.
_getHosts () { _getHosts () {
return differenceBy( return filter(this.xo.getObjects(), object => (
filter(this.xo.getObjects(), object => {
object.type === 'host' && object.type === 'host' &&
includes(this._poolIds, object.$poolId) && includes(this._poolIds, object.$poolId) &&
object.power_state !== 'Halted' object.power_state !== 'Halted' &&
}), !includes(this._excludedHosts, object.id)
this._excludedHosts, ))
val => val.id || val
)
} }
async _getVms (hostId) { async _getVms (hostId) {
@@ -11,16 +11,3 @@ export const EXECUTION_DELAY = 1
export const debug = LOAD_BALANCER_DEBUG export const debug = LOAD_BALANCER_DEBUG
? str => console.log(`[load-balancer]${str}`) ? str => console.log(`[load-balancer]${str}`)
: noop : noop
// Compare a list of objects and give the best.
export function searchObject (objects, fun) {
let object = objects[0]
for (let i = 1; i < objects.length; i++) {
if (fun(object, objects[i]) > 0) {
object = objects[i]
}
}
return object
}