Search in sources :

Example 6 with SchedulerException

use of org.btrplace.scheduler.SchedulerException in project scheduler by btrplace.

the class Bench method benchHA.

public static void benchHA(int nbSamples, Integer partSize, Integer ratio, Integer nbParts) {
    Model mo = new DefaultModel();
    Instance inst = new Instance(mo, new MinMTTR());
    int nbNodes = partSize * nbParts;
    int nbVMs = ratio * nbNodes;
    // Make the infrastructure
    List<Node> l = makeNodeList(mo, nbNodes);
    ShareableResource rcCpu = new ShareableResource("cpu", 20, 0);
    ShareableResource rcMem = new ShareableResource("mem", 16, /*GB*/
    0);
    List<Collection<Node>> edges = makeEdges(l, 250);
    mo.attach(rcCpu);
    mo.attach(rcMem);
    while (nbVMs != 0) {
        nbVMs -= makeApp(inst, nbVMs, edges);
    }
    FixedSizePartitioning partitioner = new FixedSizePartitioning(partSize);
    try {
        for (int x = 0; x < nbSamples; x++) {
            long start = System.currentTimeMillis();
            List<Instance> instances = partitioner.split(new DefaultParameters(), inst);
            long end = System.currentTimeMillis();
            System.err.println(instances.size() + " " + nbNodes + " " + nbNodes * ratio + " " + inst.getSatConstraints().size() + " " + (end - start));
        }
    } catch (SchedulerException ex) {
        Assert.fail(ex.getMessage(), ex);
    }
}
Also used : SchedulerException(org.btrplace.scheduler.SchedulerException) MinMTTR(org.btrplace.model.constraint.MinMTTR) ShareableResource(org.btrplace.model.view.ShareableResource) DefaultParameters(org.btrplace.scheduler.choco.DefaultParameters)

Example 7 with SchedulerException

use of org.btrplace.scheduler.SchedulerException in project scheduler by btrplace.

the class DefaultChocoScheduler method solve.

