Search in sources :

Example 16 with SatConstraint

use of org.btrplace.model.constraint.SatConstraint in project scheduler by btrplace.

the class CShareableResourceTest method testWithFloat.

@Test
public void testWithFloat() throws SchedulerException {
    Model mo = new DefaultModel();
    VM vm1 = mo.newVM();
    VM vm2 = mo.newVM();
    Node n1 = mo.newNode();
    Node n2 = mo.newNode();
    Mapping map = mo.getMapping().on(n1, n2).run(n1, vm1, vm2);
    ShareableResource rc = new ShareableResource("foo");
    rc.setCapacity(n1, 32);
    rc.setConsumption(vm1, 3);
    rc.setConsumption(vm2, 2);
    mo.attach(rc);
    ChocoScheduler cra = new DefaultChocoScheduler();
    List<SatConstraint> cstrs = new ArrayList<>();
    cstrs.addAll(Online.newOnline(map.getAllNodes()));
    Overbook o = new Overbook(n1, "foo", 1.5, false);
    cstrs.add(o);
    Overbook o2 = new Overbook(n2, "foo", 1.5, false);
    cstrs.add(o2);
    cstrs.add(new Preserve(vm1, "foo", 5));
    ReconfigurationPlan p = cra.solve(mo, cstrs);
    Assert.assertNotNull(p);
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) Node(org.btrplace.model.Node) SatConstraint(org.btrplace.model.constraint.SatConstraint) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) ArrayList(java.util.ArrayList) Mapping(org.btrplace.model.Mapping) ShareableResource(org.btrplace.model.view.ShareableResource) Preserve(org.btrplace.model.constraint.Preserve) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) ChocoScheduler(org.btrplace.scheduler.choco.ChocoScheduler) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) VM(org.btrplace.model.VM) Overbook(org.btrplace.model.constraint.Overbook) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) Test(org.testng.annotations.Test)

Example 17 with SatConstraint

use of org.btrplace.model.constraint.SatConstraint in project scheduler by btrplace.

the class CShareableResourceTest method testInsertAction.

/**
 * Reproduce issue#145.
 */
/*@Test*/
public void testInsertAction() {
    Model mo = new DefaultModel();
    ShareableResource cpu = new ShareableResource("cpu");
    ShareableResource mem = new ShareableResource("mem");
    mo.attach(cpu);
    mo.attach(mem);
    Node node = mo.newNode();
    Node node2 = mo.newNode();
    mo.getMapping().on(node, node2);
    cpu.setCapacity(node, 100000);
    mem.setCapacity(node, 100000);
    cpu.setCapacity(node2, 100000);
    mem.setCapacity(node2, 100000);
    for (int i = 0; i < 10000; i++) {
        VM vm = mo.newVM();
        mo.getMapping().run(node, vm);
        cpu.setConsumption(vm, 1);
        mem.setConsumption(vm, 1);
    }
    ChocoScheduler sched = new DefaultChocoScheduler();
    List<SatConstraint> cstrs = new ArrayList<>();
    cstrs.addAll(Running.newRunning(mo.getMapping().getAllVMs()));
    cstrs.addAll(NoDelay.newNoDelay(mo.getMapping().getAllVMs()));
    cstrs.addAll(Fence.newFence(mo.getMapping().getAllVMs(), Arrays.asList(node2)));
    cstrs.addAll(Preserve.newPreserve(mo.getMapping().getAllVMs(), "cpu", 2));
    cstrs.addAll(Preserve.newPreserve(mo.getMapping().getAllVMs(), "mem", 2));
    ReconfigurationPlan plan = sched.solve(mo, cstrs);
    System.out.println(plan);
    System.out.println(sched.getStatistics());
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) ChocoScheduler(org.btrplace.scheduler.choco.ChocoScheduler) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) Node(org.btrplace.model.Node) VM(org.btrplace.model.VM) SatConstraint(org.btrplace.model.constraint.SatConstraint) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) ArrayList(java.util.ArrayList) ShareableResource(org.btrplace.model.view.ShareableResource) SatConstraint(org.btrplace.model.constraint.SatConstraint)

Example 18 with SatConstraint

use of org.btrplace.model.constraint.SatConstraint in project scheduler by btrplace.

the class ModelCustomization method run.

@Override
public void run() {
    Model model = makeModel();
    List<SatConstraint> cstrs = makeConstraints(model);
    // Set attributes for the VMs
    Attributes attrs = model.getAttributes();
    for (VM vm : model.getMapping().getAllVMs()) {
        attrs.put(vm, "template", vm.id() % 2 == 0 ? "small" : "large");
        attrs.put(vm, "clone", true);
        attrs.put(vm, "forge", vm.id() % 2 == 0 ? 2 : 10);
    // forge == 2 && template == small  for vm0, vm2, vm4, vm6, vm8
    // forge == 10 && template == large for vm1, vm3, vm5, vm7, vm9
    }
    // Change the duration evaluator for MigrateVM action
    ChocoScheduler cra = new DefaultChocoScheduler();
    DurationEvaluators dev = cra.getDurationEvaluators();
    dev.register(MigrateVM.class, new LinearToAResourceActionDuration<VM>("mem", 2, 3));
    dev.register(BootVM.class, new ConstantActionDuration<>(1));
    dev.register(ShutdownVM.class, new ConstantActionDuration<>(1));
    // Relocate VM4:
    // using a migration: (2 * mem + 3) = (2 * 2 + 3) = 7 sec.
    // using a re-instantiation: forge + boot + shutdown = 2 + 1 + 1 = 4 sec.
    // Relocate VM5:
    // using a migration: (2 * mem + 3) = (2 * 3 + 3) = 9 sec.
    // using a re-instantiation: forge + boot + shutdown = 10 + 1 + 1 = 12 sec.
    cra.doOptimize(true);
    ReconfigurationPlan plan = cra.solve(model, cstrs);
    System.out.println(plan);
}
Also used : DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) ChocoScheduler(org.btrplace.scheduler.choco.ChocoScheduler) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) SatConstraint(org.btrplace.model.constraint.SatConstraint) MigrateVM(org.btrplace.plan.event.MigrateVM) BootVM(org.btrplace.plan.event.BootVM) VM(org.btrplace.model.VM) ShutdownVM(org.btrplace.plan.event.ShutdownVM) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) Attributes(org.btrplace.model.Attributes) DurationEvaluators(org.btrplace.scheduler.choco.duration.DurationEvaluators)

Example 19 with SatConstraint

use of org.btrplace.model.constraint.SatConstraint in project scheduler by btrplace.

the class ModelCustomization method makeConstraints.

private List<SatConstraint> makeConstraints(Model model) {
    List<SatConstraint> cstrs = new ArrayList<>();
    // No more than 5 VMs per node
    for (Node n : model.getMapping().getAllNodes()) {
        cstrs.add(new RunningCapacity(n, 5));
    }
    // vm1 and vm10 on the same node
    cstrs.add(new Gather(Arrays.asList(vms.get(0), vms.get(9))));
    // (vm1, vm2, vm4) and (vm5, vm6, vm8) must not share node
    Collection<VM> g1 = Arrays.asList(vms.get(0), vms.get(1), vms.get(3));
    Collection<VM> g2 = Arrays.asList(vms.get(4), vms.get(5), vms.get(7));
    cstrs.add(new Split(Arrays.asList(g1, g2)));
    // vm10 must be running
    cstrs.add(new Running(vms.get(9)));
    return cstrs;
}
Also used : RunningCapacity(org.btrplace.model.constraint.RunningCapacity) SatConstraint(org.btrplace.model.constraint.SatConstraint) Node(org.btrplace.model.Node) MigrateVM(org.btrplace.plan.event.MigrateVM) BootVM(org.btrplace.plan.event.BootVM) VM(org.btrplace.model.VM) ShutdownVM(org.btrplace.plan.event.ShutdownVM) ArrayList(java.util.ArrayList) Running(org.btrplace.model.constraint.Running) Split(org.btrplace.model.constraint.Split) Gather(org.btrplace.model.constraint.Gather)

Example 20 with SatConstraint

use of org.btrplace.model.constraint.SatConstraint in project scheduler by btrplace.

the class AdvancedMigScheduling method run.

