Search in sources :

Example 6 with RelocatableVM

use of org.btrplace.scheduler.choco.transition.RelocatableVM in project scheduler by btrplace.

the class CMinMTTR method injectPlacementHeuristic.

private void injectPlacementHeuristic(ReconfigurationProblem p, Parameters ps, IntVar cost) {
    List<CShareableResource> rcs = rp.getSourceModel().getViews().stream().filter(v -> v instanceof ShareableResource).map(v -> (CShareableResource) rp.getRequiredView(v.getIdentifier())).collect(Collectors.toList());
    useResources = !rcs.isEmpty();
    Model mo = p.getSourceModel();
    Mapping map = mo.getMapping();
    OnStableNodeFirst schedHeuristic = new OnStableNodeFirst(p);
    // Get the VMs to place
    Set<VM> onBadNodes = new HashSet<>(p.getManageableVMs());
    // Get the VMs that runs and have a pretty low chances to move
    Set<VM> onGoodNodes = map.getRunningVMs(map.getOnlineNodes());
    onGoodNodes.removeAll(onBadNodes);
    List<VMTransition> goodActions = p.getVMActions(onGoodNodes);
    List<VMTransition> badActions = p.getVMActions(onBadNodes);
    Solver s = p.getSolver();
    // Get the VMs to move for exclusion issue
    Set<VM> vmsToExclude = new HashSet<>(p.getManageableVMs());
    for (Iterator<VM> ite = vmsToExclude.iterator(); ite.hasNext(); ) {
        VM vm = ite.next();
        if (!(map.isRunning(vm) && p.getFutureRunningVMs().contains(vm))) {
            ite.remove();
        }
    }
    List<AbstractStrategy<?>> strategies = new ArrayList<>();
    Map<IntVar, VM> pla = VMPlacementUtils.makePlacementMap(p);
    if (!vmsToExclude.isEmpty()) {
        List<VMTransition> actions = new LinkedList<>();
        // Get all the involved slices
        for (VM vm : vmsToExclude) {
            if (p.getFutureRunningVMs().contains(vm)) {
                actions.add(p.getVMAction(vm));
            }
        }
        placeVMs(ps, strategies, actions, schedHeuristic, pla);
    }
    TObjectIntMap<VM> costs = CShareableResource.getWeights(rp, rcs);
    badActions.sort((v2, v1) -> costs.get(v1.getVM()) - costs.get(v2.getVM()));
    goodActions.sort((v2, v1) -> costs.get(v1.getVM()) - costs.get(v2.getVM()));
    placeVMs(ps, strategies, badActions, schedHeuristic, pla);
    placeVMs(ps, strategies, goodActions, schedHeuristic, pla);
    // Reinstantations. Try to reinstantiate first
    List<IntVar> migs = new ArrayList<>();
    for (VMTransition t : rp.getVMActions()) {
        if (t instanceof RelocatableVM) {
            migs.add(((RelocatableVM) t).getRelocationMethod());
        }
    }
    strategies.add(Search.intVarSearch(new FirstFail(rp.getModel()), new IntDomainMax(), migs.toArray(new IntVar[migs.size()])));
    if (!p.getNodeActions().isEmpty()) {
        // Boot some nodes if needed
        IntVar[] starts = p.getNodeActions().stream().map(Transition::getStart).toArray(IntVar[]::new);
        strategies.add(new IntStrategy(starts, new FirstFail(rp.getModel()), new IntDomainMin()));
    }
    // /SCHEDULING PROBLEM
    MovementGraph gr = new MovementGraph(rp);
    IntVar[] starts = dSlices(rp.getVMActions()).map(Slice::getStart).filter(v -> !v.isInstantiated()).toArray(IntVar[]::new);
    strategies.add(new IntStrategy(starts, new StartOnLeafNodes(rp, gr), new IntDomainMin()));
    strategies.add(new IntStrategy(schedHeuristic.getScope(), schedHeuristic, new IntDomainMin()));
    IntVar[] ends = rp.getVMActions().stream().map(Transition::getEnd).filter(v -> !v.isInstantiated()).toArray(IntVar[]::new);
    strategies.add(Search.intVarSearch(new MyInputOrder<>(s), new IntDomainMin(), ends));
    // At this stage only it matters to plug the cost constraints
    strategies.add(new IntStrategy(new IntVar[] { p.getEnd(), cost }, new MyInputOrder<>(s, this), new IntDomainMin()));
    s.setSearch(new StrategiesSequencer(s.getEnvironment(), strategies.toArray(new AbstractStrategy[strategies.size()])));
}
Also used : Slice(org.btrplace.scheduler.choco.Slice) SchedulerException(org.btrplace.scheduler.SchedulerException) Transition(org.btrplace.scheduler.choco.transition.Transition) StrategiesSequencer(org.chocosolver.solver.search.strategy.strategy.StrategiesSequencer) Solver(org.chocosolver.solver.Solver) Search(org.chocosolver.solver.search.strategy.Search) TObjectIntMap(gnu.trove.map.TObjectIntMap) CObjective(org.btrplace.scheduler.choco.constraint.CObjective) RelocatableVM(org.btrplace.scheduler.choco.transition.RelocatableVM) IntDomainMin(org.chocosolver.solver.search.strategy.selectors.values.IntDomainMin) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) VM(org.btrplace.model.VM) FirstFail(org.chocosolver.solver.search.strategy.selectors.variables.FirstFail) Mapping(org.btrplace.model.Mapping) Map(java.util.Map) ReconfigurationProblem(org.btrplace.scheduler.choco.ReconfigurationProblem) CShareableResource(org.btrplace.scheduler.choco.view.CShareableResource) LinkedList(java.util.LinkedList) Model(org.btrplace.model.Model) BiggestDimension(org.btrplace.scheduler.choco.constraint.mttr.load.BiggestDimension) Iterator(java.util.Iterator) Set(java.util.Set) Parameters(org.btrplace.scheduler.choco.Parameters) Collectors(java.util.stream.Collectors) VMTransition(org.btrplace.scheduler.choco.transition.VMTransition) Objects(java.util.Objects) IntVar(org.chocosolver.solver.variables.IntVar) MinMTTR(org.btrplace.model.constraint.MinMTTR) List(java.util.List) Stream(java.util.stream.Stream) IntStrategy(org.chocosolver.solver.search.strategy.strategy.IntStrategy) ShareableResource(org.btrplace.model.view.ShareableResource) IntValueSelector(org.chocosolver.solver.search.strategy.selectors.values.IntValueSelector) Instance(org.btrplace.model.Instance) AbstractStrategy(org.chocosolver.solver.search.strategy.strategy.AbstractStrategy) IntDomainMax(org.chocosolver.solver.search.strategy.selectors.values.IntDomainMax) Collections(java.util.Collections) Solver(org.chocosolver.solver.Solver) ArrayList(java.util.ArrayList) Mapping(org.btrplace.model.Mapping) RelocatableVM(org.btrplace.scheduler.choco.transition.RelocatableVM) AbstractStrategy(org.chocosolver.solver.search.strategy.strategy.AbstractStrategy) CShareableResource(org.btrplace.scheduler.choco.view.CShareableResource) ShareableResource(org.btrplace.model.view.ShareableResource) IntVar(org.chocosolver.solver.variables.IntVar) IntStrategy(org.chocosolver.solver.search.strategy.strategy.IntStrategy) IntDomainMin(org.chocosolver.solver.search.strategy.selectors.values.IntDomainMin) FirstFail(org.chocosolver.solver.search.strategy.selectors.variables.FirstFail) CShareableResource(org.btrplace.scheduler.choco.view.CShareableResource) HashSet(java.util.HashSet) VMTransition(org.btrplace.scheduler.choco.transition.VMTransition) StrategiesSequencer(org.chocosolver.solver.search.strategy.strategy.StrategiesSequencer) LinkedList(java.util.LinkedList) Slice(org.btrplace.scheduler.choco.Slice) RelocatableVM(org.btrplace.scheduler.choco.transition.RelocatableVM) VM(org.btrplace.model.VM) Model(org.btrplace.model.Model) Transition(org.btrplace.scheduler.choco.transition.Transition) VMTransition(org.btrplace.scheduler.choco.transition.VMTransition) IntDomainMax(org.chocosolver.solver.search.strategy.selectors.values.IntDomainMax)