@Override
public ReconfigurationPlan solve(Instance i) throws SchedulerException {
    Model mo = i.getModel();
    Collection<SatConstraint> cstrs = i.getSatConstraints();
    // If a network view is attached, ensure that all the migrations' destination node are defined
    Network net = Network.get(mo);
    stages = null;
    if (net != null) {
        // The network view is useless to take placement decisions
        mo.detach(net);
        // Solve a first time using placement oriented MinMTTR optimisation constraint
        ReconfigurationPlan p = runner.solve(params, i);
        stages = new StagedSolvingStatistics(runner.getStatistics());
        if (p == null) {
            return null;
        }
        // Add Fence constraints for each destination node chosen
        List<SatConstraint> newCstrs = p.getActions().stream().filter(a -> a instanceof MigrateVM).map(a -> new Fence(((MigrateVM) a).getVM(), Collections.singleton(((MigrateVM) a).getDestinationNode()))).collect(Collectors.toList());
        Model result = p.getResult();
        if (result == null) {
            throw new InconsistentSolutionException(mo, p, "The plan cannot be applied");
        }
        // Add Root constraints to all staying VMs
        newCstrs.addAll(mo.getMapping().getRunningVMs().stream().filter(v -> p.getOrigin().getMapping().getVMLocation(v).id() == result.getMapping().getVMLocation(v).id()).map(Root::new).collect(Collectors.toList()));
        // Add the old constraints
        newCstrs.addAll(cstrs);
        // Re-attach the network view
        mo.attach(net);
        // New timeout value = elapsed time - initial timeout value
        Parameters ps = new DefaultParameters(params);
        if (ps.getTimeLimit() > 0) {
            // in seconds
            double timeout = params.getTimeLimit() - runner.getStatistics().getMetrics().timeCount() / 1000;
            ps.setTimeLimit((int) timeout);
        }
        return runner.solve(ps, new Instance(mo, newCstrs, i.getOptConstraint()));
    }
    // Solve and return the computed plan
    return runner.solve(params, new Instance(mo, cstrs, i.getOptConstraint()));
}
Also used : ChocoView(org.btrplace.scheduler.choco.view.ChocoView) Root(org.btrplace.model.constraint.Root) SchedulerException(org.btrplace.scheduler.SchedulerException) MigrateVM(org.btrplace.plan.event.MigrateVM) SolvingStatistics(org.btrplace.scheduler.choco.runner.SolvingStatistics) Fence(org.btrplace.model.constraint.Fence) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) SingleRunner(org.btrplace.scheduler.choco.runner.single.SingleRunner) BiConsumer(java.util.function.BiConsumer) ChocoMapper(org.btrplace.scheduler.choco.constraint.ChocoMapper) SatConstraint(org.btrplace.model.constraint.SatConstraint) Model(org.btrplace.model.Model) StagedSolvingStatistics(org.btrplace.scheduler.choco.runner.StagedSolvingStatistics) DurationEvaluators(org.btrplace.scheduler.choco.duration.DurationEvaluators) Collection(java.util.Collection) TransitionFactory(org.btrplace.scheduler.choco.transition.TransitionFactory) Collectors(java.util.stream.Collectors) MinMTTR(org.btrplace.model.constraint.MinMTTR) InconsistentSolutionException(org.btrplace.scheduler.InconsistentSolutionException) List(java.util.List) Instance(org.btrplace.model.Instance) InstanceSolver(org.btrplace.scheduler.choco.runner.InstanceSolver) Collections(java.util.Collections) Network(org.btrplace.model.view.network.Network) Settings(org.chocosolver.solver.Settings) InconsistentSolutionException(org.btrplace.scheduler.InconsistentSolutionException) Root(org.btrplace.model.constraint.Root) Instance(org.btrplace.model.Instance) SatConstraint(org.btrplace.model.constraint.SatConstraint) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) MigrateVM(org.btrplace.plan.event.MigrateVM) StagedSolvingStatistics(org.btrplace.scheduler.choco.runner.StagedSolvingStatistics) Network(org.btrplace.model.view.network.Network) Model(org.btrplace.model.Model) Fence(org.btrplace.model.constraint.Fence)

Example 8 with SchedulerException

use of org.btrplace.scheduler.SchedulerException in project scheduler by btrplace.

the class InstanceSolverRunner method makeViews.

private List<ChocoView> makeViews() throws SchedulerException {
    List<ChocoView> l = new ArrayList<>();
    ChocoMapper mapper = params.getMapper();
    origin.getViews().stream().filter(v -> mapper.viewHasMapping(v.getClass())).forEach(v -> l.add(mapper.get(v)));
    return l;
}
Also used : ChocoView(org.btrplace.scheduler.choco.view.ChocoView) LifeCycleViolationException(org.btrplace.scheduler.choco.LifeCycleViolationException) ChocoView(org.btrplace.scheduler.choco.view.ChocoView) Ready(org.btrplace.model.constraint.Ready) MeasuresRecorder(org.chocosolver.solver.search.measure.MeasuresRecorder) SchedulerException(org.btrplace.scheduler.SchedulerException) Node(org.btrplace.model.Node) OptConstraint(org.btrplace.model.constraint.OptConstraint) ContradictionException(org.chocosolver.solver.exception.ContradictionException) Callable(java.util.concurrent.Callable) SolvingStatistics(org.btrplace.scheduler.choco.runner.SolvingStatistics) CObjective(org.btrplace.scheduler.choco.constraint.CObjective) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) DefaultReconfigurationProblemBuilder(org.btrplace.scheduler.choco.DefaultReconfigurationProblemBuilder) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) VM(org.btrplace.model.VM) Running(org.btrplace.model.constraint.Running) SchedulerModelingException(org.btrplace.scheduler.SchedulerModelingException) Measures(org.chocosolver.solver.search.measure.Measures) ReconfigurationProblem(org.btrplace.scheduler.choco.ReconfigurationProblem) IMonitorSolution(org.chocosolver.solver.search.loop.monitors.IMonitorSolution) SearchState(org.chocosolver.solver.search.SearchState) ChocoMapper(org.btrplace.scheduler.choco.constraint.ChocoMapper) SatConstraint(org.btrplace.model.constraint.SatConstraint) Model(org.btrplace.model.Model) Sleeping(org.btrplace.model.constraint.Sleeping) Constraint(org.btrplace.model.constraint.Constraint) Collection(java.util.Collection) SolutionStatistics(org.btrplace.scheduler.choco.runner.SolutionStatistics) Set(java.util.Set) ChocoConstraint(org.btrplace.scheduler.choco.constraint.ChocoConstraint) Cause(org.chocosolver.solver.Cause) Parameters(org.btrplace.scheduler.choco.Parameters) IntVar(org.chocosolver.solver.variables.IntVar) List(java.util.List) Killed(org.btrplace.model.constraint.Killed) Metrics(org.btrplace.scheduler.choco.runner.Metrics) ChocoViews(org.btrplace.scheduler.choco.view.ChocoViews) Solution(org.chocosolver.solver.Solution) Optional(java.util.Optional) Instance(org.btrplace.model.Instance) ChocoMapper(org.btrplace.scheduler.choco.constraint.ChocoMapper) ArrayList(java.util.ArrayList)

Example 9 with SchedulerException

use of org.btrplace.scheduler.SchedulerException in project scheduler by btrplace.

the class DefaultReconfigurationProblemTest method testMinimize.

/**
 * Test a minimization problem: use the minimum number of nodes.
 *
 * @throws org.btrplace.scheduler.SchedulerException
 */
@Test
public void testMinimize() throws SchedulerException {
    Model mo = new DefaultModel();
    Mapping map = mo.getMapping();
    for (int i = 0; i < 10; i++) {
        Node n = mo.newNode();
        VM vm = mo.newVM();
        map.addOnlineNode(n);
        map.addRunningVM(vm, n);
    }
    Parameters ps = new DefaultParameters();
    ReconfigurationProblem rp = new DefaultReconfigurationProblemBuilder(mo).setParams(ps).build();
    Solver s = rp.getSolver();
    IntVar nbNodes = rp.getModel().intVar("nbNodes", 1, map.getAllNodes().size(), true);
    Stream<Slice> dSlices = rp.getVMActions().stream().filter(t -> t.getDSlice() != null).map(VMTransition::getDSlice);
    IntVar[] hosters = dSlices.map(Slice::getHoster).toArray(IntVar[]::new);
    rp.getModel().post(rp.getModel().atMostNValues(hosters, nbNodes, true));
    rp.setObjective(true, nbNodes);
    ReconfigurationPlan plan = rp.solve(-1, true);
    Assert.assertNotNull(plan);
    Assert.assertEquals(s.getMeasures().getSolutionCount(), 1);
    Mapping dst = plan.getResult().getMapping();
    Assert.assertEquals(usedNodes(dst), 1);
}
Also used : ShutdownableNode(org.btrplace.scheduler.choco.transition.ShutdownableNode) ChocoView(org.btrplace.scheduler.choco.view.ChocoView) Arrays(java.util.Arrays) SchedulerException(org.btrplace.scheduler.SchedulerException) SuspendVM(org.btrplace.scheduler.choco.transition.SuspendVM) Node(org.btrplace.model.Node) ModelView(org.btrplace.model.view.ModelView) UnstatableProblemException(org.btrplace.scheduler.UnstatableProblemException) NodeTransition(org.btrplace.scheduler.choco.transition.NodeTransition) ContradictionException(org.chocosolver.solver.exception.ContradictionException) Test(org.testng.annotations.Test) Solver(org.chocosolver.solver.Solver) RelocatableVM(org.btrplace.scheduler.choco.transition.RelocatableVM) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) HashSet(java.util.HashSet) VM(org.btrplace.model.VM) BootableNode(org.btrplace.scheduler.choco.transition.BootableNode) Assert(org.testng.Assert) Mapping(org.btrplace.model.Mapping) StayAwayVM(org.btrplace.scheduler.choco.transition.StayAwayVM) Model(org.btrplace.model.Model) DurationEvaluators(org.btrplace.scheduler.choco.duration.DurationEvaluators) ResumeVM(org.btrplace.scheduler.choco.transition.ResumeVM) Set(java.util.Set) DefaultModel(org.btrplace.model.DefaultModel) Cause(org.chocosolver.solver.Cause) VMTransition(org.btrplace.scheduler.choco.transition.VMTransition) IntVar(org.chocosolver.solver.variables.IntVar) Stream(java.util.stream.Stream) KillVM(org.btrplace.scheduler.choco.transition.KillVM) CMinMTTR(org.btrplace.scheduler.choco.constraint.mttr.CMinMTTR) BootVM(org.btrplace.scheduler.choco.transition.BootVM) ForgeVM(org.btrplace.scheduler.choco.transition.ForgeVM) ShutdownVM(org.btrplace.scheduler.choco.transition.ShutdownVM) ShareableResource(org.btrplace.model.view.ShareableResource) Solution(org.chocosolver.solver.Solution) Collections(java.util.Collections) DefaultModel(org.btrplace.model.DefaultModel) Solver(org.chocosolver.solver.Solver) ShutdownableNode(org.btrplace.scheduler.choco.transition.ShutdownableNode) Node(org.btrplace.model.Node) BootableNode(org.btrplace.scheduler.choco.transition.BootableNode) ReconfigurationPlan(org.btrplace.plan.ReconfigurationPlan) VMTransition(org.btrplace.scheduler.choco.transition.VMTransition) Mapping(org.btrplace.model.Mapping) IntVar(org.chocosolver.solver.variables.IntVar) SuspendVM(org.btrplace.scheduler.choco.transition.SuspendVM) RelocatableVM(org.btrplace.scheduler.choco.transition.RelocatableVM) VM(org.btrplace.model.VM) StayAwayVM(org.btrplace.scheduler.choco.transition.StayAwayVM) ResumeVM(org.btrplace.scheduler.choco.transition.ResumeVM) KillVM(org.btrplace.scheduler.choco.transition.KillVM) BootVM(org.btrplace.scheduler.choco.transition.BootVM) ForgeVM(org.btrplace.scheduler.choco.transition.ForgeVM) ShutdownVM(org.btrplace.scheduler.choco.transition.ShutdownVM) Model(org.btrplace.model.Model) DefaultModel(org.btrplace.model.DefaultModel) Test(org.testng.annotations.Test)

