Skip to content

Getting Started

fhermeni edited this page Mar 14, 2013 · 95 revisions

Getting started

Btrplace is a flexible algorithm to place Virtual Machines (VMs) on servers in a hosting platforms. Basically, it will manage VMs according to stated constraints. As a user of the algorithm, you only have to declare the constraints you want to have satisfied. Btrplace will then compute a viable placement, and a schedule of actions to reach it by itself.

This tutorial presents how to use Btrplace to solve a basic placement problems. The complete source code of this tutorial can be found there.

Defining a model

A model depicts a consistent view of a virtualized hosting platforms. It is composed of

In Btrplace, as in many hypervisors, elements of the are identified by a UUID.

A sample mapping###

UUID n1 = UUID.randomUUID();
UUID n2 = UUID.randomUUID();
UUID n3 = UUID.randomUUID();
UUID n4 = UUID.randomUUID();

Mapping m = new DefaultMapping();
//4 online nodes        
map.addOnlineNode(n1);
map.addOnlineNode(n2);
map.addOnlineNode(n3);
map.addOnlineNode(n4);

//The 6 running VMs
map.addRunningVM(vm3, n1); //vm3 runs on n1
map.addRunningVM(vm2, n1);

map.addRunningVM(vm1, n3);
map.addRunningVM(vm5, n3);
map.addRunningVM(vm4, n3);

map.addRunningVM(vm6, n4);

Describing the current resource usage

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 code to use to declare a "cpu" resource.For this example, it will indicates the amount of physical CPUs available on the nodes, and the amount of virtual CPUs that are allocated to the VMs.

        ShareableResource rcCPU = new ShareableResource("cpu");
        //Each of the node has 8 pCPUs
        rcCPU.set(n1, 8);
        rcCPU.set(n2, 8);
        rcCPU.set(n3, 8);
        rcCPU.set(n4, 8);

        //VMs uses between 2 and 5 vCPUs
        rcCPU.set(vm1, 2);
        rcCPU.set(vm2, 3);
        rcCPU.set(vm3, 4);
        rcCPU.set(vm4, 3);
        rcCPU.set(vm5, 3);
        rcCPU.set(vm6, 5);

Building the resulting model

Model mo = new DefaultModel(map);
mo.attach(rcCPU);

Stating constraints

Constraints are independant elements that impose a restriction on a model. Typically, it may restrict the VMs placement, their state, their resource allocation, ...

The following code creates a set of 5 constraints

  Set<SatConstraint> cstrs = new HashSet<SatConstraint>();

  //We disallow CPU overbooking, so each unit of
  //virtual resource consumes one unit of physical
  //resource on every nodes
  Set<UUID> allNodes = new HashSet<UUID>(Arrays.asList(n1, n2, n3, n4));
  cstrs.add(new Overbook(allNodes, "cpu", 1));      

  //VM2 and VM3 must be running on distinct nodes
  cstrs.add(new Spread(new HashSet<UUID>(Arrays.asList(vm2, vm3))));

  //VM1 must have at least 3 virtual CPU dedicated to it
  cstrs.add(new Preserve(Collections.singleton(vm1), "cpu", 3));

  //node N4 must be offline
  cstrs.add(new Offline(Collections.singleton(n4)));

Clone this wiki locally