Example 7 with RelocatableVM

use of org.btrplace.scheduler.choco.transition.RelocatableVM in project scheduler by btrplace.

the class CNoDelay method inject.

@Override
public boolean inject(Parameters ps, ReconfigurationProblem rp) {
    VM v = noDelay.getInvolvedVMs().iterator().next();
    // For each vm involved in the constraint
    VMTransition vt = rp.getVMAction(v);
    // Get the VMTransition start time
    // Add the constraint "start = 0" to the solver
    Slice d = vt.getDSlice();
    if (d == null) {
        return true;
    }
    if (!(vt instanceof RelocatableVM)) {
        try {
            d.getStart().instantiateTo(0, Cause.Null);
        } catch (ContradictionException ex) {
            rp.getLogger().debug("Unable to prevent any delay on '" + v + "'", ex);
            return false;
        }
    } else {
        Constraint c = rp.getModel().arithm(d.getStart(), "=", 0);
        BoolVar move = ((RelocatableVM) vt).isStaying().not();
        ChocoUtils.postImplies(rp, move, c);
    }
    return true;
}
Also used : Constraint(org.chocosolver.solver.constraints.Constraint) Slice(org.btrplace.scheduler.choco.Slice) ContradictionException(org.chocosolver.solver.exception.ContradictionException) RelocatableVM(org.btrplace.scheduler.choco.transition.RelocatableVM) VM(org.btrplace.model.VM) VMTransition(org.btrplace.scheduler.choco.transition.VMTransition) RelocatableVM(org.btrplace.scheduler.choco.transition.RelocatableVM) BoolVar(org.chocosolver.solver.variables.BoolVar)

