Search in sources :

Example 6 with Attributes

use of org.btrplace.model.Attributes 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

Attributes (org.btrplace.model.Attributes)6 VM (org.btrplace.model.VM)6 Model (org.btrplace.model.Model)5 DefaultModel (org.btrplace.model.DefaultModel)4 Node (org.btrplace.model.Node)4 Test (org.testng.annotations.Test)3 JSONObject (net.minidev.json.JSONObject)2 DefaultAttributes (org.btrplace.model.DefaultAttributes)2 Map (java.util.Map)1 JSONConverterException (org.btrplace.json.JSONConverterException)1 JSONs.getNode (org.btrplace.json.JSONs.getNode)1 JSONs.getVM (org.btrplace.json.JSONs.getVM)1 Mapping (org.btrplace.model.Mapping)1 SatConstraint (org.btrplace.model.constraint.SatConstraint)1 ShareableResource (org.btrplace.model.view.ShareableResource)1 ReconfigurationPlan (org.btrplace.plan.ReconfigurationPlan)1 BootVM (org.btrplace.plan.event.BootVM)1 MigrateVM (org.btrplace.plan.event.MigrateVM)1 ShutdownVM (org.btrplace.plan.event.ShutdownVM)1 SchedulerModelingException (org.btrplace.scheduler.SchedulerModelingException)1