Cloud balancing tutorial

1. Problem statement

Suppose your company owns a number of cloud computers and needs to run a number of processes on those computers. Assign each process to a computer under the following 4 constraints.

Hard constraints which must be fulfilled:

Every computer must be able to handle the minimal hardware requirements of the sum of its processes: The CPU power of a computer must be at least the sum of the CPU power required by the processes assigned to that computer. The RAM memory of a computer must be at least the sum of the RAM memory required by the processes assigned to that computer. The network bandwidth of a computer must be at least the sum of the network bandwidth required by the processes assigned to that computer.



Soft constraints which should be optimized:

Each computer that has one or more processes assigned, incurs a maintenance cost (which is fixed per computer). Minimize the total maintenance cost.



How would you do that? This problem is a form of bin packing. Here's a simplified example where we assign 4 processes to 2 computers with 2 constraints (CPU and RAM) with a simple algorithm:

The simple algorithm used here is the First Fit Decreasing algorithm, which assigns the bigger processes first and assigns the smaller processes to the remaining space. As you can see, it's not optimal, because it does not leave enough room to assign the yellow process D.

Drools Planner does find the more optimal solution fast, by using additional, smarter algorithms. And it scales too: both in data (more processes, more computers) and constraints (more hardware requirements, other constraints). So let's take a look how we can use Planner for this.