Example 8 with RelocatableVM

use of org.btrplace.scheduler.choco.transition.RelocatableVM in project scheduler by btrplace.

the class CNetwork method addLinkConstraints.

/**
 * Add the cumulative constraints for each link.
 *
 * Full-duplex links are considered, two cumulative constraints are defined per link by looking at
 * the migration direction for each link on the migration path.
 *
 * @param rp the reconfiguration problem
 */
private void addLinkConstraints(ReconfigurationProblem rp) {
    // Links limitation
    List<Task> tasksListUp = new ArrayList<>();
    List<Task> tasksListDown = new ArrayList<>();
    List<IntVar> heightsListUp = new ArrayList<>();
    List<IntVar> heightsListDown = new ArrayList<>();
    for (Link l : net.getLinks()) {
        for (VM vm : rp.getVMs()) {
            VMTransition a = rp.getVMAction(vm);
            if (a instanceof RelocatableVM && !a.getDSlice().getHoster().isInstantiatedTo(a.getCSlice().getHoster().getValue())) {
                Node src = source.getMapping().getVMLocation(vm);
                Node dst = rp.getNode(a.getDSlice().getHoster().getValue());
                List<Link> path = net.getRouting().getPath(src, dst);
                // Check first if the link is on migration path
                if (path.contains(l)) {
                    // Get link direction
                    LinkDirection linkDirection = net.getRouting().getLinkDirection(src, dst, l);
                    // UpLink
                    if (linkDirection == LinkDirection.UPLINK) {
                        tasksListUp.add(((RelocatableVM) a).getMigrationTask());
                        heightsListUp.add(((RelocatableVM) a).getBandwidth());
                    } else // DownLink
                    {
                        tasksListDown.add(((RelocatableVM) a).getMigrationTask());
                        heightsListDown.add(((RelocatableVM) a).getBandwidth());
                    }
                }
            }
        }
        if (!tasksListUp.isEmpty()) {
            // Post the cumulative constraint for the current UpLink
            csp.post(csp.cumulative(tasksListUp.toArray(new Task[tasksListUp.size()]), heightsListUp.toArray(new IntVar[heightsListUp.size()]), csp.intVar(l.getCapacity()), true));
            tasksListUp.clear();
            heightsListUp.clear();
        }
        if (!tasksListDown.isEmpty()) {
            // Post the cumulative constraint for the current DownLink
            csp.post(csp.cumulative(tasksListDown.toArray(new Task[tasksListDown.size()]), heightsListDown.toArray(new IntVar[heightsListDown.size()]), csp.intVar(l.getCapacity()), true));
            tasksListDown.clear();
            heightsListDown.clear();
        }
    }
}
Also used : Task(org.chocosolver.solver.variables.Task) RelocatableVM(org.btrplace.scheduler.choco.transition.RelocatableVM) VM(org.btrplace.model.VM) Node(org.btrplace.model.Node) ArrayList(java.util.ArrayList) VMTransition(org.btrplace.scheduler.choco.transition.VMTransition) LinkDirection(org.btrplace.model.view.network.Routing.LinkDirection) RelocatableVM(org.btrplace.scheduler.choco.transition.RelocatableVM) IntVar(org.chocosolver.solver.variables.IntVar) Link(org.btrplace.model.view.network.Link)

Example 9 with RelocatableVM

use of org.btrplace.scheduler.choco.transition.RelocatableVM in project scheduler by btrplace.

the class CNetwork method addSwitchConstraints.

/**
 * Add the cumulative constraints for each blocking switch (having limited capacity)
 *
 * @param rp the reconfiguration problem
 */
private void addSwitchConstraints(ReconfigurationProblem rp) {
    // Switches capacity limitation
    List<Task> tasksList = new ArrayList<>();
    List<IntVar> heightsList = new ArrayList<>();
    for (Switch sw : net.getSwitches()) {
        // Only if the capacity is limited
        if (sw.getCapacity() != Integer.MAX_VALUE) {
            for (VM vm : rp.getVMs()) {
                VMTransition a = rp.getVMAction(vm);
                if (a != null && a instanceof RelocatableVM) {
                    if (a.getDSlice().getHoster().isInstantiated()) {
                        if (a.getCSlice().getHoster().getValue() != a.getDSlice().getHoster().getValue()) {
                            Node src = source.getMapping().getVMLocation(vm);
                            Node dst = rp.getNode(a.getDSlice().getHoster().getValue());
                            if (!Collections.disjoint(net.getConnectedLinks(sw), net.getRouting().getPath(src, dst))) {
                                tasksList.add(new Task(a.getStart(), a.getDuration(), a.getEnd()));
                                heightsList.add(((RelocatableVM) a).getBandwidth());
                            }
                        }
                    }
                }
            }
            if (!tasksList.isEmpty()) {
                // Post the cumulative constraint for the current switch
                csp.post(csp.cumulative(tasksList.toArray(new Task[tasksList.size()]), heightsList.toArray(new IntVar[heightsList.size()]), csp.intVar(sw.getCapacity()), true));
                tasksList.clear();
                heightsList.clear();
            }
        }
    }
}
Also used : Task(org.chocosolver.solver.variables.Task) Switch(org.btrplace.model.view.network.Switch) RelocatableVM(org.btrplace.scheduler.choco.transition.RelocatableVM) VM(org.btrplace.model.VM) Node(org.btrplace.model.Node) ArrayList(java.util.ArrayList) VMTransition(org.btrplace.scheduler.choco.transition.VMTransition) RelocatableVM(org.btrplace.scheduler.choco.transition.RelocatableVM) IntVar(org.chocosolver.solver.variables.IntVar)

Example 10 with RelocatableVM

use of org.btrplace.scheduler.choco.transition.RelocatableVM in project scheduler by btrplace.

the class CNetwork method beforeSolve.

