Commit 2f9bb721 authored by Benardi's avatar Benardi
Browse files

Add power utilization history on host

Remove discreet time values from logging.

Add custom power history for host.
parent a325c081
......@@ -19,6 +19,8 @@ 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.power.models.PowerModel;
import org.cloudbus.cloudsim.power.models.PowerModelSpecPowerDvfsMode;
import org.cloudbus.cloudsim.provisioners.PeProvisionerSimple;
import org.cloudbus.cloudsim.provisioners.ResourceProvisioner;
import org.cloudbus.cloudsim.provisioners.ResourceProvisionerShared;
......@@ -170,7 +172,7 @@ public class SlaExploitationSimulation2Hosts {
CsvGenerator.outputCloudletResults(PATH+"cloudlets-"+FILEID, finishedCloudlets);
CsvGenerator.outputSlaResults(PATH+"sla-"+FILEID, finishedCloudlets, (int) simulation.clock());
CsvGenerator.outputHostsEnergy(PATH+"hosts-"+FILEID, datacenter.getHostList(),datacenter.getSchedulingInterval());
CsvGenerator.outputHostsEnergy(PATH+"hosts-"+FILEID, datacenter.getHostList(),SCHEDULING_TIME);
}
private SlaContract createSlaContract(long minimum_iops, double availability) {
......@@ -227,13 +229,15 @@ public class SlaExploitationSimulation2Hosts {
List<Pe> peList = createPeList(HOST_PES);
ResourceProvisioner ramProvisioner = new ResourceProvisionerSimple();
ResourceProvisioner bwProvisioner = new ResourceProvisionerSimple();
ResourceProvisioner bwProvisioner = new ResourceProvisionerSimple();
PowerModel powerModel = new PowerModelSpecPowerDvfsMode();
Host host = new HostSimple(HOST_RAM, HOST_IOPS, HOST_BW, HOST_BASE_STORAGE, peList);
host.setIopsProvisioner(iopsProvisioner)
.setRamProvisioner(ramProvisioner)
.setBwProvisioner(bwProvisioner)
.setVmScheduler(vmScheduler);
.setVmScheduler(vmScheduler)
.setPowerModel(powerModel);
host.enableStateHistory();
return host;
......@@ -247,6 +251,7 @@ public class SlaExploitationSimulation2Hosts {
((VmSimple)vm).setInitialRequestedIops(VM_IOPS);
vm.setContract(contract);
vm.getUtilizationHistory().enable();
vm.getUtilizationHistory().setMaxHistoryEntries(Integer.MAX_VALUE);
list.add(vm);
}
......
......@@ -19,6 +19,8 @@ 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.power.models.PowerModel;
import org.cloudbus.cloudsim.power.models.PowerModelSpecPowerDvfsMode;
import org.cloudbus.cloudsim.provisioners.PeProvisionerSimple;
import org.cloudbus.cloudsim.provisioners.ResourceProvisioner;
import org.cloudbus.cloudsim.provisioners.ResourceProvisionerShared;
......@@ -64,7 +66,7 @@ import org.cloudsimplus.slametrics.SlaMetricDimension;
public class SlaExploitationSimulation4Hosts {
private static String PATH;
private static String PATH = "/home/benardi/";
private static String FILEID;
private static int SLA_TIGHT_HOSTS;
private static int SLA_LOOSE_HOSTS;
......@@ -174,7 +176,8 @@ public class SlaExploitationSimulation4Hosts {
new CloudletsTableBuilder(finishedCloudlets).build();
CsvGenerator.outputCloudletResults(PATH+"cloudlets-"+FILEID, finishedCloudlets);
CsvGenerator.outputSlaResults(PATH+"sla-"+FILEID, finishedCloudlets, (int) simulation.clock());
CsvGenerator.outputSlaResults(PATH+"sla-"+FILEID, finishedCloudlets, (int) simulation.clock());
CsvGenerator.outputHostsEnergy(PATH+"hosts-"+FILEID, datacenter.getHostList(),SCHEDULING_TIME);
}
private SlaContract createSlaContract(long minimum_iops, double availability) {
......@@ -231,14 +234,18 @@ public class SlaExploitationSimulation4Hosts {
List<Pe> peList = createPeList(HOST_PES);
ResourceProvisioner ramProvisioner = new ResourceProvisionerSimple();
ResourceProvisioner bwProvisioner = new ResourceProvisionerSimple();
ResourceProvisioner bwProvisioner = new ResourceProvisionerSimple();
PowerModel powerModel = new PowerModelSpecPowerDvfsMode();
Host host = new HostSimple(HOST_RAM, HOST_IOPS, HOST_BW, HOST_BASE_STORAGE, peList);
host.setIopsProvisioner(iopsProvisioner)
.setRamProvisioner(ramProvisioner)
.setBwProvisioner(bwProvisioner)
.setVmScheduler(vmScheduler);
.setVmScheduler(vmScheduler)
.setPowerModel(powerModel);
host.enableStateHistory();
host.getPowerUtilizationHistory().enable();
host.getPowerUtilizationHistory().setMaxHistoryEntries(Integer.MAX_VALUE);
return host;
}
......@@ -250,6 +257,8 @@ public class SlaExploitationSimulation4Hosts {
.setIops(VM_IOPS).setCloudletScheduler(new CloudletSchedulerSpaceShared());
((VmSimple)vm).setInitialRequestedIops(VM_IOPS);
vm.setContract(contract);
vm.getUtilizationHistory().enable();
vm.getUtilizationHistory().setMaxHistoryEntries(Integer.MAX_VALUE);
list.add(vm);
}
......
......@@ -548,7 +548,7 @@ public class DatacenterSimple extends CloudSimEntity implements Datacenter {
for(Host host : hostList){
HostSimple hs = (HostSimple) host;
if(hs.getIopsProvisioner() instanceof ResourceProvisionerSimple){
if(hs.getVmList().isEmpty()){
if(hs.getVmList().isEmpty() && hs.isActive()){
hs.setActive(false);
Log.printFormattedLine("[Host] %s had just been turned off!", hs.getId());
}
......
......@@ -10,6 +10,7 @@ package org.cloudbus.cloudsim.hosts;
import org.cloudbus.cloudsim.core.Machine;
import org.cloudbus.cloudsim.power.models.PowerModel;
import org.cloudbus.cloudsim.resources.*;
import org.cloudbus.cloudsim.vms.UtilizationHistory;
import org.cloudbus.cloudsim.vms.Vm;
import org.cloudbus.cloudsim.datacenters.Datacenter;
import org.cloudbus.cloudsim.schedulers.vm.VmScheduler;
......@@ -616,4 +617,6 @@ public interface Host extends Machine, Comparable<Host> {
* @return
*/
List<Vm> getFinishedVms();
UtilizationHistory getPowerUtilizationHistory();
}
......@@ -8,6 +8,7 @@ import org.cloudbus.cloudsim.resources.Pe;
import org.cloudbus.cloudsim.resources.Resource;
import org.cloudbus.cloudsim.resources.ResourceManageable;
import org.cloudbus.cloudsim.schedulers.vm.VmScheduler;
import org.cloudbus.cloudsim.vms.UtilizationHistory;
import org.cloudbus.cloudsim.vms.Vm;
import org.cloudsimplus.listeners.EventListener;
import org.cloudsimplus.listeners.HostUpdatesVmsProcessingEventInfo;
......@@ -207,6 +208,8 @@ final class HostNull implements Host {
return 0;
}
public UtilizationHistory getPowerUtilizationHistory() {
return null;
}
}
......@@ -9,6 +9,7 @@ package org.cloudbus.cloudsim.hosts;
import org.cloudbus.cloudsim.power.models.PowerModel;
import org.cloudbus.cloudsim.resources.*;
import org.cloudbus.cloudsim.util.Log;
import org.cloudbus.cloudsim.vms.UtilizationHistory;
import org.cloudbus.cloudsim.vms.Vm;
import org.cloudbus.cloudsim.datacenters.Datacenter;
import org.cloudbus.cloudsim.schedulers.vm.VmScheduler;
......@@ -43,6 +44,8 @@ public class HostSimple implements Host {
private final List<HostStateHistoryEntry> stateHistory;
private PowerModel powerModel;
protected final UtilizationHistory utilizationHistory;
/**
* @see #getId()
*/
......@@ -171,6 +174,9 @@ public class HostSimple implements Host {
this.vmsMigratingIn = new HashSet<>();
this.vmsMigratingOut = new HashSet<>();
this.powerModel = PowerModel.NULL;
utilizationHistory = new HostUtilizationHistory(this, false);
stateHistory = new LinkedList<>();
}
......@@ -199,6 +205,9 @@ public class HostSimple implements Host {
this.vmsMigratingIn = new HashSet<>();
this.vmsMigratingOut = new HashSet<>();
this.powerModel = PowerModel.NULL;
utilizationHistory = new HostUtilizationHistory(this, false);
stateHistory = new LinkedList<>();
}
......@@ -248,6 +257,7 @@ public class HostSimple implements Host {
notifyOnUpdateProcessingListeners(nextSimulationTime);
addStateHistory(currentTime);
utilizationHistory.addPowerUtilizationHistory(currentTime);
return nextSimulationTime;
}
......@@ -889,6 +899,10 @@ public class HostSimple implements Host {
return utilizationHistory;
}
public UtilizationHistory getPowerUtilizationHistory() {
return utilizationHistory;
}
private int getMaxNumberOfVmHistoryEntries() {
return vmCreatedList
.stream()
......
package org.cloudbus.cloudsim.hosts;
import org.cloudbus.cloudsim.util.MathUtil;
import org.cloudbus.cloudsim.vms.UtilizationHistory;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
/**
* Stores resource utilization data for a specific {@link Vm}.
*
* @author Anton Beloglazov
* @author Manoel Campos da Silva Filho
* @since CloudSim Plus 1.4
*/
public class HostUtilizationHistory implements UtilizationHistory {
private boolean enabled;
private int maxHistoryEntries;
/**
* @see #getHistory()
*/
public final List<Double> history;
public final List<Double> timeHistory;
private final Host host;
/**
* @see #getPreviousTime()
*/
public double previousTime;
/**
* Instantiates the class to store resource utilization history for a specific {@link Vm}.
*
* @param host the vm to instantiates the object to store utilization history
* @param enabled true if the history must be enabled by default, enabling usage
* history to be collected and stored;
* false if it must be disabled to avoid storing any history,
* in order to reduce memory usage
*/
public HostUtilizationHistory(final Host host, final boolean enabled) {
this.history = new LinkedList<>();
this.timeHistory = new LinkedList<>();
this.host = host;
this.enabled = enabled;
this.setMaxHistoryEntries(DEF_MAX_HISTORY_ENTRIES);
}
public HostUtilizationHistory(final Host host) {
this(host, true);
}
@Override
public double getUtilizationMad() {
if (!history.isEmpty()) {
final int n = Math.min(getMaxHistoryEntries(), getHistory().size());
final double median = MathUtil.median(getHistory());
final double[] deviationSum = new double[n];
for (int i = 0; i < n; i++) {
deviationSum[i] = Math.abs(median - getHistory().get(i));
}
return MathUtil.median(deviationSum);
}
return 0;
}
@Override
public double getUtilizationMean() {
if (!history.isEmpty()) {
final int maxEntries = Math.min(getMaxHistoryEntries(), getHistory().size());
final double usagePercentMean = getHistory().stream()
.limit(maxEntries)
.mapToDouble(usagePercent -> usagePercent)
.average()
.orElse(0);
return usagePercentMean * host.getMips();
}
return 0;
}
@Override
public double getUtilizationVariance() {
if (!history.isEmpty()) {
final double mean = getUtilizationMean();
final int maxNumOfEntriesToAverage = Math.min(getMaxHistoryEntries(), getHistory().size());
return getHistory().stream()
.limit(maxNumOfEntriesToAverage)
.mapToDouble(usagePercent -> usagePercent * host.getMips())
.map(usageValue -> usageValue - mean)
.map(usageValue -> usageValue * usageValue)
.average().orElse(0);
}
return 0;
}
@Override
public void addUtilizationHistory(final double time){
if(!enabled) {
return;
}
if (time > getPreviousTime()) {
final double utilization = host.getUtilizationOfCpu();
if (time != 0 ) {
addUtilizationHistoryValue(utilization, time);
}
setPreviousTime(time);
}
}
public void addPowerUtilizationHistory(final double time){
if(!enabled) {
return;
}
if (time > getPreviousTime()) {
final double utilization = host.getPowerModel().getPower();
if (time != 0 ) {
addUtilizationHistoryValue(utilization, time);
}
setPreviousTime(time);
}
}
/**
* Adds a Power utilization percentage history value to the beginning of the History List.
*
* @param utilization the CPU utilization percentage to add
*/
private void addUtilizationHistoryValue(final double utilization, final double time) {
history.add(utilization);
timeHistory.add(time);
// if (getHistory().size() > getMaxHistoryEntries()) {
// history.remove(getMaxHistoryEntries());
// }
}
@Override
public List<Double> getHistory() {
return Collections.unmodifiableList(history);
}
public List<Double> getTimeHistory() {
return Collections.unmodifiableList(timeHistory);
}
@Override
public double getPreviousTime() {
return previousTime;
}
@Override
public void setPreviousTime(final double previousTime) {
this.previousTime = previousTime;
}
@Override
public boolean isEnabled() {
return enabled;
}
@Override
public void enable() {
this.enabled = true;
}
@Override
public void disable() {
this.enabled = false;
}
@Override
public int getMaxHistoryEntries() {
return maxHistoryEntries;
}
@Override
public void setMaxHistoryEntries(final int maxHistoryEntries) {
this.maxHistoryEntries = maxHistoryEntries;
}
}
......@@ -115,18 +115,20 @@ public class CsvGenerator {
//datacenter.id, host.id, host.time, host.energy
try{
for(Host h : existingHosts){
int moment = 0;
double[] history = h.getUtilizationHistory();
for(int i = 0; i < history.length; i++) {
// int moment = 0;
List<Double> history = h.getPowerUtilizationHistory().getHistory();
List<Double> timeHistory = h.getPowerUtilizationHistory().getTimeHistory();
for(int i = 0; i < history.size(); i++) {
writer.append(String.valueOf(h.getDatacenter().getId()));
writer.append(',');
writer.append(String.valueOf(h.getId()));
writer.append(',');
writer.append(String.valueOf(schedulingInterval * moment));
writer.append(String.valueOf(timeHistory.get(i)));
writer.append(',');
writer.append(String.valueOf(history[i]));
writer.append(String.valueOf((history.get(i) / 100)));
writer.append('\n');
moment++;
// moment++;
}
}
} catch (IOException e) {
......
......@@ -109,4 +109,7 @@ public interface UtilizationHistory {
*/
void setMaxHistoryEntries(int maxHistoryEntries);
void addPowerUtilizationHistory(final double time);
List<Double> getTimeHistory();
}
......@@ -24,4 +24,6 @@ final class UtilizationHistoryNull implements UtilizationHistory {
@Override public void disable() {/**/}
@Override public int getMaxHistoryEntries() { return 0; }
@Override public void setMaxHistoryEntries(int maxHistoryEntries) {/**/}
public void addPowerUtilizationHistory(final double time) {}
public List<Double> getTimeHistory(){ return null; }
}
......@@ -16,7 +16,7 @@ import java.util.List;
public class VmUtilizationHistory implements UtilizationHistory {
private boolean enabled;
private int maxHistoryEntires;
private int maxHistoryEntries;
/**
* @see #getHistory()
......@@ -128,6 +128,10 @@ public class VmUtilizationHistory implements UtilizationHistory {
return Collections.unmodifiableList(history);
}
public List<Double> getTimeHistory() {
return new LinkedList<Double>();
}
@Override
public double getPreviousTime() {
return previousTime;
......@@ -155,11 +159,13 @@ public class VmUtilizationHistory implements UtilizationHistory {
@Override
public int getMaxHistoryEntries() {
return maxHistoryEntires;
return maxHistoryEntries;
}
@Override
public void setMaxHistoryEntries(final int maxHistoryEntries) {
this.maxHistoryEntires = maxHistoryEntries;
this.maxHistoryEntries = maxHistoryEntries;
}
public void addPowerUtilizationHistory(final double time) {}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment