-
Notifications
You must be signed in to change notification settings - Fork 14
Getting Started
Btrplace is a flexible algorithm to place Virtual Machines (VMs) on servers in a hosting platforms. Basically, it manages VMs with respect to constraints that are stated by the users. As a user of the algorithm, you only have to declare the constraints you want to have satisfied. This tutorial presents the fundaments of BtrPlace. [Associated source code] (https://github.com/fhermeni/btrplace-solver/blob/master/examples/src/main/java/btrplace/examples/GettingStarted.java)
BtrPlace is articulated around 4 primitives:
-
The model depicts the current state of a virtualized hosting platforms. It is usually generated from monitoring data
-
A reconfiguration plan. A plan consists of a scheduled set of actions to execute. A plan allows to transit from a source model to a destination model.
-
A set of Satisfaction Oriented Constraints (SatConstraints). A SatConstraint imposes a restriction on a model or a reconfiguration plan. On a model, it provides a discrete restriction. On a plan, it imposes a continuous restriction, i.e a restriction over the time. In practice, a constraint allows to control the state of the elements (VMs, servers), the resource allocation, the VMs placement, ...
-
A reconfiguration algorithm is an algorithm that takes a model and a set of constraints as a parameter. It checks if the model is consistent with regards to the states constraints. If not, it computes a plan to reach a model that satisfies all the constraints simultaneously.
A model is composed of several elements:
-
The mapping (required) declares the current servers states and the current VMs states and placement.
-
a serie of [views] (http://btrp.inria.fr/apidocs/releases/btrplace/solver/last/index.html?btrplace/model/view/ModelView.html) (optional) to declare domain-specific informations about the elements, such as their resources consumptions.
-
some [attributes] (http://btrp.inria.fr/apidocs/releases/btrplace/solver/last/index.html?btrplace/model/Attributes.html) (optional) that indicate options for certain elements.
In this tutorial, we will reproduce the model that is depicted by the following figure. It represents a model composed by 4 online servers hosting 5 VMs and a sixth ready for being running.

In Btrplace, as in many hypervisors, elements such as servers and VMs are identified by a UUID. The next snippet creates a mapping that declare the online node n1 and set VMs vm2 and vm3 running on it. vm5 is indicated to be ready for being running on a node. origin will be the resulting model:
Mapping m = new DefaultMapping();
UUID n1 = UUID.randomUUID();
UUID vm2 = UUID.randomUUID();
UUID vm3 = UUID.randomUUID();
//n1 is online
map.addOnlineNode(n1);
//vm3 and vm2 runs on n1
map.addRunningVM(vm3, n1);
map.addRunningVM(vm2, n1);
Model origin = new DefaultModel(map);BtrPlace support more states for VMs and nodes. For additional informations, see VMs and nodes life cycle.
In Btrplace, a resource is defined using a special view called ShareableResource. This allows to specify the physical resource capacity of the nodes and the virtual resource usage of the VMs.
Below is the snippet to declare a resource called "cpu" and attach it to the model origin. For this example, itindicates the number of physical CPUs available on n1, and the number of virtual CPUs that are allocated to vm2 and vm3.
ShareableResource rcCPU = new ShareableResource("cpu");
//n1 has 8 physical CPUs
rcCPU.set(n1, 8);
//vm2 has 3 virtual CPUs
rcCPU.set(vm2, 3);
//vm3 has 3 virtual CPUs
rcCPU.set(vm3, 4);
//the rcCPU view is attached to the model
origin.attach(rcCPU);A Satisfaction Oriented Constraint (SatConstraint) imposes a restriction on a model or a reconfiguration plan. On a model, it provides a discrete restriction. On a plan, it imposes a continuous restriction, i.e a restriction over the time. The type of the restriction depends on the constraint semantics and a constraint may support the both type of restriction.
Constraints control several aspects of the model (VM and nodes states, resource allocation, ...). By default, BtrPlace considers the state of a VM is not changed unless a constraint explicitely asks for a new state.
The following code creates 5 constraints:
//VM2 and VM3 must be running on distinct nodes
Spread s = new Spread(new HashSet<UUID>(Arrays.asList(vm2, vm3)));
//VM1 must have at least 3 virtual CPU dedicated to it
Preserve cpu4vm1 = new Preserve(Collections.singleton(vm1), "cpu", 3);
//node N4 must be offline
Offline offN4 = new Offline(Collections.singleton(n4));
//VM5 must be running, It asks for 3 cpu and 2 mem resources
Running runVM5 = new Running(Collections.singleton(vm5)));
Preserve cpu4vm5 = new Preserve(Collections.singleton(vm5), "cpu", 3);
Preserve mem4vm5 = new Preserve(Collections.singleton(vm5), "mem", 2);
//VM4 must be set back to the ready state
Ready readyVM4 = new Ready(Collections.singleton(vm4)));
Set<SatConstraint> cstrs = new HashSet<SatConstraint>(Arrays.asList(spread, cpu4vm1, offN4,
runVM5, mem4vm5, cpu4vm5, readyVM4));If we oppose the model origin with the set of constraints:
-
spread(vm2, vm3)is not satisfied inmoas both VMs are running onn1. -
preserve(vm1, "cpu", 3)is not satisfied as the VMs currently has 2 virtual CPUs. -
offline(n4)is not satisfied asn4is online.
Using Btrplace, it is possible to compute a new model that satisfies all the stated constraints. The following snipped instantiates the default reconfiguration algorithm and solve the current problem:
ChocoReconfigurationAlgorithm ra = new DefaultChocoReconfigurationAlgorithm();
ReconfigurationPlan plan = ra.solve(origin, cstrs);plan contains the following schedule of actions that will lead to a new model satisfying all the constraints in cstrs:
| Schedule | Action |
|---|---|
| 0:00 to 0:01 | boot vm5 on n2 then allocate 2 "mem" and 3 "cpu" resources |
| 0:00 to 0:01 | shutdown vm4 |
| 0:01 to 0:02 | migrate vm6 from n4 to n3 |
| 0:02 to 0:03 | shutdown n4 |
| 0:03 to 0:03 | allocate 3 "cpu" on vm1 |
If this plan is applyed, the resulting model, accesible through plan.getResultingModel() will be:

The actions schedule has been infered from the actions semantics but also a theroretical estimation of the actions duration. By default, each action takes one second to complete. This can be changed easily to comply with your data (see Basic Tuning).
The practical duration of an actions may exceed its estimated duration. It is then not safe to rely only on the time-based schedule to execute a reconfiguration plan on a real infrastructure. A solution is to extract the actions dependencies using a DependencyBasedPlanApplier. This produces an event-based reconfiguration plan where blocked actions are delayed until there dependencies have been met (i.e. until the unblocking actions are terminated). Here, the resulting event-based plan will be:
| Dependency | Action |
|---|---|
| - | boot vm5 on n2 |
| - | shutdown vm4 |
| shutdown vm4 | migrate vm6 from n4 to n3 |
| migrate vm6 from n4 to n3 | shutdown n4 |
| shutdown vm4 | allocate 3 "cpu" on vm1 |
That's all for this tutorial. We have seen how to create a basic model, state some satisfaction-oriented constraints and compute a plan that fix a non-viable model. Have a look to the VMs and nodes life cycle for a better understanding of the state management using BtrPlace or the supported constraints.
Next tutorial is about the Basic Tuning of a reconfiguration algorithm.