Search in sources :

Example 1 with ShareableResource

use of org.btrplace.model.view.ShareableResource in project scheduler by btrplace.

the class UCC15 method decommissioning_40gb.

public SolvingStatistics decommissioning_40gb() throws SchedulerException {
    // Set nb of nodes and vms
    int nbNodesRack = 24;
    int nbSrcNodes = nbNodesRack * 8;
    int nbDstNodes = nbNodesRack * 4;
    int nbVMs = nbSrcNodes * 2;
    // Set mem + cpu for VMs and Nodes
    int memVM = 4, cpuVM = 1;
    int memSrcNode = 16, cpuSrcNode = 4;
    int memDstNode = 16, cpuDstNode = 4;
    // Set memoryUsed and dirtyRate (for all VMs)
    int tpl1MemUsed = 2000, tpl1MaxDirtySize = 5, tpl1MaxDirtyDuration = 3;
    // idle vm
    double tpl1DirtyRate = 0;
    int tpl2MemUsed = 4000, tpl2MaxDirtySize = 96, tpl2MaxDirtyDuration = 2;
    // stress --vm 1000 --bytes 70K
    double tpl2DirtyRate = 3;
    int tpl3MemUsed = 2000, tpl3MaxDirtySize = 96, tpl3MaxDirtyDuration = 2;
    // stress --vm 1000 --bytes 70K
    double tpl3DirtyRate = 3;
    int tpl4MemUsed = 4000, tpl4MaxDirtySize = 5, tpl4MaxDirtyDuration = 3;
    // idle vm
    double tpl4DirtyRate = 0;
    // New default model
    Model mo = new DefaultModel();
    Mapping ma = mo.getMapping();
    // Create online source nodes and offline destination nodes
    List<Node> srcNodes = new ArrayList<>(), dstNodes = new ArrayList<>();
    for (int i = 0; i < nbSrcNodes; i++) {
        srcNodes.add(mo.newNode());
        ma.addOnlineNode(srcNodes.get(i));
    }
    for (int i = 0; i < nbDstNodes; i++) {
        dstNodes.add(mo.newNode());
        ma.addOfflineNode(dstNodes.get(i));
    }
    // Set boot and shutdown time
    for (Node n : dstNodes) {
        mo.getAttributes().put(n, "boot", 120);
    /*~2 minutes to boot*/
    }
    for (Node n : srcNodes) {
        mo.getAttributes().put(n, "shutdown", 17);
    /*~30 seconds to shutdown*/
    }
    // Create running VMs on src nodes
    List<VM> vms = new ArrayList<>();
    VM v;
    for (int i = 0; i < nbSrcNodes; i++) {
        if (i % 2 == 0) {
            v = mo.newVM();
            vms.add(v);
            mo.getAttributes().put(v, "memUsed", tpl1MemUsed);
            mo.getAttributes().put(v, "coldDirtyRate", tpl1DirtyRate);
            mo.getAttributes().put(v, "hotDirtySize", tpl1MaxDirtySize);
            mo.getAttributes().put(v, "hotDirtyDuration", tpl1MaxDirtyDuration);
            ma.addRunningVM(v, srcNodes.get(i));
            v = mo.newVM();
            vms.add(v);
            mo.getAttributes().put(v, "memUsed", tpl2MemUsed);
            mo.getAttributes().put(v, "coldDirtyRate", tpl2DirtyRate);
            mo.getAttributes().put(v, "hotDirtySize", tpl2MaxDirtySize);
            mo.getAttributes().put(v, "hotDirtyDuration", tpl2MaxDirtyDuration);
            ma.addRunningVM(v, srcNodes.get(i));
        } else {
            v = mo.newVM();
            vms.add(v);
            mo.getAttributes().put(v, "memUsed", tpl3MemUsed);
            mo.getAttributes().put(v, "coldDirtyRate", tpl3DirtyRate);
            mo.getAttributes().put(v, "hotDirtySize", tpl3MaxDirtySize);
            mo.getAttributes().put(v, "hotDirtyDuration", tpl3MaxDirtyDuration);
            ma.addRunningVM(v, srcNodes.get(i));
            v = mo.newVM();
            vms.add(v);
            mo.getAttributes().put(v, "memUsed", tpl4MemUsed);
            mo.getAttributes().put(v, "coldDirtyRate", tpl4DirtyRate);
            mo.getAttributes().put(v, "hotDirtySize", tpl4MaxDirtySize);
            mo.getAttributes().put(v, "hotDirtyDuration", tpl4MaxDirtyDuration);
            ma.addRunningVM(v, srcNodes.get(i));
        }
    }
    // Add resource decorators
    ShareableResource rcMem = new ShareableResource("mem", 0, 0);
    ShareableResource rcCPU = new ShareableResource("cpu", 0, 0);
    for (Node n : srcNodes) {
        rcMem.setCapacity(n, memSrcNode);
        rcCPU.setCapacity(n, cpuSrcNode);
    }
    for (Node n : dstNodes) {
        rcMem.setCapacity(n, memDstNode);
        rcCPU.setCapacity(n, cpuDstNode);
    }
    for (VM vm : vms) {
        rcMem.setConsumption(vm, memVM);
        rcCPU.setConsumption(vm, cpuVM);
    }
    mo.attach(rcMem);
    mo.attach(rcCPU);
    // Add a NetworkView view
    Network net = new Network();
    Switch swSrcRack1 = net.newSwitch();
    Switch swSrcRack2 = net.newSwitch();
    Switch swSrcRack3 = net.newSwitch();
    Switch swSrcRack4 = net.newSwitch();
    Switch swSrcRack5 = net.newSwitch();
    Switch swSrcRack6 = net.newSwitch();
    Switch swSrcRack7 = net.newSwitch();
    Switch swSrcRack8 = net.newSwitch();
    Switch swDstRack1 = net.newSwitch();
    Switch swDstRack2 = net.newSwitch();
    Switch swDstRack3 = net.newSwitch();
    Switch swDstRack4 = net.newSwitch();
    Switch swMain = net.newSwitch();
    net.connect(1000, swSrcRack1, srcNodes.subList(0, nbNodesRack));
    net.connect(1000, swSrcRack2, srcNodes.subList(nbNodesRack, nbNodesRack * 2));
    net.connect(1000, swSrcRack3, srcNodes.subList(nbNodesRack * 2, nbNodesRack * 3));
    net.connect(1000, swSrcRack4, srcNodes.subList(nbNodesRack * 3, nbNodesRack * 4));
    net.connect(1000, swSrcRack5, srcNodes.subList(nbNodesRack * 4, nbNodesRack * 5));
    net.connect(1000, swSrcRack6, srcNodes.subList(nbNodesRack * 5, nbNodesRack * 6));
    net.connect(1000, swSrcRack7, srcNodes.subList(nbNodesRack * 6, nbNodesRack * 7));
    net.connect(1000, swSrcRack8, srcNodes.subList(nbNodesRack * 7, nbNodesRack * 8));
    net.connect(1000, swDstRack1, dstNodes.subList(0, nbNodesRack));
    net.connect(1000, swDstRack2, dstNodes.subList(nbNodesRack, nbNodesRack * 2));
    net.connect(1000, swDstRack3, dstNodes.subList(nbNodesRack * 2, nbNodesRack * 3));
    net.connect(1000, swDstRack4, dstNodes.subList(nbNodesRack * 3, nbNodesRack * 4));
    net.connect(40000, swMain, swSrcRack1, swSrcRack2, swSrcRack3, swSrcRack4, swSrcRack5, swSrcRack6, swSrcRack7, swSrcRack8, swDstRack1, swDstRack2, swDstRack3, swDstRack4);
    mo.attach(net);
    // net.generateDot(path + "topology.dot", false);
    // Set parameters
    DefaultParameters ps = new DefaultParameters();
    ps.setVerbosity(0);
    ps.setTimeLimit(60);
    // ps.setMaxEnd(600);
    ps.doOptimize(false);
    // Migrate all VMs to destination nodes
    List<SatConstraint> cstrs = new ArrayList<>();
    int vm_num = 0;
    for (int i = 0; i < nbDstNodes; i++) {
        cstrs.add(new Fence(vms.get(vm_num), Collections.singleton(dstNodes.get(i))));
        cstrs.add(new Fence(vms.get(vm_num + 1), Collections.singleton(dstNodes.get(i))));
        cstrs.add(new Fence(vms.get(nbVMs - 1 - vm_num), Collections.singleton(dstNodes.get(i))));
        cstrs.add(new Fence(vms.get(nbVMs - 2 - vm_num), Collections.singleton(dstNodes.get(i))));
        vm_num += 2;
    }
    // Shutdown source nodes
    cstrs.addAll(srcNodes.stream().map(Offline::new).collect(Collectors.toList()));
    // Set a custom objective
    DefaultChocoScheduler sc = new DefaultChocoScheduler(ps);
    Instance i = new Instance(mo, cstrs, new MinMTTRMig());
    ReconfigurationPlan p;
    try {
        p = sc.solve(i);
        Assert.assertNotNull(p);
    } catch (Exception e) {
        e.printStackTrace();
    }
    // finally {
    return sc.getStatistics();
// }
}
Also used : SatConstraint(org.btrplace.model.constraint.SatConstraint) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) ArrayList(java.util.ArrayList) Offline(org.btrplace.model.constraint.Offline) ShareableResource(org.btrplace.model.view.ShareableResource) SatConstraint(org.btrplace.model.constraint.SatConstraint) SchedulerException(org.btrplace.scheduler.SchedulerException) MinMTTRMig(org.btrplace.model.constraint.migration.MinMTTRMig) Switch(org.btrplace.model.view.network.Switch) DefaultParameters(org.btrplace.scheduler.choco.DefaultParameters) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) Network(org.btrplace.model.view.network.Network) Fence(org.btrplace.model.constraint.Fence)

Example 2 with ShareableResource

use of org.btrplace.model.view.ShareableResource in project scheduler by btrplace.

the class OverbookTest method testContinuousIsSatisfied.

@Test
public void testContinuousIsSatisfied() {
    Model mo = new DefaultModel();
    List<VM> vms = Util.newVMs(mo, 10);
    Node n0 = mo.newNode();
    Node n1 = mo.newNode();
    Model i = new DefaultModel();
    Mapping cfg = i.getMapping();
    cfg.addOnlineNode(n0);
    cfg.addOnlineNode(n1);
    ShareableResource rc = new ShareableResource("cpu");
    rc.setCapacity(n0, 1);
    rc.setCapacity(n1, 4);
    rc.setConsumption(vms.get(0), 2);
    rc.setConsumption(vms.get(1), 2);
    rc.setConsumption(vms.get(2), 4);
    cfg.addRunningVM(vms.get(0), n0);
    cfg.addRunningVM(vms.get(1), n1);
    cfg.addRunningVM(vms.get(2), n1);
    cfg.addRunningVM(vms.get(3), n1);
    i.attach(rc);
    Overbook o = new Overbook(n1, "cpu", 2);
    o.setContinuous(true);
    ReconfigurationPlan p = new DefaultReconfigurationPlan(i);
    Assert.assertEquals(o.isSatisfied(p), true);
    p.add(new Allocate(vms.get(0), n0, "cpu", 1, 2, 5));
    Assert.assertEquals(o.isSatisfied(p), true);
    p.add(new Allocate(vms.get(1), n1, "cpu", 5, 2, 5));
    Assert.assertEquals(o.isSatisfied(p), false);
    p.add(new Allocate(vms.get(2), n1, "cpu", 2, 0, 1));
    Assert.assertEquals(o.isSatisfied(p), true);
    p.add(new Allocate(vms.get(3), n1, "cpu", 3, 4, 6));
    Assert.assertEquals(o.isSatisfied(p), false);
    p.add(new ShutdownVM(vms.get(2), n1, 2, 3));
    Assert.assertEquals(o.isSatisfied(p), true);
}
Also used : DefaultReconfigurationPlan(org.btrplace.plan.DefaultReconfigurationPlan) ShutdownVM(org.btrplace.plan.event.ShutdownVM) DefaultReconfigurationPlan(org.btrplace.plan.DefaultReconfigurationPlan) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) ShareableResource(org.btrplace.model.view.ShareableResource) ShutdownVM(org.btrplace.plan.event.ShutdownVM) Allocate(org.btrplace.plan.event.Allocate) Test(org.testng.annotations.Test)

Example 3 with ShareableResource

use of org.btrplace.model.view.ShareableResource in project scheduler by btrplace.

the class ResourceCapacityTest method testContinuousIsSatisfied.

@Test
public void testContinuousIsSatisfied() {
    Model mo = new DefaultModel();
    List<Node> ns = Util.newNodes(mo, 10);
    List<VM> vms = Util.newVMs(mo, 10);
    Mapping map = mo.getMapping();
    map.addOnlineNode(ns.get(0));
    map.addOnlineNode(ns.get(1));
    map.addOnlineNode(ns.get(2));
    map.addRunningVM(vms.get(0), ns.get(0));
    map.addRunningVM(vms.get(1), ns.get(0));
    map.addRunningVM(vms.get(2), ns.get(1));
    map.addRunningVM(vms.get(3), ns.get(2));
    map.addReadyVM(vms.get(4));
    ShareableResource rc = new ShareableResource("foo", 1, 1);
    mo.attach(rc);
    Set<Node> nodes = new HashSet<>(Arrays.asList(ns.get(0), ns.get(1)));
    ResourceCapacity cc = new ResourceCapacity(nodes, "foo", 4, true);
    ReconfigurationPlan plan = new DefaultReconfigurationPlan(mo);
    Assert.assertEquals(cc.isSatisfied(plan), true);
    // 3/4
    MigrateVM m = new MigrateVM(vms.get(3), ns.get(2), ns.get(1), 0, 1);
    m.addEvent(Action.Hook.POST, new AllocateEvent(vms.get(3), "foo", 2));
    plan.add(m);
    // 5/4
    plan.add(new ShutdownVM(vms.get(2), ns.get(1), 1, 2));
    // 4/4
    plan.add(new BootVM(vms.get(4), ns.get(2), 2, 3));
    // 4/4
    plan.add(new Allocate(vms.get(1), ns.get(0), "foo", 2, 2, 3));
    // 5/4
    plan.add(new MigrateVM(vms.get(0), ns.get(0), ns.get(2), 3, 4));
    System.out.println(plan);
    Assert.assertEquals(cc.isSatisfied(plan), true);
}
Also used : DefaultReconfigurationPlan(org.btrplace.plan.DefaultReconfigurationPlan) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) ShareableResource(org.btrplace.model.view.ShareableResource) DefaultReconfigurationPlan(org.btrplace.plan.DefaultReconfigurationPlan) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 4 with ShareableResource