Example 10 with SchedulerException

use of org.btrplace.scheduler.SchedulerException 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)

Aggregations

SchedulerException (org.btrplace.scheduler.SchedulerException)17 SatConstraint (org.btrplace.model.constraint.SatConstraint)12 ReconfigurationPlan (org.btrplace.plan.ReconfigurationPlan)11 ArrayList (java.util.ArrayList)10 ShareableResource (org.btrplace.model.view.ShareableResource)10 DefaultChocoScheduler (org.btrplace.scheduler.choco.DefaultChocoScheduler)10 Model (org.btrplace.model.Model)7 Network (org.btrplace.model.view.network.Network)7 Node (org.btrplace.model.Node)6 Fence (org.btrplace.model.constraint.Fence)6 MinMTTRMig (org.btrplace.model.constraint.migration.MinMTTRMig)6 Test (org.testng.annotations.Test)6 List (java.util.List)5 VM (org.btrplace.model.VM)5 Offline (org.btrplace.model.constraint.Offline)5 Switch (org.btrplace.model.view.network.Switch)5 MigrateVM (org.btrplace.plan.event.MigrateVM)5 DefaultParameters (org.btrplace.scheduler.choco.DefaultParameters)5 SolvingStatistics (org.btrplace.scheduler.choco.runner.SolvingStatistics)5 DefaultModel (org.btrplace.model.DefaultModel)4