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

View File

@ -34,8 +34,8 @@
"cron": "^1.1.0",
"event-to-promise": "^0.6.0",
"lodash.clonedeep": "^4.3.1",
"lodash.differenceby": "^4.2.1",
"lodash.filter": "^4.2.0",
"lodash.find": "^4.3.0",
"lodash.includes": "^4.1.0",
"lodash.intersection": "^4.1.0",
"lodash.map": "^4.2.0",

View File

@ -1,10 +1,21 @@
import filter from 'lodash.filter'
import find from 'lodash.find'
import Plan from './plan'
import {
debug,
searchObject
} from './utils'
import { debug } from './utils'
// Compare a list of objects and give the best.
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)
let optimizationsCount = 0
const searchFunction = (a, b) => hostsAverages[b.id].cpu - hostsAverages[a.id].cpu
for (const vm of vms) {
// Search host with lower cpu usage.
const destination = searchObject(hosts, (a, b) =>
hostsAverages[b.id].cpu - hostsAverages[a.id].cpu
)
// Search host with lower cpu usage in the same pool first. In other pool if necessary.
let destination = searchBestObject(find(hosts, host => host.$poolId === vm.$poolId), searchFunction)
if (!destination) {
destination = searchBestObject(hosts, searchFunction)
}
const destinationAverages = hostsAverages[destination.id]
const vmAverages = vmsAverages[vm.id]

View File

@ -1,4 +1,3 @@
import differenceBy from 'lodash.differenceby'
import filter from 'lodash.filter'
import includes from 'lodash.includes'
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.
_getHosts () {
return differenceBy(
filter(this.xo.getObjects(), object => {
object.type === 'host' &&
includes(this._poolIds, object.$poolId) &&
object.power_state !== 'Halted'
}),
this._excludedHosts,
val => val.id || val
)
return filter(this.xo.getObjects(), object => (
object.type === 'host' &&
includes(this._poolIds, object.$poolId) &&
object.power_state !== 'Halted' &&
!includes(this._excludedHosts, object.id)
))
}
async _getVms (hostId) {

View File

@ -11,16 +11,3 @@ export const EXECUTION_DELAY = 1
export const debug = LOAD_BALANCER_DEBUG
? str => console.log(`[load-balancer]${str}`)
: 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
}