use of org.btrplace.model.constraint.SatConstraint in project scheduler by btrplace.
the class CSerializeTest method testOk.
@Test
public void testOk() 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
// The destination node have twice the bandwidth of source nodes
Switch swMain = net.newSwitch();
net.connect(1000, swMain, srcNode1, srcNode2);
net.connect(2000, 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));
// SERIALIZE THE TWO MIGRATIONS
Serialize serial = new Serialize(vm1, vm2);
cstrs.add(serial);
// Solve it using the Min Max Time To Repair Migration scheduling oriented objective
ReconfigurationPlan p = new DefaultChocoScheduler().solve(mo, cstrs, new MinMTTRMig());
Assert.assertNotNull(p);
// Check if the serialize constraint is respected
MigrateVM mig1 = (MigrateVM) p.getActions().stream().filter(s -> s instanceof MigrateVM && ((MigrateVM) s).getVM().equals(vm1)).findAny().get();
MigrateVM mig2 = (MigrateVM) p.getActions().stream().filter(s -> s instanceof MigrateVM && ((MigrateVM) s).getVM().equals(vm2)).findAny().get();
Assert.assertTrue(mig1.getStart() >= mig2.getEnd() || mig2.getStart() >= mig1.getEnd());
// TODO: use methods on SerializeChecker to verify that the actions are serialized ?
Assert.assertTrue(serial.isSatisfied(p));
}
use of org.btrplace.model.constraint.SatConstraint in project scheduler by btrplace.
the class CSyncTest method testOk.
@Test
public void testOk() 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
// The destination node have twice the bandwidth of source nodes
Switch swMain = net.newSwitch();
net.connect(1000, swMain, srcNode1, srcNode2);
net.connect(2000, 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));
// SYNCHRONIZE THE TWO MIGRATIONS
Sync sync = new Sync(vm1, vm2);
cstrs.add(sync);
// Solve it using the Min Max Time To Repair Migration scheduling oriented objective
ReconfigurationPlan p = new DefaultChocoScheduler().solve(mo, cstrs, new MinMTTRMig());
// It works BUT the VMs are synchronized by default (thanks to BW optimization), is Sync a useless constraint ?
Assert.assertNotNull(p);
// Check if the sync constraint is respected
Action mig1 = p.getActions().stream().filter(s -> s instanceof MigrateVM && ((MigrateVM) s).getVM().equals(vm1)).findAny().get();
Action mig2 = p.getActions().stream().filter(s -> s instanceof MigrateVM && ((MigrateVM) s).getVM().equals(vm2)).findAny().get();
Assert.assertTrue(mig1.getEnd() == mig2.getEnd());
// TODO: use methods on SyncChecker to verify that the actions are synchronized ?
Assert.assertTrue(sync.isSatisfied(p));
}
use of org.btrplace.model.constraint.SatConstraint in project scheduler by btrplace.
the class CSyncTest 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));
// TRY TO SYNCHRONIZE THE TWO MIGRATIONS
Sync sync = new Sync(vm1, vm2);
cstrs.add(sync);
// Solve it using the Min Max Time To Repair Migration scheduling oriented objective
ChocoScheduler sched = new DefaultChocoScheduler();
ReconfigurationPlan p = sched.solve(mo, cstrs, new MinMTTRMig());
// Unable to sync two migrations on the same path !
Assert.assertNull(p);
}
use of org.btrplace.model.constraint.SatConstraint in project scheduler by btrplace.
the class CMinMTTRTest method testHeavyLoad.
/**
* The DC is heavily loaded.
* Provoked a large amount of backtracks when we relied on a random search
* @throws Exception
*/
/*@Test*/
public void testHeavyLoad() throws Exception {
Model mo = new DefaultModel();
ShareableResource cpu = new ShareableResource("core", 7, 1);
ShareableResource mem = new ShareableResource("mem", 20, 2);
for (int i = 0; i < 50; i++) {
Node n = mo.newNode();
mo.getMapping().addOnlineNode(n);
for (int j = 0; j < 4; j++) {
VM v = mo.newVM();
mo.getMapping().addRunningVM(v, n);
if (j % 2 == 0) {
mem.setConsumption(v, 1);
}
}
}
List<SatConstraint> l = new ArrayList<>();
for (Node n : mo.getMapping().getAllNodes()) {
if (n.id() % 3 == 0) {
l.addAll(Preserve.newPreserve(mo.getMapping().getRunningVMs(n), "core", 2));
}
}
mo.attach(cpu);
mo.attach(mem);
DefaultChocoScheduler sched = new DefaultChocoScheduler();
ReconfigurationPlan p = sched.solve(mo, l);
Assert.assertNotNull(p);
System.err.println(sched.getStatistics());
// TODO: fragile. Usefull ?
Assert.assertTrue(sched.getStatistics().getMetrics().backtracks() < 100);
System.err.flush();
}
use of org.btrplace.model.constraint.SatConstraint in project scheduler by btrplace.
the class KilledBuilderTest method testGoodSignatures.
@Test(dataProvider = "goodKilleds")
public void testGoodSignatures(String str, int nbVMs, boolean c) throws Exception {
ScriptBuilder b = new ScriptBuilder(new DefaultModel());
Set<SatConstraint> cstrs = b.build("namespace test; VM[1..10] : tiny;\n@N[1..20] : defaultNode;" + str).getConstraints();
Set<VM> vms = new HashSet<>();
Assert.assertEquals(cstrs.size(), nbVMs);
for (SatConstraint x : cstrs) {
Assert.assertTrue(x instanceof Killed);
Assert.assertTrue(vms.addAll(x.getInvolvedVMs()));
Assert.assertEquals(x.isContinuous(), c);
}
}
Aggregations