use of org.btrplace.model.constraint.SatConstraint in project scheduler by btrplace.
the class SingleRunnerStatisticsTest method testInstantiate.
@Test
public void testInstantiate() {
Parameters ps = new DefaultParameters();
Model mo = new DefaultModel();
long st = System.currentTimeMillis();
List<SatConstraint> cstrs = new ArrayList<>();
Instance i = new Instance(mo, cstrs, new MinMTTR());
SingleRunnerStatistics stats = new SingleRunnerStatistics(ps, i, st);
Assert.assertEquals(stats.getStart(), st);
Assert.assertEquals(stats.getCoreBuildDuration(), -1);
Assert.assertEquals(stats.getSpecializationDuration(), -1);
Assert.assertEquals(stats.getInstance(), i);
Assert.assertEquals(stats.getNbManagedVMs(), -1);
Assert.assertEquals(stats.getParameters(), ps);
Assert.assertEquals(stats.getSolutions().size(), 0);
Assert.assertEquals(stats.completed(), false);
Assert.assertEquals(stats.getMetrics(), null);
stats.setCoreBuildDuration(12);
stats.setSpecialisationDuration(17);
stats.setNbManagedVMs(18);
stats.setCompleted(true);
Assert.assertEquals(stats.getCoreBuildDuration(), 12);
Assert.assertEquals(stats.getSpecializationDuration(), 17);
Assert.assertEquals(stats.getNbManagedVMs(), 18);
Assert.assertEquals(stats.completed(), true);
ReconfigurationPlan plan = new DefaultReconfigurationPlan(mo);
SolutionStatistics sol = new SolutionStatistics(new Metrics(), plan);
stats.addSolution(sol);
Assert.assertEquals(stats.getSolutions().size(), 1);
Assert.assertEquals(stats.getSolutions().get(0), sol);
}
use of org.btrplace.model.constraint.SatConstraint 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));
}
use of org.btrplace.model.constraint.SatConstraint in project scheduler by btrplace.
the class CShareableResourceTest method testRealNodeUsage.
/**
* Place some VMs and check realNodeUsage is updated accordingly
*/
@Test
public void testRealNodeUsage() throws SchedulerException {
Model mo = new DefaultModel();
Mapping ma = mo.getMapping();
VM vm1 = mo.newVM();
VM vm2 = mo.newVM();
Node n1 = mo.newNode();
Node n2 = mo.newNode();
ma.addOnlineNode(n1);
ma.addOnlineNode(n2);
ma.addRunningVM(vm1, n1);
ma.addRunningVM(vm2, n1);
ShareableResource rc = new ShareableResource("foo", 0, 0);
rc.setConsumption(vm1, 2);
rc.setConsumption(vm2, 3);
rc.setCapacity(n1, 5);
rc.setCapacity(n2, 3);
mo.attach(rc);
ChocoScheduler s = new DefaultChocoScheduler();
List<SatConstraint> cstrs = new ArrayList<>();
cstrs.add(new Fence(vm1, n1));
cstrs.add(new Fence(vm2, n2));
ReconfigurationPlan p = s.solve(mo, cstrs);
Assert.assertNotNull(p);
Model res = p.getResult();
rc = (ShareableResource.get(res, "foo"));
// rcm.getVirtualUsage(0).isInstantiatedTo(2));
Assert.assertEquals(2, rc.getConsumption(vm1));
// rcm.getVirtualUsage(1).isInstantiatedTo(3));
Assert.assertEquals(3, rc.getConsumption(vm2));
}
use of org.btrplace.model.constraint.SatConstraint in project scheduler by btrplace.
the class CShareableResourceTest method testMisplaced.
@Test
public void testMisplaced() throws SchedulerException {
Model mo = new DefaultModel();
Node n1 = mo.newNode();
Node n2 = mo.newNode();
ShareableResource rc = new ShareableResource("cpu", 10, 1);
VM v1 = mo.newVM();
VM v2 = mo.newVM();
mo.getMapping().addOnlineNode(n1);
mo.getMapping().addOnlineNode(n2);
mo.getMapping().addRunningVM(v1, n1);
mo.getMapping().addRunningVM(v2, n1);
mo.attach(rc);
List<SatConstraint> l = new ArrayList<>();
l.addAll(Preserve.newPreserve(mo.getMapping().getAllVMs(), "cpu", 5));
ChocoScheduler s = new DefaultChocoScheduler();
s.doRepair(true);
ReconfigurationPlan p = s.solve(mo, l);
Assert.assertEquals(s.getStatistics().getNbManagedVMs(), 0);
Assert.assertNotNull(p);
Assert.assertEquals(p.getResult().getMapping(), mo.getMapping());
Assert.assertEquals(p.getSize(), 2);
}
use of org.btrplace.model.constraint.SatConstraint in project scheduler by btrplace.
the class SolverTuning method run.
@Override
@SuppressWarnings("squid:S1166")
public void run() {
// Make a default model with 500 nodes hosting 3,000 VMs
Model model = makeModel();
Set<SatConstraint> constraints = new HashSet<>();
// We allow memory over-commitment with a overbooking ratio of 50%
// i.e. 1MB physical RAM for 1.5MB virtual RAM
constraints.addAll(Overbook.newOverbooks(model.getMapping().getAllNodes(), "mem", 1.5));
/**
* On 10 nodes, 4 of the 6 hosted VMs ask now for a 4GB bandwidth
*/
for (int i = 0; i < 5; i++) {
Node n = nodes.get(i);
Set<VM> vmsOnN = model.getMapping().getRunningVMs(n);
Iterator<VM> ite = vmsOnN.iterator();
for (int j = 0; ite.hasNext() && j < 4; j++) {
VM v = ite.next();
constraints.add(new Preserve(v, "bandwidth", 4));
}
}
ChocoScheduler cra = new DefaultChocoScheduler();
// Customize the estimated duration of actions
cra.getDurationEvaluators().register(MigrateVM.class, new LinearToAResourceActionDuration<VM>("mem", 1, 3));
// We want the best possible solution, computed in up to 5 sec.
cra.doOptimize(true);
cra.setTimeLimit(5);
// We solve without the repair mode
cra.doRepair(false);
try {
solve(cra, model, constraints);
} catch (@SuppressWarnings("unused") SchedulerException ex) {
// Just in case the testing environment is not performant enough
// It does not matter that much if there is no enough time to get a solution here
}
// Re-solve using the repair mode to check for the improvement
cra.doRepair(true);
solve(cra, model, constraints);
}
Aggregations