use of org.btrplace.model.Model in project scheduler by btrplace.
the class CMinMigrations 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.getView(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()));
// Fix the duration. The side effect will be that states will be fixed as well
// with the objective to not do un-necessary actions
IntVar[] durations = p.getNodeActions().stream().map(Transition::getDuration).toArray(IntVar[]::new);
strategies.add(new IntStrategy(durations, new FirstFail(rp.getModel()), new IntDomainMin()));
}
postCostConstraints();
// /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()])));
}
use of org.btrplace.model.Model 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.getView(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()])));
}
use of org.btrplace.model.Model 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().error("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().error("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;
}
use of org.btrplace.model.Model in project scheduler by btrplace.
the class CShareableResource method getWeights.
/**
* Estimate the weight of each VMs with regards to multiple dimensions.
* In practice, it sums the normalised size of each VM against the total capacity
*
* @param rp the problem to solve
* @param rcs the resources to consider
* @return a weight per VM
*/
public static TObjectIntMap<VM> getWeights(ReconfigurationProblem rp, List<CShareableResource> rcs) {
Model mo = rp.getSourceModel();
int[] capa = new int[rcs.size()];
int[] cons = new int[rcs.size()];
TObjectIntMap<VM> cost = new TObjectIntHashMap<>();
for (Node n : mo.getMapping().getAllNodes()) {
for (int i = 0; i < rcs.size(); i++) {
capa[i] += rcs.get(i).virtRcUsage.get(rp.getNode(n)).getUB() * rcs.get(i).ratios.get(rp.getNode(n));
}
}
for (VM v : mo.getMapping().getAllVMs()) {
for (int i = 0; i < rcs.size(); i++) {
cons[i] += rcs.get(i).getVMAllocation(rp.getVM(v));
}
}
for (VM v : mo.getMapping().getAllVMs()) {
double sum = 0;
for (int i = 0; i < rcs.size(); i++) {
double ratio = 0;
if (cons[i] > 0) {
ratio = 1.0 * rcs.get(i).getVMAllocation(rp.getVM(v)) / capa[i];
}
sum += ratio;
}
cost.put(v, (int) (sum * 10000));
}
return cost;
}
use of org.btrplace.model.Model in project scheduler by btrplace.
the class DefaultChocoSchedulerTest method testTransitionFactoryCustomisation.
/**
* Remove the ready->running transition so the solving process will fail
*
* @throws org.btrplace.scheduler.SchedulerException
*/
@Test
public void testTransitionFactoryCustomisation() throws SchedulerException {
ChocoScheduler cra = new DefaultChocoScheduler();
TransitionFactory tf = cra.getTransitionFactory();
VMTransitionBuilder b = tf.getBuilder(VMState.READY, VMState.RUNNING);
Assert.assertTrue(tf.remove(b));
Model mo = new DefaultModel();
VM v = mo.newVM();
mo.getMapping().addReadyVM(v);
Assert.assertNull(cra.solve(mo, Collections.singletonList(new Running(v))));
}
Aggregations