@Override
public boolean beforeSolve(ReconfigurationProblem rp) throws SchedulerException {
    Model mo = rp.getSourceModel();
    Attributes attrs = mo.getAttributes();
    // Pre-compute duration and bandwidth for each VM migration
    for (VMTransition migration : rp.getVMActions()) {
        if (!(migration instanceof RelocatableVM)) {
            continue;
        }
        // Get vars from migration
        VM vm = migration.getVM();
        IntVar bandwidth = ((RelocatableVM) migration).getBandwidth();
        IntVar duration = migration.getDuration();
        Node src = rp.getSourceModel().getMapping().getVMLocation(vm);
        // Try to get the destination node
        Node dst;
        if (!migration.getDSlice().getHoster().isInstantiated()) {
            throw new SchedulerModelingException(null, "Destination node for VM '" + vm + "' should be known !");
        }
        if (!mo.getAttributes().isSet(vm, "memUsed")) {
            throw new SchedulerModelingException(null, "Unable to retrieve 'memUsed' attribute for the vm '" + vm + "'");
        }
        dst = rp.getNode(migration.getDSlice().getHoster().getValue());
        if (src.equals(dst)) {
            try {
                ((RelocatableVM) migration).getBandwidth().instantiateTo(0, Cause.Null);
                continue;
            } catch (ContradictionException e) {
                rp.getLogger().debug("Contradiction exception when trying to instantiate bandwidth and " + " duration variables for " + vm + " migration", e);
                return false;
            }
        }
        // Get attribute vars
        int memUsed = attrs.get(vm, "memUsed", -1);
        // Get VM memory activity attributes if defined, otherwise set an idle workload on the VM
        // Minimal observed value on idle VM
        double hotDirtySize = attrs.get(vm, "hotDirtySize", 5.0);
        // Minimal observed value on idle VM
        double hotDirtyDuration = attrs.get(vm, "hotDirtyDuration", 2.0);
        double coldDirtyRate = attrs.get(vm, "coldDirtyRate", 0.0);
        // Get the maximal bandwidth available on the migration path
        int maxBW = net.getRouting().getMaxBW(src, dst);
        // Compute the duration related to each enumerated bandwidth
        double durationMin;
        double durationColdPages;
        double durationHotPages;
        double durationTotal;
        // Cheat a bit, real is less than theoretical (8->9)
        double bandwidthOctet = maxBW / 9.0;
        // Estimate the duration for the current bandwidth
        durationMin = memUsed / bandwidthOctet;
        if (durationMin > hotDirtyDuration) {
            durationColdPages = (hotDirtySize + (durationMin - hotDirtyDuration) * coldDirtyRate) / (bandwidthOctet - coldDirtyRate);
            durationHotPages = (hotDirtySize / bandwidthOctet * ((hotDirtySize / hotDirtyDuration) / (bandwidthOctet - (hotDirtySize / hotDirtyDuration))));
            durationTotal = durationMin + durationColdPages + durationHotPages;
        } else {
            durationTotal = durationMin + (((hotDirtySize / hotDirtyDuration) * durationMin) / (bandwidthOctet - (hotDirtySize / hotDirtyDuration)));
        }
        // Instantiate the computed bandwidth and duration
        try {
            // prevent from a 0 duration when the memory usage is very low
            int dd = (int) Math.max(1, Math.round(durationTotal));
            duration.instantiateTo(dd, Cause.Null);
            bandwidth.instantiateTo(maxBW, Cause.Null);
        } catch (ContradictionException e) {
            rp.getLogger().debug("Contradiction exception when trying to instantiate bandwidth and " + " duration variables for " + vm + " migration: ", e);
            return false;
        }
    }
    // Add links and switches constraints
    addLinkConstraints(rp);
    addSwitchConstraints(rp);
    return true;
}
Also used : ContradictionException(org.chocosolver.solver.exception.ContradictionException) RelocatableVM(org.btrplace.scheduler.choco.transition.RelocatableVM) VM(org.btrplace.model.VM) Node(org.btrplace.model.Node) Model(org.btrplace.model.Model) Attributes(org.btrplace.model.Attributes) VMTransition(org.btrplace.scheduler.choco.transition.VMTransition) RelocatableVM(org.btrplace.scheduler.choco.transition.RelocatableVM) IntVar(org.chocosolver.solver.variables.IntVar) SchedulerModelingException(org.btrplace.scheduler.SchedulerModelingException)

Aggregations

RelocatableVM (org.btrplace.scheduler.choco.transition.RelocatableVM)10 VMTransition (org.btrplace.scheduler.choco.transition.VMTransition)10 VM (org.btrplace.model.VM)9 IntVar (org.chocosolver.solver.variables.IntVar)8 ArrayList (java.util.ArrayList)7 Model (org.btrplace.model.Model)3 Node (org.btrplace.model.Node)3 Slice (org.btrplace.scheduler.choco.Slice)3 Task (org.chocosolver.solver.variables.Task)3 TObjectIntMap (gnu.trove.map.TObjectIntMap)2 Collections (java.util.Collections)2 HashSet (java.util.HashSet)2 Iterator (java.util.Iterator)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 Map (java.util.Map)2 Objects (java.util.Objects)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 Stream (java.util.stream.Stream)2