@Override
public void run() {
    Model mo = makeModel();
    // Create, define, and attach CPU and Mem resource decorators for nodes and VMs
    int memSrc = 8;
    int cpuSrc = 4;
    int memDst = 16;
    int cpuDst = 8;
    ShareableResource rcMem = new ShareableResource("mem", 0, 8);
    ShareableResource rcCPU = new ShareableResource("cpu", 0, 4);
    // VMs resources consumption
    // Nodes resources capacity
    rcMem.setCapacity(srcNode1, memSrc).setCapacity(srcNode2, memSrc).setCapacity(srcNode3, memSrc).setCapacity(srcNode4, memSrc).setCapacity(dstNode1, memDst).setCapacity(dstNode2, memDst);
    rcCPU.setCapacity(srcNode1, cpuSrc).setCapacity(srcNode2, cpuSrc).setCapacity(srcNode3, cpuSrc).setCapacity(srcNode4, cpuSrc).setCapacity(dstNode1, cpuDst).setCapacity(dstNode2, cpuDst);
    mo.attach(rcMem);
    mo.attach(rcCPU);
    // Set VM attributes 'hot dirty page size', 'hot dirty page duration', and 'cold dirty pages rate'
    // to simulate a memory intensive workload equivalent to "stress --vm 1000 --bytes 50K"
    int vmHds = 56;
    int vmHdd = 2;
    double vmCdr = 22.6;
    // vm0 is an 'idle' VM (with no special memory activity) but still consumes 2 GiB of memory
    mo.getAttributes().put(vm0, "memUsed", 2000);
    // vm1 is an 'idle' VM (with no special memory activity) but still consumes 4 GiB of memory
    mo.getAttributes().put(vm1, "memUsed", 3000);
    // vm2 consumes 4 GiB memory and has a memory intensive workload
    mo.getAttributes().put(vm2, "memUsed", 4000);
    mo.getAttributes().put(vm2, "hotDirtySize", vmHds);
    mo.getAttributes().put(vm2, "hotDirtyDuration", vmHdd);
    mo.getAttributes().put(vm2, "coldDirtyRate", vmCdr);
    // vm3 consumes 6 GiB memory and has a memory intensive workload
    mo.getAttributes().put(vm3, "memUsed", 5000);
    mo.getAttributes().put(vm3, "hotDirtySize", vmHds);
    mo.getAttributes().put(vm3, "hotDirtyDuration", vmHdd);
    mo.getAttributes().put(vm3, "coldDirtyRate", vmCdr);
    // Attach a network view
    Network net = new Network();
    mo.attach(net);
    Switch swMain = net.newSwitch(30000);
    net.connect(10000, swMain, srcNode1, srcNode2, srcNode3, srcNode4);
    // The destination nodes have twice the bandwidth of source nodes
    net.connect(20000, swMain, dstNode1, dstNode2);
    // Create constraints
    List<SatConstraint> cstrs = new ArrayList<>();
    // We want to boot the destination nodes
    cstrs.addAll(Online.newOnline(dstNode1, dstNode2));
    // We want to shutdown the source nodes
    cstrs.addAll(Offline.newOffline(srcNode1, srcNode2, srcNode3, srcNode4));
    // Try to solve as is, and show the computed plan
    solve(mo, cstrs);
    /**
     ******* Add some migrations scheduling constraints ********
     */
    // We want vm0 and vm1 migrations to terminate at the same time
    cstrs.add(new Sync(vm0, vm1));
    // We want to serialize the migrations of vm1, vm2, and vm3
    cstrs.add(new Serialize(new HashSet<>(Arrays.asList(vm1, vm2, vm3))));
    // We want vm0 migration terminate before vm2 start to migrate
    cstrs.add(new Precedence(vm1, vm2));
    // We want vm3 migration terminate before 10s
    cstrs.add(new Deadline(vm3, "+0:0:10"));
    // Try to solve, and show the computed plan
    solve(mo, cstrs);
}
Also used : Serialize(org.btrplace.model.constraint.migration.Serialize) SatConstraint(org.btrplace.model.constraint.SatConstraint) Deadline(org.btrplace.model.constraint.migration.Deadline) ArrayList(java.util.ArrayList) ShareableResource(org.btrplace.model.view.ShareableResource) SatConstraint(org.btrplace.model.constraint.SatConstraint) Switch(org.btrplace.model.view.network.Switch) Network(org.btrplace.model.view.network.Network) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) Sync(org.btrplace.model.constraint.migration.Sync) Precedence(org.btrplace.model.constraint.migration.Precedence) HashSet(java.util.HashSet)

Aggregations

SatConstraint (org.btrplace.model.constraint.SatConstraint)111 DefaultModel (org.btrplace.model.DefaultModel)90 Test (org.testng.annotations.Test)82 VM (org.btrplace.model.VM)79 Node (org.btrplace.model.Node)77 Model (org.btrplace.model.Model)76 ArrayList (java.util.ArrayList)74 ReconfigurationPlan (org.btrplace.plan.ReconfigurationPlan)72 DefaultChocoScheduler (org.btrplace.scheduler.choco.DefaultChocoScheduler)65 ChocoScheduler (org.btrplace.scheduler.choco.ChocoScheduler)51 Mapping (org.btrplace.model.Mapping)50 ShareableResource (org.btrplace.model.view.ShareableResource)41 HashSet (java.util.HashSet)33 Fence (org.btrplace.model.constraint.Fence)27 Offline (org.btrplace.model.constraint.Offline)17 Preserve (org.btrplace.model.constraint.Preserve)16 MigrateVM (org.btrplace.plan.event.MigrateVM)15 ScriptBuilder (org.btrplace.btrpsl.ScriptBuilder)14 Instance (org.btrplace.model.Instance)14 Network (org.btrplace.model.view.network.Network)14