
Ask HN: help needed on VM placement algorithm - kuvkir
Hello!<p>I'm working on a "cloud computing" management system and need help on a VM placement/provision algorithm.<p>Let us assume we have a cluster of N physical servers. Each server has a single type of resource - slots (Note that in real world servers have more resources CPU/memory/disk/etc...).
Let a server have M slots.
Servers can run virtual machines, every VM occupies from 1 to M slots.
Once the VM (with k slots) starts on a server, the number of free server slots is reduced accordingly.
When the VM stops, the occupied slots are freed.<p>VMs can live-migrate across servers. For example, when there is no server with M free slots (every server runs at least one VM), and we need to start an M-slot VM - there we need to rearrange VMs across a cluster.<p>The goal is implement a VM placement policy to satisfy the following requirements:<p>* utilize server resources in a uniform way, e.g. if we have 3 servers and 3 single-slot VMs we should place them on different servers.<p>* minimize number of VM migrations as it is a costly operation.<p>It looks like the problem in question has something to do with multiple knapsack problem, so I'm looking for some kind of heuristic algorithm.<p>Any advise / papers / working solutions ?<p>Thanks in advance,<p>Kirill
======
eru
I will look into your problem. Perhaps I can work out an integer linear
formulation that you can feed into a standard solver for linear optimization
problems.

If you want to read papers on the subject, look for 'scheduling' or
'production planning'. 'Bin packing' and 'cutting stock' might also be
related.

Do you need an online solution or do you know all demands in advance? Also
what do you do when not enough slots are available for all VMs? That could
happen either because the number of slots in demand is higher than the supply
--- or a bit more subtle: Say you have n servers, and n+1 VMs each taking
M/2+1 slots. The total number of slots suffices, but still your VMs do not fit
the machines.

~~~
kuvkir
Thanks for your reply, eru!

> Do you need an online solution or do you know all demands in advance?

The online solution, as we don't know the type of load in advance. It
resembles tetris in some way, meaning that we don't know which piece you'll
get next.

> Also what do you do when not enough slots are available for all VMs?

If it's not theoretically possible to host all VMs like in examples you
provided, nothing can be done. But it's not an algorithmic problem, in real
world new servers should be bought in that case.

~~~
rjprins
Wait, this is very simple:

Always pick the server with the most slots open.

Only when no server has enough space to accomodate the next machine, but
together they have enough space, should you apply a packing algorithm.

~~~
kuvkir
That's not that simple.

Let us imagine the following configuration.

We have 3 servers each of 4 slots, below is the state of each server (the
state of a server is a set of VMs it's running)

[3], [2, 1] and [2].

Say we need to place a new 3-slot VM to our system. We'll pick the third
server as less-loaded and try to accomodate the second server. Together they
have enough space, but we can't provision the VM withour using all 3 servers.
The solution here is

1) migrate a 1-slot VM from server 2 to server 1

2) migrate a 2-slot VM from server 2 to server 3

3) place the new VM to server 2

~~~
rjprins
Don't get me wrong, a correct packing algorithm for this is far from trivial!

What would you say is more important: minimizing the amount of slots to move
or the number of VM's?

~~~
kuvkir
That's not a simple question. But I would guess having one 2-slot migration is
better than two 1-slot migrations...

------
rjprins
Is it first come first serve?

Very interesting, I'll see what I can work out..

