use of org.btrplace.plan.ReconfigurationPlan in project scheduler by btrplace.
the class CDeadlineTest method testKo.
@Test
public void testKo() throws SchedulerException {
// New default model
Model mo = new DefaultModel();
Mapping ma = mo.getMapping();
// Create and boot 2 source nodes and 1 destination node
Node srcNode1 = mo.newNode(), srcNode2 = mo.newNode(), dstNode = mo.newNode();
ma.addOnlineNode(srcNode1);
ma.addOnlineNode(srcNode2);
ma.addOnlineNode(dstNode);
// Attach a network view
Network net = new Network();
mo.attach(net);
// Connect the nodes through a main non-blocking switch with 1 Gbit/s links
Switch swMain = net.newSwitch();
net.connect(1000, swMain, srcNode1, srcNode2);
net.connect(1000, swMain, dstNode);
// Create and host 1 VM per source node
VM vm1 = mo.newVM();
VM vm2 = mo.newVM();
ma.addRunningVM(vm1, srcNode1);
ma.addRunningVM(vm2, srcNode2);
// Attach CPU and Mem resource views and assign nodes capacity and VMs consumption
int mem_vm = 8, cpu_vm = 4, mem_src = 8, cpu_src = 4, mem_dst = 16, cpu_dst = 8;
ShareableResource rcMem = new ShareableResource("mem", 0, 0), rcCPU = new ShareableResource("cpu", 0, 0);
mo.attach(rcMem);
mo.attach(rcCPU);
// VMs
rcMem.setConsumption(vm1, mem_vm).setConsumption(vm2, mem_vm);
rcCPU.setConsumption(vm1, cpu_vm).setConsumption(vm2, cpu_vm);
// Nodes
rcMem.setCapacity(srcNode1, mem_src).setCapacity(srcNode2, mem_src).setCapacity(dstNode, mem_dst);
rcCPU.setCapacity(srcNode1, cpu_src).setCapacity(srcNode2, cpu_src).setCapacity(dstNode, cpu_dst);
// Set VM attributes 'memory used', 'hot dirty page size', 'hot dirty page duration' and 'cold dirty pages rate'
int vm_mu = 6000, vm_mds = 46, vm_mdd = 2;
double vm_cdr = 23.6;
// vm1 is an 'idle' VM (with no special memory activity) but still consumes 6 GiB of memory
mo.getAttributes().put(vm1, "memUsed", vm_mu);
// vm2 consumes 6 GiB memory and has a memory intensive workload equivalent to "stress --vm 1000 --bytes 50K"
// VM with a workload
mo.getAttributes().put(vm2, "memUsed", vm_mu);
mo.getAttributes().put(vm2, "hotDirtySize", vm_mds);
mo.getAttributes().put(vm2, "hotDirtyDuration", vm_mdd);
mo.getAttributes().put(vm2, "coldDirtyRate", vm_cdr);
// Create constraints
List<SatConstraint> cstrs = new ArrayList<>();
// Placement constraints, we want to shutdown the source nodes to force the migration to destination nodes
cstrs.add(new Offline(srcNode1));
cstrs.add(new Offline(srcNode2));
// SET A TOO SHORT DEADLINE FOR THE MIGRATION OF VM2
// 30s
Deadline dead = new Deadline(vm2, "+00:00:30");
cstrs.add(dead);
// Try to solve it using the Min Max Time To Repair Migration scheduling oriented objective
ReconfigurationPlan p = new DefaultChocoScheduler().solve(mo, cstrs, new MinMTTRMig());
Assert.assertNull(p);
}
use of org.btrplace.plan.ReconfigurationPlan in project scheduler by btrplace.
the class CMinMigrationsTest method simpleTest.
@Test
public void simpleTest() {
Model mo = new DefaultModel();
Node n0 = mo.newNode();
Node n1 = mo.newNode();
VM vm0 = mo.newVM();
VM vm1 = mo.newVM();
VM vm2 = mo.newVM();
mo.getMapping().on(n0, n1).run(n0, vm0, vm1, vm2);
ShareableResource mem = new ShareableResource("mem", 5, 1);
// cpu dimension to create the violation
ShareableResource cpu = new ShareableResource("cpu", 5, 1);
// VM0 as the big VM
mem.setConsumption(vm0, 3);
mo.attach(cpu);
mo.attach(mem);
List<SatConstraint> cstrs = new ArrayList<>();
// The 3 VMs no longer feet on n0
cstrs.add(new Preserve(vm0, "cpu", 5));
ChocoScheduler s = new DefaultChocoScheduler();
s.doOptimize(true);
ReconfigurationPlan p = s.solve(mo, cstrs, new MinMigrations());
System.out.println(s.getStatistics());
System.out.println(p);
// VM0 to n1
Assert.assertEquals(p.getActions().size(), 1);
// VM0 to n1
Assert.assertEquals(p.getResult().getMapping().getVMLocation(vm0), n1);
}
use of org.btrplace.plan.ReconfigurationPlan in project scheduler by btrplace.
the class CMinMigrationsTest method testWithFreeNodes.
/**
* Issue #137.
* ShutdownableNode.isOnline() is not instantiated at the end of the problem
*/
@Test
public void testWithFreeNodes() {
Model mo = new DefaultModel();
Node n0 = mo.newNode();
Node n1 = mo.newNode();
Node n2 = mo.newNode();
VM v1 = mo.newVM();
VM v2 = mo.newVM();
DefaultChocoScheduler s = new DefaultChocoScheduler();
mo.getMapping().on(n0, n1, n2).run(n0, v1, v2);
Instance i = new Instance(mo, Arrays.asList(new Spread(mo.getMapping().getAllVMs(), false)), new MinMigrations());
ReconfigurationPlan p = s.solve(i);
Assert.assertNotNull(p);
}
use of org.btrplace.plan.ReconfigurationPlan in project scheduler by btrplace.
the class CMinMigrationsTest method main.
public static void main(String[] args) {
String root = "/Users/fabien.hermenier/Documents/BtrPlace/nutanix/instances";
List<OptConstraint> objs = Arrays.asList(/*new MinMTTR(),*/
new MinMigrations());
boolean verbose = true;
for (OptConstraint o : objs) {
System.out.print(" " + o);
}
System.out.println();
for (int idx = 1; idx <= 256; idx += 5) {
String path = root + "/lazan/lazan-" + idx + ".json.gz";
if (verbose) {
System.out.println("--- " + idx + " --- ");
} else {
System.out.print(idx);
}
List<Long> res = new ArrayList<>();
for (OptConstraint o : objs) {
if (verbose) {
System.out.println("\t" + o);
}
Instance i = JSON.readInstance(new File(path));
if (Network.get(i.getModel()) != null) {
i.getModel().detach(Network.get(i.getModel()));
}
i = new Instance(i.getModel(), i.getSatConstraints(), o);
ChocoScheduler s = new DefaultChocoScheduler();
s.doOptimize(false);
s.setTimeLimit(30);
s.doRepair(false);
ReconfigurationPlan p = s.solve(i);
Assert.assertNotNull(p);
res.add(p.getActions().stream().filter(x -> x instanceof MigrateVM).mapToLong(x -> x.getEnd() - x.getStart()).sum());
// res.add((long)s.getStatistics().lastSolution().getDuration());
if (verbose) {
System.out.println(s.getStatistics());
// System.out.println(p);
}
}
if (!verbose) {
for (Long l : res) {
System.out.print("\t" + l);
}
System.out.println();
}
}
}
use of org.btrplace.plan.ReconfigurationPlan 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()));
}
Aggregations