Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved network and power model required for LEAF #1

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -92,17 +92,17 @@ private NetworkExample1() {

private void configureNetwork() {
//load the network topology file
NetworkTopology networkTopology = BriteNetworkTopology.getInstance(NETWORK_TOPOLOGY_FILE);
BriteNetworkTopology networkTopology = BriteNetworkTopology.getInstance(NETWORK_TOPOLOGY_FILE);
simulation.setNetworkTopology(networkTopology);

//maps CloudSim entities to BRITE entities
//Datacenter will correspond to BRITE node 0
int briteNode = 0;
networkTopology.mapNode(datacenter0.getId(), briteNode);
networkTopology.mapNode(datacenter0, briteNode);

//Broker will correspond to BRITE node 3
briteNode = 3;
networkTopology.mapNode(broker.getId(), briteNode);
networkTopology.mapNode(broker, briteNode);
}

private void createAndSubmitCloudlets(DatacenterBroker broker) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,21 +85,21 @@ private NetworkExample2() {

private void configureNetwork() {
//Configures network by loading the network topology file
NetworkTopology networkTopology = BriteNetworkTopology.getInstance(NETWORK_TOPOLOGY_FILE);
BriteNetworkTopology networkTopology = BriteNetworkTopology.getInstance(NETWORK_TOPOLOGY_FILE);
simulation.setNetworkTopology(networkTopology);

//Maps CloudSim entities to BRITE entities
//Datacenter0 will correspond to BRITE node 0
int briteNode = 0;
networkTopology.mapNode(datacenterList.get(0).getId(), briteNode);
networkTopology.mapNode(datacenterList.get(0), briteNode);

//Datacenter1 will correspond to BRITE node 2
briteNode = 2;
networkTopology.mapNode(datacenterList.get(1).getId(), briteNode);
networkTopology.mapNode(datacenterList.get(1), briteNode);

//Broker will correspond to BRITE node 3
briteNode = 3;
networkTopology.mapNode(broker.getId(), briteNode);
networkTopology.mapNode(broker, briteNode);
}

private void createAndSubmitCloudlets() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,25 +149,25 @@ private void createAndSubmitVms() {
*/
private void createNetwork() {
//load the network topology file
NetworkTopology networkTopology = BriteNetworkTopology.getInstance("topology.brite");
BriteNetworkTopology networkTopology = BriteNetworkTopology.getInstance("topology.brite");
simulation.setNetworkTopology(networkTopology);

//Maps CloudSim entities to BRITE entities
//Datacenter0 will correspond to BRITE node 0
int briteNode = 0;
networkTopology.mapNode(datacenterList.get(0).getId(), briteNode);
networkTopology.mapNode(datacenterList.get(0), briteNode);

//Datacenter1 will correspond to BRITE node 2
briteNode = 2;
networkTopology.mapNode(datacenterList.get(1).getId(), briteNode);
networkTopology.mapNode(datacenterList.get(1), briteNode);

//Broker1 will correspond to BRITE node 3
briteNode = 3;
networkTopology.mapNode(brokerList.get(0).getId(), briteNode);
networkTopology.mapNode(brokerList.get(0), briteNode);

//Broker2 will correspond to BRITE node 4
briteNode = 4;
networkTopology.mapNode(brokerList.get(1).getId(), briteNode);
networkTopology.mapNode(brokerList.get(1), briteNode);
}

private Datacenter createDatacenter() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ private void configureNetwork() {
//Configure network by mapping CloudSim entities to BRITE entities
NetworkTopology networkTopology = new BriteNetworkTopology();
simulation.setNetworkTopology(networkTopology);
networkTopology.addLink(datacenter0.getId(), broker.getId(), 10.0, 10);
networkTopology.addLink(datacenter0, broker, 10.0, 10);
}

private void createAndSubmitCloudlets() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@
import org.cloudbus.cloudsim.hosts.Host;
import org.cloudbus.cloudsim.hosts.HostSimple;
import org.cloudbus.cloudsim.hosts.HostStateHistoryEntry;
import org.cloudbus.cloudsim.power.models.PowerModelLinear;
import org.cloudbus.cloudsim.power.models.PowerModel;
import org.cloudbus.cloudsim.power.models.PowerModelHost;
import org.cloudbus.cloudsim.provisioners.PeProvisionerSimple;
import org.cloudbus.cloudsim.provisioners.ResourceProvisionerSimple;
import org.cloudbus.cloudsim.resources.Pe;
Expand All @@ -83,7 +84,7 @@
* dynamic host CPU utilization threshold} based on CPU utilization.
*
* <p>This VmAllocationPolicy considers the power usage of Hosts to place VMs.
* So that, a {@link org.cloudbus.cloudsim.power.models.PowerModel} is being
* So that, a {@link PowerModel} is being
* set to every created Host by means of {@code host.setPowerModel(powerModel)}.</p>
*
* <p>The example uses a {@link UtilizationModelDynamic} that defines the CPU usage of cloudlets
Expand Down Expand Up @@ -268,8 +269,8 @@ private void printHostCpuUsageAndPowerConsumption(final Host host) {
final double time = entry.getKey();
//The sum of CPU usage of every VM which has run in the Host
final double hostCpuUsage = entry.getValue().getSum();
System.out.printf("Time: %6.1f | %9.2f | %.2f%n", time, hostCpuUsage, host.getPowerModel().getPower(hostCpuUsage));
totalHostPowerConsumptionWattSec += host.getPowerModel().getPower(hostCpuUsage);
System.out.printf("Time: %6.1f | %9.2f | %.2f%n", time, hostCpuUsage, host.getPowerModel().computePowerUsage(hostCpuUsage).getTotalUsage());
totalHostPowerConsumptionWattSec += host.getPowerModel().computePowerUsage(hostCpuUsage).getTotalUsage();
}
System.out.printf("Total Host power consumption in the period: %.2f Watt-Sec%n", totalHostPowerConsumptionWattSec);
System.out.println();
Expand Down Expand Up @@ -429,7 +430,7 @@ public Host createHost(int numberOfPes, long mipsByPe) {
.setBwProvisioner(new ResourceProvisionerSimple())
.setVmScheduler(new VmSchedulerTimeShared());
host.enableStateHistory();
host.setPowerModel(new PowerModelLinear(50, 0.3));
host.setPowerModel(new PowerModelHost(35, 50));
return host;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,8 @@
import org.cloudbus.cloudsim.datacenters.DatacenterSimple;
import org.cloudbus.cloudsim.hosts.Host;
import org.cloudbus.cloudsim.hosts.HostSimple;
import org.cloudbus.cloudsim.power.models.PowerAware;
import org.cloudbus.cloudsim.power.models.PowerModel;
import org.cloudbus.cloudsim.power.models.PowerModelLinear;
import org.cloudbus.cloudsim.power.models.PowerModelHost;
import org.cloudbus.cloudsim.provisioners.PeProvisionerSimple;
import org.cloudbus.cloudsim.provisioners.ResourceProvisioner;
import org.cloudbus.cloudsim.provisioners.ResourceProvisionerSimple;
Expand Down Expand Up @@ -76,8 +75,8 @@
* <p>However, you may notice in this case that the power usage isn't
* half of the maximum consumption, because there is a minimum
* amount of power to use, even if the Host is idle,
* which is defined by {@link #STATIC_POWER_PERCENT}.
* In the case of the {@link PowerModelLinear},
* which is defined by {@link #STATIC_POWER}.
* In the case of the {@link PowerModelHost},
* there is a constant power which is computed
* and added to consumer power when it
* is lower or equal to the minimum usage percentage.</p>
Expand Down Expand Up @@ -121,12 +120,12 @@ public class PowerExample {
* Defines the minimum percentage of power a Host uses,
* even it it's idle.
*/
private static final double STATIC_POWER_PERCENT = 0.7;
private static final double STATIC_POWER = 35;

/**
* The max number of watt-second (Ws) of power a Host uses.
* The max number of watt of power a Host uses.
*/
private static final int MAX_POWER_WATTS_SEC = 50;
private static final int MAX_POWER = 50;

private final CloudSim simulation;
private DatacenterBroker broker0;
Expand Down Expand Up @@ -169,7 +168,7 @@ private PowerExample(boolean showAllHostUtilizationHistoryEntries) {

new CloudletsTableBuilder(finishedCloudlets).build();
printHostsCpuUtilizationAndPowerConsumption();
printVmsCpuUtilizationAndPowerConsumption();
printVmsCpuUtilization();
}

/**
Expand Down Expand Up @@ -206,7 +205,7 @@ private PowerExample(boolean showAllHostUtilizationHistoryEntries) {
* is computed here, that detail is abstracted.
* </p>
*/
private void printVmsCpuUtilizationAndPowerConsumption() {
private void printVmsCpuUtilization() {
for (Vm vm : vmList) {
System.out.println("Vm " + vm.getId() + " at Host " + vm.getHost().getId() + " CPU Usage and Power Consumption");
System.out.println("----------------------------------------------------------------------------------------------------------------------");
Expand All @@ -215,11 +214,9 @@ private void printVmsCpuUtilizationAndPowerConsumption() {
final UtilizationHistory history = vm.getUtilizationHistory();
for (final double time : history.getHistory().keySet()) {
utilizationHistoryTimeInterval = time - prevTime;
vmPower = history.powerConsumption(time);
final double wattsPerInterval = vmPower*utilizationHistoryTimeInterval;
System.out.printf(
"\tTime %8.1f | Host CPU Usage: %6.1f%% | Power Consumption: %8.0f Watt-Sec * %6.0f Secs = %10.2f Watt-Sec%n",
time, history.getHostCpuUtilization(time) *100, vmPower, utilizationHistoryTimeInterval, wattsPerInterval);
"\tTime %8.1f | Host CPU Usage: %6.1f%%",
time, history.getHostCpuUtilization(time) *100);
prevTime = time;
}
System.out.println();
Expand Down Expand Up @@ -251,7 +248,7 @@ private void printHostCpuUtilizationAndPowerConsumption(final Host host) {
utilizationHistoryTimeInterval = entry.getKey() - prevTime;
//The total Host's CPU utilization for the time specified by the map key
final double utilizationPercent = entry.getValue().getSum();
final double watts = host.getPowerModel().getPower(utilizationPercent);
final double watts = host.getPowerModel().computePowerUsage(utilizationPercent).getTotalUsage();
//Energy consumption in the time interval
final double wattsSec = watts*utilizationHistoryTimeInterval;
//Energy consumption in the entire simulation time
Expand All @@ -269,11 +266,11 @@ private void printHostCpuUtilizationAndPowerConsumption(final Host host) {

System.out.printf(
"Total Host %d Power Consumption in %.0f secs: %.0f Watt-Sec (%.5f KWatt-Hour)%n",
host.getId(), simulation.clock(), totalWattsSec, PowerAware.wattsSecToKWattsHour(totalWattsSec));
host.getId(), simulation.clock(), totalWattsSec, wattsSecToKWattsHour(totalWattsSec));
final double powerWattsSecMean = totalWattsSec / simulation.clock();
System.out.printf(
"Mean %.2f Watt-Sec for %d usage samples (%.5f KWatt-Hour)%n",
powerWattsSecMean, utilizationPercentHistory.size(), PowerAware.wattsSecToKWattsHour(powerWattsSecMean));
powerWattsSecMean, utilizationPercentHistory.size(), wattsSecToKWattsHour(powerWattsSecMean));
System.out.printf("----------------------------------------------------------------------------------------------------------------------%n%n");
}

Expand All @@ -298,7 +295,7 @@ private Host createPowerHost() {
peList.add(new PeSimple(1000, new PeProvisionerSimple()));
}

final PowerModel powerModel = new PowerModelLinear(MAX_POWER_WATTS_SEC, STATIC_POWER_PERCENT);
final PowerModelHost powerModel = new PowerModelHost(STATIC_POWER, MAX_POWER);

final long ram = 2048; //in Megabytes
final long bw = 10000; //in Megabits/s
Expand Down Expand Up @@ -354,4 +351,8 @@ private List<Cloudlet> createCloudlets() {
return list;
}

static double wattsSecToKWattsHour(final double power) {
return power / (3600.0 * 1000.0);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@
import org.cloudbus.cloudsim.datacenters.DatacenterSimple;
import org.cloudbus.cloudsim.hosts.Host;
import org.cloudbus.cloudsim.hosts.HostSimple;
import org.cloudbus.cloudsim.power.models.PowerAware;
import org.cloudbus.cloudsim.power.models.PowerModelLinear;
import org.cloudbus.cloudsim.power.models.PowerModelHost;
import org.cloudbus.cloudsim.provisioners.PeProvisionerSimple;
import org.cloudbus.cloudsim.provisioners.ResourceProvisionerSimple;
import org.cloudbus.cloudsim.resources.Pe;
Expand Down Expand Up @@ -86,21 +85,17 @@ public class PowerExampleSchedulingInterval {
* Defines the minimum percentage of power a Host uses,
* even when it's idle.
*/
private static final double STATIC_POWER_PERCENT = 0.7;
private static final double STATIC_POWER = 35;

/**
* The max number of watt-second (Ws) of power a Host uses.
* The max number of watts of power a Host uses.
*/
private static final int MAX_POWER_WATTS_SEC = 50;
private static final int MAX_POWER = 50;

private final int schedulingInterval;
private boolean showAllHostUtilizationHistoryEntries;

private CloudSim simulation;
private DatacenterBroker broker0;
private List<Vm> vmList;
private List<Cloudlet> cloudletList;
private Datacenter datacenter0;
private List<Host> hostList;

public static void main(String[] args) {
Expand All @@ -124,11 +119,11 @@ private PowerExampleSchedulingInterval(
simulation = new CloudSim();
hostList = new ArrayList<>(HOSTS);
this.schedulingInterval = schedulingInterval;
datacenter0 = createDatacenterSimple();
broker0 = new DatacenterBrokerSimple(simulation);
Datacenter datacenter0 = createDatacenterSimple();
DatacenterBroker broker0 = new DatacenterBrokerSimple(simulation);

vmList = createVms();
cloudletList = createCloudlets();
List<Vm> vmList = createVms();
List<Cloudlet> cloudletList = createCloudlets();
broker0.submitVmList(vmList);
broker0.submitCloudletList(cloudletList);

Expand Down Expand Up @@ -165,7 +160,7 @@ private void printHostCpuUtilizationAndPowerConsumption(final Host host) {
utilizationHistoryTimeInterval = entry.getKey() - prevTime;
//The total Host's CPU utilization for the time specified by the map key
final double utilizationPercent = entry.getValue().getSum();
final double watts = host.getPowerModel().getPower(utilizationPercent);
final double watts = host.getPowerModel().computePowerUsage(utilizationPercent).getTotalUsage();
//Energy consumption in the time interval
final double wattsSec = watts*utilizationHistoryTimeInterval;
//Energy consumption in the entire simulation time
Expand All @@ -183,11 +178,11 @@ private void printHostCpuUtilizationAndPowerConsumption(final Host host) {

System.out.printf(
"Total Host %d Power Consumption in %.0f secs: %.0f Watt-Sec (%.5f KWatt-Hour)%n",
host.getId(), simulation.clock(), totalWattsSec, PowerAware.wattsSecToKWattsHour(totalWattsSec));
host.getId(), simulation.clock(), totalWattsSec, PowerExample.wattsSecToKWattsHour(totalWattsSec));
final double powerWattsSecMean = totalWattsSec / simulation.clock();
System.out.printf(
"Mean %.2f Watt-Sec for %d usage samples (%.5f KWatt-Hour)%n",
powerWattsSecMean, utilizationPercentHistory.size(), PowerAware.wattsSecToKWattsHour(powerWattsSecMean));
powerWattsSecMean, utilizationPercentHistory.size(), PowerExample.wattsSecToKWattsHour(powerWattsSecMean));
}

private Datacenter createDatacenterSimple() {
Expand All @@ -212,7 +207,7 @@ private Host createPowerHost() {
final long storage = 1000000; //in Megabytes

final Host host = new HostSimple(ram, bw, storage, peList);
host.setPowerModel(new PowerModelLinear(MAX_POWER_WATTS_SEC, STATIC_POWER_PERCENT));
host.setPowerModel(new PowerModelHost(STATIC_POWER, MAX_POWER));
host
.setRamProvisioner(new ResourceProvisionerSimple())
.setBwProvisioner(new ResourceProvisionerSimple())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import org.cloudbus.cloudsim.datacenters.DatacenterSimple;
import org.cloudbus.cloudsim.hosts.Host;
import org.cloudbus.cloudsim.hosts.HostSimple;
import org.cloudbus.cloudsim.power.models.PowerModelLinear;
import org.cloudbus.cloudsim.power.models.PowerModelHost;
import org.cloudbus.cloudsim.provisioners.PeProvisionerSimple;
import org.cloudbus.cloudsim.provisioners.ResourceProvisionerSimple;
import org.cloudbus.cloudsim.resources.Pe;
Expand Down Expand Up @@ -287,10 +287,10 @@ private Datacenter createDatacenter() {
private Host createHost(final int numberOfPes, final long mipsByPe) {
final List<Pe> peList = createPeList(numberOfPes, mipsByPe);
final Host host = new HostSimple(HOST_RAM, HOST_BW, HOST_STORAGE, peList);
host.setPowerModel(new PowerModelLinear(1000, 0.7))
.setRamProvisioner(new ResourceProvisionerSimple())
.setBwProvisioner(new ResourceProvisionerSimple())
.setVmScheduler(new VmSchedulerTimeShared());
host.setPowerModel(new PowerModelHost(700, 1000));
host.setRamProvisioner(new ResourceProvisionerSimple());
host.setBwProvisioner(new ResourceProvisionerSimple());
host.setVmScheduler(new VmSchedulerTimeShared());
return host;
}

Expand Down
2 changes: 1 addition & 1 deletion cloudsim-plus/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>org.cloudsimplus</groupId>
<artifactId>cloudsim-plus</artifactId>
<version>5.5.1</version>
<version>5.5.1-leaf</version>

<name>CloudSim Plus API</name>
<description>CloudSim Plus: A modern, highly extensible and easier-to-use Java 8+ Framework for Modeling and Simulation of Cloud Computing Infrastructures and Services</description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ private String overloadedHostToString(final Host host) {
protected double getPowerDifferenceAfterAllocation(final Host host, final Vm vm){
final double powerAfterAllocation = getPowerAfterAllocation(host, vm);
if (powerAfterAllocation > 0) {
return powerAfterAllocation - host.getPowerModel().getPower();
return powerAfterAllocation - host.getPowerModel().measure().getTotalUsage();
}

return 0;
Expand Down Expand Up @@ -653,7 +653,7 @@ private void restoreAllocation() {
*/
protected double getPowerAfterAllocation(final Host host, final Vm vm) {
try {
return host.getPowerModel().getPower(getMaxUtilizationAfterAllocation(host, vm));
return host.getPowerModel().computePowerUsage(getMaxUtilizationAfterAllocation(host, vm)).getTotalUsage();
} catch (IllegalArgumentException e) {
LOGGER.error("Power consumption for {} could not be determined: {}", host, e.getMessage());
}
Expand Down
Loading