Search in sources :

Example 46 with SatConstraint

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

the class SingleRunnerStatisticsTest method testInstantiate.

@Test
public void testInstantiate() {
    Parameters ps = new DefaultParameters();
    Model mo = new DefaultModel();
    long st = System.currentTimeMillis();
    List<SatConstraint> cstrs = new ArrayList<>();
    Instance i = new Instance(mo, cstrs, new MinMTTR());
    SingleRunnerStatistics stats = new SingleRunnerStatistics(ps, i, st);
    Assert.assertEquals(stats.getStart(), st);
    Assert.assertEquals(stats.getCoreBuildDuration(), -1);
    Assert.assertEquals(stats.getSpecializationDuration(), -1);
    Assert.assertEquals(stats.getInstance(), i);
    Assert.assertEquals(stats.getNbManagedVMs(), -1);
    Assert.assertEquals(stats.getParameters(), ps);
    Assert.assertEquals(stats.getSolutions().size(), 0);
    Assert.assertEquals(stats.completed(), false);
    Assert.assertEquals(stats.getMetrics(), null);
    stats.setCoreBuildDuration(12);
    stats.setSpecialisationDuration(17);
    stats.setNbManagedVMs(18);
    stats.setCompleted(true);
    Assert.assertEquals(stats.getCoreBuildDuration(), 12);
    Assert.assertEquals(stats.getSpecializationDuration(), 17);
    Assert.assertEquals(stats.getNbManagedVMs(), 18);
    Assert.assertEquals(stats.completed(), true);
    ReconfigurationPlan plan = new DefaultReconfigurationPlan(mo);
    SolutionStatistics sol = new SolutionStatistics(new Metrics(), plan);
    stats.addSolution(sol);
    Assert.assertEquals(stats.getSolutions().size(), 1);
    Assert.assertEquals(stats.getSolutions().get(0), sol);
}
Also used : DefaultModel(org.btrplace.model.DefaultModel) Parameters(org.btrplace.scheduler.choco.Parameters) DefaultParameters(org.btrplace.scheduler.choco.DefaultParameters) Instance(org.btrplace.model.Instance) SatConstraint(org.btrplace.model.constraint.SatConstraint) DefaultReconfigurationPlan(org.btrplace.plan.DefaultReconfigurationPlan) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) SolutionStatistics(org.btrplace.scheduler.choco.runner.SolutionStatistics) ArrayList(java.util.ArrayList) MinMTTR(org.btrplace.model.constraint.MinMTTR) DefaultReconfigurationPlan(org.btrplace.plan.DefaultReconfigurationPlan) Metrics(org.btrplace.scheduler.choco.runner.Metrics) DefaultParameters(org.btrplace.scheduler.choco.DefaultParameters) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) Test(org.testng.annotations.Test)

Example 47 with SatConstraint

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

the class CNetworkTest method defaultTest.

/**
 * Test the instantiation and the creation of the variables.
 *
 * @throws org.btrplace.scheduler.SchedulerException if an error occurs during the solving process (it should not)
 */
@Test
public void defaultTest() throws SchedulerException {
    // New default model
    Model mo = new DefaultModel();
    Mapping ma = mo.getMapping();
    // Create and boot 1 source and 1 destination node
    Node srcNode = mo.newNode(), dstNode = mo.newNode();
    ma.addOnlineNode(srcNode);
    ma.addOnlineNode(dstNode);
    // Attach a network view
    Network net = new Network();
    mo.attach(net);
    // Connect the nodes through a main non-blocking switch using 1 Gbit/s links
    Switch swMain = net.newSwitch();
    int bw = 1000;
    net.connect(bw, swMain, srcNode, dstNode);
    // Create and host 1 running VM on the source node
    VM vm = mo.newVM();
    ma.addRunningVM(vm, srcNode);
    // The VM consumes 6 GiB memory and has a memory intensive workload equivalent to "stress --vm 1000 --bytes 50K"
    int memUsed = 6000, hotDirtySize = 46, hotDirtyDuration = 2;
    double coldDirtyRate = 23.6;
    // 6 GiB
    mo.getAttributes().put(vm, "memUsed", memUsed);
    // 46 MiB
    mo.getAttributes().put(vm, "hotDirtySize", hotDirtySize);
    // 2 sec.
    mo.getAttributes().put(vm, "hotDirtyDuration", hotDirtyDuration);
    // 23.6 MiB/sec.
    mo.getAttributes().put(vm, "coldDirtyRate", coldDirtyRate);
    // Add constraints
    List<SatConstraint> cstrs = new ArrayList<>();
    // We force the migration to go on the destination node
    cstrs.add(new Fence(vm, Collections.singleton(dstNode)));
    // Try to solve using the custom Min MTTR objective for migration scheduling
    ReconfigurationPlan p = new DefaultChocoScheduler().solve(mo, cstrs, new MinMTTRMig());
    Assert.assertNotNull(p);
    // The switch is non-blocking
    Assert.assertEquals(swMain.getCapacity(), Integer.MAX_VALUE);
    // Check the migration path and bandwidth
    MigrateVM mig = (MigrateVM) p.getActions().stream().filter(s -> s instanceof MigrateVM).findFirst().get();
    Assert.assertTrue(net.getRouting().getPath(mig.getSourceNode(), mig.getDestinationNode()).containsAll(net.getLinks()));
    Assert.assertEquals(net.getRouting().getMaxBW(mig.getSourceNode(), mig.getDestinationNode()), bw);
    Assert.assertEquals(mig.getBandwidth(), bw);
    // Check the migration duration computation
    double bandwidth_octet = mig.getBandwidth() / 9, durationMin, durationColdPages, durationHotPages, durationTotal;
    durationMin = memUsed / bandwidth_octet;
    durationColdPages = ((hotDirtySize + ((durationMin - hotDirtyDuration) * coldDirtyRate)) / (bandwidth_octet - coldDirtyRate));
    durationHotPages = ((hotDirtySize / bandwidth_octet) * ((hotDirtySize / hotDirtyDuration) / (bandwidth_octet - (hotDirtySize / hotDirtyDuration))));
    durationTotal = durationMin + durationColdPages + durationHotPages;
    Assert.assertEquals((mig.getEnd() - mig.getStart()), (int) Math.round(durationTotal));
}
Also used : SchedulerException(org.btrplace.scheduler.SchedulerException) MigrateVM(org.btrplace.plan.event.MigrateVM) Test(org.testng.annotations.Test) MinMTTRMig(org.btrplace.model.constraint.migration.MinMTTRMig) Fence(org.btrplace.model.constraint.Fence) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) ArrayList(java.util.ArrayList) List(java.util.List) Assert(org.testng.Assert) org.btrplace.model(org.btrplace.model) ShareableResource(org.btrplace.model.view.ShareableResource) Switch(org.btrplace.model.view.network.Switch) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) Collections(java.util.Collections) Network(org.btrplace.model.view.network.Network) SatConstraint(org.btrplace.model.constraint.SatConstraint) ChocoScheduler(org.btrplace.scheduler.choco.ChocoScheduler) SatConstraint(org.btrplace.model.constraint.SatConstraint) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) ArrayList(java.util.ArrayList) MigrateVM(org.btrplace.plan.event.MigrateVM) SatConstraint(org.btrplace.model.constraint.SatConstraint) MinMTTRMig(org.btrplace.model.constraint.migration.MinMTTRMig) Switch(org.btrplace.model.view.network.Switch) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) Network(org.btrplace.model.view.network.Network) MigrateVM(org.btrplace.plan.event.MigrateVM) Fence(org.btrplace.model.constraint.Fence) Test(org.testng.annotations.Test)

Example 48 with SatConstraint

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

the class CShareableResourceTest method testRealNodeUsage.

/**
 * Place some VMs and check realNodeUsage is updated accordingly
 */
@Test
public void testRealNodeUsage() throws SchedulerException {
    Model mo = new DefaultModel();
    Mapping ma = mo.getMapping();
    VM vm1 = mo.newVM();
    VM vm2 = mo.newVM();
    Node n1 = mo.newNode();
    Node n2 = mo.newNode();
    ma.addOnlineNode(n1);
    ma.addOnlineNode(n2);
    ma.addRunningVM(vm1, n1);
    ma.addRunningVM(vm2, n1);
    ShareableResource rc = new ShareableResource("foo", 0, 0);
    rc.setConsumption(vm1, 2);
    rc.setConsumption(vm2, 3);
    rc.setCapacity(n1, 5);
    rc.setCapacity(n2, 3);
    mo.attach(rc);
    ChocoScheduler s = new DefaultChocoScheduler();
    List<SatConstraint> cstrs = new ArrayList<>();
    cstrs.add(new Fence(vm1, n1));
    cstrs.add(new Fence(vm2, n2));
    ReconfigurationPlan p = s.solve(mo, cstrs);
    Assert.assertNotNull(p);
    Model res = p.getResult();
    rc = (ShareableResource.get(res, "foo"));
    // rcm.getVirtualUsage(0).isInstantiatedTo(2));
    Assert.assertEquals(2, rc.getConsumption(vm1));
    // rcm.getVirtualUsage(1).isInstantiatedTo(3));
    Assert.assertEquals(3, rc.getConsumption(vm2));
}
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) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) ChocoScheduler(org.btrplace.scheduler.choco.ChocoScheduler) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) VM(org.btrplace.model.VM) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) Fence(org.btrplace.model.constraint.Fence) Test(org.testng.annotations.Test)

Example 49 with SatConstraint

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

the class CShareableResourceTest method testMisplaced.

@Test
public void testMisplaced() throws SchedulerException {
    Model mo = new DefaultModel();
    Node n1 = mo.newNode();
    Node n2 = mo.newNode();
    ShareableResource rc = new ShareableResource("cpu", 10, 1);
    VM v1 = mo.newVM();
    VM v2 = mo.newVM();
    mo.getMapping().addOnlineNode(n1);
    mo.getMapping().addOnlineNode(n2);
    mo.getMapping().addRunningVM(v1, n1);
    mo.getMapping().addRunningVM(v2, n1);
    mo.attach(rc);
    List<SatConstraint> l = new ArrayList<>();
    l.addAll(Preserve.newPreserve(mo.getMapping().getAllVMs(), "cpu", 5));
    ChocoScheduler s = new DefaultChocoScheduler();
    s.doRepair(true);
    ReconfigurationPlan p = s.solve(mo, l);
    Assert.assertEquals(s.getStatistics().getNbManagedVMs(), 0);
    Assert.assertNotNull(p);
    Assert.assertEquals(p.getResult().getMapping(), mo.getMapping());
    Assert.assertEquals(p.getSize(), 2);
}
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) Test(org.testng.annotations.Test)

Example 50 with SatConstraint

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

the class SolverTuning method run.

@Override
@SuppressWarnings("squid:S1166")
public void run() {
    // Make a default model with 500 nodes hosting 3,000 VMs
    Model model = makeModel();
    Set<SatConstraint> constraints = new HashSet<>();
    // We allow memory over-commitment with a overbooking ratio of 50%
    // i.e. 1MB physical RAM for 1.5MB virtual RAM
    constraints.addAll(Overbook.newOverbooks(model.getMapping().getAllNodes(), "mem", 1.5));
    /**
     * On 10 nodes, 4 of the 6 hosted VMs ask now for a 4GB bandwidth
     */
    for (int i = 0; i < 5; i++) {
        Node n = nodes.get(i);
        Set<VM> vmsOnN = model.getMapping().getRunningVMs(n);
        Iterator<VM> ite = vmsOnN.iterator();
        for (int j = 0; ite.hasNext() && j < 4; j++) {
            VM v = ite.next();
            constraints.add(new Preserve(v, "bandwidth", 4));
        }
    }
    ChocoScheduler cra = new DefaultChocoScheduler();
    // Customize the estimated duration of actions
    cra.getDurationEvaluators().register(MigrateVM.class, new LinearToAResourceActionDuration<VM>("mem", 1, 3));
    // We want the best possible solution, computed in up to 5 sec.
    cra.doOptimize(true);
    cra.setTimeLimit(5);
    // We solve without the repair mode
    cra.doRepair(false);
    try {
        solve(cra, model, constraints);
    } catch (@SuppressWarnings("unused") SchedulerException ex) {
    // Just in case the testing environment is not performant enough
    // It does not matter that much if there is no enough time to get a solution here
    }
    // Re-solve using the repair mode to check for the improvement
    cra.doRepair(true);
    solve(cra, model, constraints);
}
Also used : SchedulerException(org.btrplace.scheduler.SchedulerException) SatConstraint(org.btrplace.model.constraint.SatConstraint) SatConstraint(org.btrplace.model.constraint.SatConstraint) Preserve(org.btrplace.model.constraint.Preserve) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) ChocoScheduler(org.btrplace.scheduler.choco.ChocoScheduler) DefaultChocoScheduler(org.btrplace.scheduler.choco.DefaultChocoScheduler) MigrateVM(org.btrplace.plan.event.MigrateVM)

Aggregations

SatConstraint (org.btrplace.model.constraint.SatConstraint)78 Test (org.testng.annotations.Test)54 ReconfigurationPlan (org.btrplace.plan.ReconfigurationPlan)43 ArrayList (java.util.ArrayList)39 DefaultChocoScheduler (org.btrplace.scheduler.choco.DefaultChocoScheduler)38 DefaultModel (org.btrplace.model.DefaultModel)33 ShareableResource (org.btrplace.model.view.ShareableResource)30 VM (org.btrplace.model.VM)27 ChocoScheduler (org.btrplace.scheduler.choco.ChocoScheduler)27 Node (org.btrplace.model.Node)23 Model (org.btrplace.model.Model)20 HashSet (java.util.HashSet)17 Fence (org.btrplace.model.constraint.Fence)16 ScriptBuilder (org.btrplace.btrpsl.ScriptBuilder)14 Network (org.btrplace.model.view.network.Network)14 Offline (org.btrplace.model.constraint.Offline)13 Switch (org.btrplace.model.view.network.Switch)13 MigrateVM (org.btrplace.plan.event.MigrateVM)13 MinMTTRMig (org.btrplace.model.constraint.migration.MinMTTRMig)11 Preserve (org.btrplace.model.constraint.Preserve)9