use of org.btrplace.model.view.ShareableResource in project scheduler by btrplace.

the class DependenciesExtractorTest method testDependencyWithAllocate.

@Test
public void testDependencyWithAllocate() {
    // An increase allocation is impossible until a decreasing allocation
    Model mo = new DefaultModel();
    Mapping map = mo.getMapping();
    map.addOnlineNode(ns.get(0));
    map.addRunningVM(vms.get(0), ns.get(0));
    map.addRunningVM(vms.get(1), ns.get(0));
    ShareableResource rc = new ShareableResource("cpu", 0, 0);
    rc.setConsumption(vms.get(0), 3);
    rc.setConsumption(vms.get(1), 5);
    mo.attach(rc);
    DependenciesExtractor ex = new DependenciesExtractor(mo);
    // 3->5
    Allocate a1 = new Allocate(vms.get(0), ns.get(0), "cpu", 5, 5, 7);
    // 5->3
    Allocate a2 = new Allocate(vms.get(1), ns.get(0), "cpu", 3, 0, 3);
    Assert.assertTrue(ex.visit(a1));
    Assert.assertTrue(ex.visit(a2));
    Assert.assertTrue(ex.getDependencies(a2).isEmpty(), ex.getDependencies(a2).toString());
    Assert.assertEquals(ex.getDependencies(a1).size(), 1, ex.getDependencies(a1).toString());
    Assert.assertTrue(ex.getDependencies(a1).contains(a2), ex.getDependencies(a1).toString());
}
Also used : ShareableResource(org.btrplace.model.view.ShareableResource) Test(org.testng.annotations.Test)

Example 5 with ShareableResource

use of org.btrplace.model.view.ShareableResource in project scheduler by btrplace.

the class DependencyBasedPlanApplierTest method testApply.

@Test
public void testApply() {
    Model mo = new DefaultModel();
    List<VM> vms = Util.newVMs(mo, 10);
    List<Node> ns = Util.newNodes(mo, 10);
    Mapping map = mo.getMapping();
    map.addOnlineNode(ns.get(0));
    map.addOnlineNode(ns.get(1));
    map.addOnlineNode(ns.get(2));
    map.addOfflineNode(ns.get(3));
    map.addRunningVM(vms.get(0), ns.get(2));
    map.addRunningVM(vms.get(1), ns.get(0));
    map.addRunningVM(vms.get(2), ns.get(1));
    map.addRunningVM(vms.get(3), ns.get(1));
    BootNode bN4 = new BootNode(ns.get(3), 3, 5);
    MigrateVM mVM1 = new MigrateVM(vms.get(0), ns.get(2), ns.get(3), 6, 7);
    Allocate aVM3 = new Allocate(vms.get(2), ns.get(1), "cpu", 7, 8, 9);
    MigrateVM mVM2 = new MigrateVM(vms.get(1), ns.get(0), ns.get(1), 1, 3);
    MigrateVM mVM4 = new MigrateVM(vms.get(3), ns.get(1), ns.get(2), 1, 7);
    ShutdownNode sN1 = new ShutdownNode(ns.get(0), 5, 7);
    ShareableResource rc = new ShareableResource("cpu");
    rc.setConsumption(vms.get(2), 3);
    mo.attach(rc);
    ReconfigurationPlan plan = new DefaultReconfigurationPlan(mo);
    plan.add(bN4);
    plan.add(mVM1);
    plan.add(aVM3);
    plan.add(mVM2);
    plan.add(mVM4);
    plan.add(sN1);
    Model res = new DependencyBasedPlanApplier().apply(plan);
    Assert.assertNotNull(res);
    Mapping resMapping = res.getMapping();
    Assert.assertTrue(resMapping.isOffline(ns.get(0)));
    Assert.assertTrue(resMapping.isOnline(ns.get(3)));
    rc = ShareableResource.get(res, "cpu");
    Assert.assertEquals(rc.getConsumption(vms.get(2)), 7);
    Assert.assertEquals(resMapping.getVMLocation(vms.get(0)), ns.get(3));
    Assert.assertEquals(resMapping.getVMLocation(vms.get(1)), ns.get(1));
    Assert.assertEquals(resMapping.getVMLocation(vms.get(3)), ns.get(2));
}
Also used : BootNode(org.btrplace.plan.event.BootNode) ShutdownNode(org.btrplace.plan.event.ShutdownNode) BootNode(org.btrplace.plan.event.BootNode) MigrateVM(org.btrplace.plan.event.MigrateVM) ShareableResource(org.btrplace.model.view.ShareableResource) MigrateVM(org.btrplace.plan.event.MigrateVM) ShutdownNode(org.btrplace.plan.event.ShutdownNode) Allocate(org.btrplace.plan.event.Allocate) Test(org.testng.annotations.Test)

Aggregations

ShareableResource (org.btrplace.model.view.ShareableResource)86 Test (org.testng.annotations.Test)61 ReconfigurationPlan (org.btrplace.plan.ReconfigurationPlan)47 DefaultChocoScheduler (org.btrplace.scheduler.choco.DefaultChocoScheduler)41 SatConstraint (org.btrplace.model.constraint.SatConstraint)32 ArrayList (java.util.ArrayList)31 ChocoScheduler (org.btrplace.scheduler.choco.ChocoScheduler)29 VM (org.btrplace.model.VM)27 Model (org.btrplace.model.Model)25 Node (org.btrplace.model.Node)25 DefaultModel (org.btrplace.model.DefaultModel)22 MigrateVM (org.btrplace.plan.event.MigrateVM)16 Mapping (org.btrplace.model.Mapping)13 Network (org.btrplace.model.view.network.Network)12 Switch (org.btrplace.model.view.network.Switch)12 Offline (org.btrplace.model.constraint.Offline)11 MinMTTRMig (org.btrplace.model.constraint.migration.MinMTTRMig)10 SchedulerException (org.btrplace.scheduler.SchedulerException)10 Fence (org.btrplace.model.constraint.Fence)7 Preserve (org.btrplace.model.constraint.Preserve)7