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);
}
}
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()));
}
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;
}
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);
}
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));
}
Aggregations