Instantly share code, notes, and snippets.
Created
March 24, 2020 00:10
-
Save alexandredias3d/a32dfac0131a081503a80685ac9d03b9 to your computer and use it in GitHub Desktop.
Shows a possible bug during migration of VMs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* CloudSim Plus: A modern, highly-extensible and easier-to-use Framework for | |
* Modeling and Simulation of Cloud Computing Infrastructures and Services. | |
* http://cloudsimplus.org | |
* | |
* Copyright (C) 2015-2018 Universidade da Beira Interior (UBI, Portugal) and | |
* the Instituto Federal de Educação Ciência e Tecnologia do Tocantins (IFTO, Brazil). | |
* | |
* This file is part of CloudSim Plus. | |
* | |
* CloudSim Plus is free software: you can redistribute it and/or modify | |
* it under the terms of the GNU General Public License as published by | |
* the Free Software Foundation, either version 3 of the License, or | |
* (at your option) any later version. | |
* | |
* CloudSim Plus is distributed in the hope that it will be useful, | |
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
* GNU General Public License for more details. | |
* | |
* You should have received a copy of the GNU General Public License | |
* along with CloudSim Plus. If not, see <http://www.gnu.org/licenses/>. | |
*/ | |
package org.cloudsimplus.examples.schedulers; | |
import ch.qos.logback.core.CoreConstants; | |
import org.cloudbus.cloudsim.allocationpolicies.VmAllocationPolicyFirstFit; | |
import org.cloudbus.cloudsim.brokers.DatacenterBroker; | |
import org.cloudbus.cloudsim.brokers.DatacenterBrokerSimple; | |
import org.cloudbus.cloudsim.cloudlets.Cloudlet; | |
import org.cloudbus.cloudsim.cloudlets.CloudletSimple; | |
import org.cloudbus.cloudsim.core.CloudSim; | |
import org.cloudbus.cloudsim.datacenters.Datacenter; | |
import org.cloudbus.cloudsim.datacenters.DatacenterSimple; | |
import org.cloudbus.cloudsim.hosts.Host; | |
import org.cloudbus.cloudsim.hosts.HostSimple; | |
import org.cloudbus.cloudsim.provisioners.PeProvisionerSimple; | |
import org.cloudbus.cloudsim.resources.Pe; | |
import org.cloudbus.cloudsim.resources.PeSimple; | |
import org.cloudbus.cloudsim.schedulers.vm.VmSchedulerSpaceShared; | |
import org.cloudbus.cloudsim.schedulers.vm.VmSchedulerTimeShared; | |
import org.cloudbus.cloudsim.vms.Vm; | |
import org.cloudbus.cloudsim.vms.VmSimple; | |
import org.cloudsimplus.builders.tables.CloudletsTableBuilder; | |
import org.cloudsimplus.builders.tables.TextTableColumn; | |
import java.util.ArrayList; | |
import java.util.Arrays; | |
import java.util.Collections; | |
import java.util.HashMap; | |
import java.util.List; | |
import java.util.Map; | |
import org.cloudbus.cloudsim.allocationpolicies.VmAllocationPolicyRoundRobin; | |
import org.cloudbus.cloudsim.schedulers.vm.VmSchedulerTimeSharedOverSubscription; | |
import org.cloudbus.cloudsim.util.Conversion; | |
import org.cloudbus.cloudsim.utilizationmodels.UtilizationModel; | |
import org.cloudbus.cloudsim.utilizationmodels.UtilizationModelDynamic; | |
import org.cloudbus.cloudsim.utilizationmodels.UtilizationModelFull; | |
public class VmSchedulerTimeSharedMigrationExample { | |
class VmAllocationPolicyMigrationTest extends VmAllocationPolicyRoundRobin { | |
private int counter = 0; | |
@Override | |
public boolean isVmMigrationSupported() { | |
return true; | |
} | |
@Override | |
public Map<Vm, Host> getOptimizedAllocationMap(List<? extends Vm> vmList) { | |
if (counter == 0) { | |
for (Vm vm : vmList) { | |
System.out.printf("vm %d on host %d - requested MIPS %s%n", vm.getId(), | |
vm.getHost().getId(), Arrays.toString(vm.getCurrentRequestedMips().toArray())); | |
} | |
for (Host host : hostList) { | |
System.out.printf("host %d - total MIPS %s - available MIPS %s - available PEs %s%n", host.getId(), | |
host.getTotalMipsCapacity(), host.getTotalAvailableMips(), host.getFreePeList()); | |
} | |
Map<Vm, Host> migrationMap = new HashMap<>(); | |
migrationMap.put(vmList.get(0), getHostList().get(2)); | |
counter++; | |
return migrationMap; | |
} | |
return Collections.EMPTY_MAP; | |
} | |
} | |
// VM configuration | |
private static final long VM_SIZE = 2_500; | |
private static final long VM_BW = 100_000; | |
private static final int VM_PES = 1; | |
private static final long VM1_RAM = 870; | |
private static final long VM1_MIPS = 2_500; | |
private static final long VM2_RAM = 3_750; | |
private static final long VM2_MIPS = 2_000; | |
private static final long VM3_RAM = 1_740; | |
private static final long VM3_MIPS = 1_000; | |
private static final long VM4_RAM = 613; | |
private static final long VM4_MIPS = 500; | |
private static final long HOST_BW = 1_000_000; | |
private static final long HOST_STORAGE = 1_000_000; | |
private static final long HOST_PES = 2; | |
private static final long HOST1_RAM = (long) Conversion.gigaToMega(4); | |
private static final long HOST1_MIPS = 1860; | |
private static final long HOST2_RAM = (long) Conversion.gigaToMega(4); | |
private static final long HOST2_MIPS = 1860; | |
private static final long HOST3_RAM = (long) Conversion.gigaToMega(4); | |
private static final long HOST3_MIPS = 2660; | |
private static final int CLOUDLET_PES = VM_PES; | |
private static final int CLOUDLET_LENGTH = 100_000_000; | |
private final CloudSim simulation; | |
private DatacenterBroker broker0; | |
private List<Host> hostList; | |
private List<Vm> vmList; | |
private List<Cloudlet> cloudletList; | |
private static final int SCHEDULING_INTERVAL = 300; | |
public static void main(String[] args) { | |
new VmSchedulerTimeSharedExample(); | |
} | |
private VmSchedulerTimeSharedExample() { | |
simulation = new CloudSim(); | |
hostList = new ArrayList<>(); | |
vmList = new ArrayList<>(); | |
cloudletList = new ArrayList<>(); | |
createDatacenter(); | |
broker0 = new DatacenterBrokerSimple(simulation); | |
createVms(); | |
createCloudlets(); | |
broker0.submitVmList(vmList); | |
broker0.submitCloudletList(cloudletList); | |
simulation.start(); | |
} | |
private void createDatacenter() { | |
List<Pe> peList1 = new ArrayList<>(); | |
for (int i = 0; i < HOST_PES; i++) { | |
peList1.add(new PeSimple(HOST1_MIPS, new PeProvisionerSimple())); | |
} | |
Host host1 = new HostSimple(HOST1_RAM, HOST_BW, HOST_STORAGE, peList1); | |
host1.setVmScheduler(new VmSchedulerTimeShared()); | |
host1.enableStateHistory(); | |
List<Pe> peList2 = new ArrayList<>(); | |
for (int i = 0; i < HOST_PES; i++) { | |
peList2.add(new PeSimple(HOST2_MIPS, new PeProvisionerSimple())); | |
} | |
Host host2 = new HostSimple(HOST2_RAM, HOST_BW, HOST_STORAGE, peList2); | |
host2.setVmScheduler(new VmSchedulerTimeShared()); | |
host2.enableStateHistory(); | |
List<Pe> peList3 = new ArrayList<>(); | |
for (int i = 0; i < HOST_PES; i++) { | |
peList3.add(new PeSimple(HOST3_MIPS, new PeProvisionerSimple())); | |
} | |
Host host3 = new HostSimple(HOST3_RAM, HOST_BW, HOST_STORAGE, peList3); | |
host3.setVmScheduler(new VmSchedulerTimeShared()); | |
host3.enableStateHistory(); | |
hostList.add(host1); | |
hostList.add(host2); | |
hostList.add(host3); | |
Datacenter dc0 = new DatacenterSimple(simulation, hostList, new VmAllocationPolicyMigrationTest()); | |
dc0.setSchedulingInterval(SCHEDULING_INTERVAL); | |
dc0.enableMigrations(); | |
} | |
private void createVms() { | |
Vm vm1 = new VmSimple(VM1_MIPS, VM_PES) | |
.setRam(VM1_RAM).setBw(VM_BW).setSize(VM_SIZE); | |
Vm vm2 = new VmSimple(VM2_MIPS, VM_PES) | |
.setRam(VM2_RAM).setBw(VM_BW).setSize(VM_SIZE); | |
Vm vm3 = new VmSimple(VM3_MIPS, VM_PES) | |
.setRam(VM3_RAM).setBw(VM_BW).setSize(VM_SIZE); | |
Vm vm4 = new VmSimple(VM4_MIPS, VM_PES) | |
.setRam(VM4_RAM).setBw(VM_BW).setSize(VM_SIZE); | |
vmList.add(vm1); | |
vmList.add(vm2); | |
vmList.add(vm3); | |
vmList.add(vm4); | |
} | |
private void createCloudlets() { | |
for (Vm vm : vmList) { | |
Cloudlet cloudlet = new CloudletSimple(CLOUDLET_LENGTH, CLOUDLET_PES); | |
cloudlet.setVm(vm); | |
cloudletList.add(cloudlet); | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment