From 274884ef4d538eb9d0720b16d1399e8d8583801c Mon Sep 17 00:00:00 2001 From: wescoeur Date: Thu, 25 Feb 2016 16:06:46 +0100 Subject: [PATCH] Reorder exceeded hosts by priority. --- packages/xo-server-load-balancer/src/index.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/packages/xo-server-load-balancer/src/index.js b/packages/xo-server-load-balancer/src/index.js index 1868b9ba3..af1193f9e 100644 --- a/packages/xo-server-load-balancer/src/index.js +++ b/packages/xo-server-load-balancer/src/index.js @@ -126,7 +126,9 @@ function computeAverage (values, nPoints = values.length) { let sum = 0 let tot = 0 - for (let i = values.length - nPoints; i < values.length; i++) { + const { length } = values + + for (let i = length - nPoints; i < length; i++) { const value = values[i] sum += value || 0 @@ -223,6 +225,17 @@ class Plan { if (exceeded.length === 0) { return } + + // 3. Reorder the exceeded hosts by priority. + exceeded.sort((a, b) => { + a = avgWithRatio[a.id] + b = avgWithRatio[b.id] + + return (b.cpus - a.cpus) || (a.memoryFree - b.memoryFree) + }) + + // 4. Search bests combinations... + // TODO } async _executeInDensityMode () {