How to Calculate the Expected Execution Time of a VM?
Share
Condition for Calculate the Expected Execution Time of a VM
Description: The Expected Execution Time is calculated by dividing the total number of instructions of the cloudlet by the MIPS value of the VM. This gives you an estimate of how long the VM will take to execute the cloudlet under ideal conditions, assuming no other external delays or resource limitations. It helps in assessing the VM's performance and is often used in scheduling tasks to ensure that deadlines or resource constraints are met. This formula can be adjusted for more complex scenarios involving varying task sizes, VM capabilities, or resource utilization.
Sample Code
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.LinkedList;
import java.util.List;
import org.cloudbus.cloudsim.Cloudlet;
import org.cloudbus.cloudsim.CloudletSchedulerTimeShared;
import org.cloudbus.cloudsim.Datacenter;
import org.cloudbus.cloudsim.DatacenterBroker;
import org.cloudbus.cloudsim.DatacenterCharacteristics;
import org.cloudbus.cloudsim.Host;
import org.cloudbus.cloudsim.Log;
import org.cloudbus.cloudsim.Pe;
import org.cloudbus.cloudsim.Storage;
import org.cloudbus.cloudsim.UtilizationModel;
import org.cloudbus.cloudsim.UtilizationModelFull;
import org.cloudbus.cloudsim.Vm;
import org.cloudbus.cloudsim.VmAllocationPolicySimple;
import org.cloudbus.cloudsim.VmSchedulerTimeShared;
import org.cloudbus.cloudsim.core.CloudSim;
import org.cloudbus.cloudsim.provisioners.BwProvisionerSimple;
import org.cloudbus.cloudsim.provisioners.PeProvisionerSimple;
import org.cloudbus.cloudsim.provisioners.RamProvisionerSimple;
/**
* A simple example showing how to create a data center with one host, run one cloudlet on it,
* and calculate the Expected Execution Time (EET) of the VMs.
*/
public class ExpectedExecutionTimeCalculator {
/** The cloudlet list. */
private static List cloudletList;
/** The vmlist. */
private static List vmlist;
/**
* Creates main() to run this example.
*
* @param args the args
*/
public static void main(String[] args) {
Log.printLine("Starting CloudSimExample1...");
try {
// First step: Initialize the CloudSim package. It should be called before creating any entities.
int num_user = 1; // number of cloud users
Calendar calendar = Calendar.getInstance(); // Calendar whose fields have been initialized with the current date and time.
boolean trace_flag = false; // trace events
CloudSim.init(num_user, calendar, trace_flag);
// Second step: Create Datacenters
Datacenter datacenter0 = createDatacenter("Datacenter_0");
// Third step: Create Broker
DatacenterBroker broker = createBroker();
int brokerId = broker.getId();
// Fourth step: Create one virtual machine
vmlist = new ArrayList();
// VM description
int vmid = 0;
int mips = 1000;
long size = 10000; // image size (MB)
int ram = 512; // vm memory (MB)
long bw = 1000;
int pesNumber = 1; // number of cpus
String vmm = "Xen"; // VMM name
// create VM
Vm vm = new Vm(vmid, brokerId, mips, pesNumber, ram, bw, size, vmm, new CloudletSchedulerTimeShared());
// add the VM to the vmList
vmlist.add(vm);
// submit vm list to the broker
broker.submitVmList(vmlist);
// Fifth step: Create one Cloudlet
cloudletList = new ArrayList();
// Cloudlet properties
int id = 0;
long length = 400000;
long fileSize = 300;
long outputSize = 300;
UtilizationModel utilizationModel = new UtilizationModelFull();
Cloudlet cloudlet = new Cloudlet(id, length, pesNumber, fileSize,
outputSize, utilizationModel,
utilizationModel, utilizationModel);
cloudlet.setUserId(brokerId);
cloudlet.setVmId(vmid);
// add the cloudlet to the list
cloudletList.add(cloudlet);
// submit cloudlet list to the broker
broker.submitCloudletList(cloudletList);
// Sixth step: Start the simulation
CloudSim.startSimulation();
// Calculate the Expected Execution Time for VMs
calculateExpectedExecutionTime();
CloudSim.stopSimulation();
// Final step: Print results when simulation is over
List newList = broker.getCloudletReceivedList();
printCloudletList(newList);
Log.printLine(" ");
Log.printLine("CloudSimExample1 finished!");
} catch (Exception e) {
e.printStackTrace();
Log.printLine("Unwanted errors happen");
}
}
/**
* Creates the datacenter.
*
* @param name the name
*
* @return the datacenter
*/
private static Datacenter createDatacenter(String name) {
List hostList = new ArrayList();
List peList = new ArrayList();
int mips = 1000;
peList.add(new Pe(0, new PeProvisionerSimple(mips))); // need to store Pe id and MIPS Rating
int hostId = 0;
int ram = 2048; // host memory (MB)
long storage = 1000000; // host storage
int bw = 10000;
hostList.add(new Host(hostId, new RamProvisionerSimple(ram), new BwProvisionerSimple(bw),
storage, peList, new VmSchedulerTimeShared(peList)));
String arch = "x86";
String os = "Linux";
String vmm = "Xen";
double time_zone = 10.0;
double cost = 3.0;
double costPerMem = 0.05;
double costPerStorage = 0.001;
double costPerBw = 0.0;
LinkedList storageList = new LinkedList();
DatacenterCharacteristics characteristics = new DatacenterCharacteristics(arch, os, vmm, hostList,
time_zone, cost, costPerMem, costPerStorage, costPerBw);
Datacenter datacenter = null;
try {
datacenter = new Datacenter(name, characteristics, new VmAllocationPolicySimple(hostList), storageList, 0);
} catch (Exception e) {
e.printStackTrace();
}
return datacenter;
}
/**
* Creates the broker.
*
* @return the broker
*/
private static DatacenterBroker createBroker() {
DatacenterBroker broker = null;
try {
broker = new DatacenterBroker("Broker");
} catch (Exception e) {
e.printStackTrace();
}
return broker;
}
/**
* Prints the cloudlet list.
*
* @param list the list
*/
private static void printCloudletList(List list) {
int size = list.size();
Cloudlet cloudlet;
String indent = " ";
Log.printLine();
Log.printLine("Cloudlet ID" + indent + "Status" + indent + "VM ID" + indent + "Time" + indent + "Start Time" + indent + "Finish Time");
DecimalFormat dft = new DecimalFormat("###.##");
for (int i = 0; i < size; i++) {
cloudlet = list.get(i);
Log.print(indent + cloudlet.getCloudletId() + indent + cloudlet.getStatus() + indent + cloudlet.getVmId() + indent
+ dft.format(cloudlet.getActualCPUTime()) + indent + dft.format(cloudlet.getExecStartTime()) + indent
+ dft.format(cloudlet.getFinishTime()));
}
}
/**
* Calculates the Expected Execution Time (EET) for each VM.
*/
private static void calculateExpectedExecutionTime() {
// Get the list of VMs created
int vsize = getVmsCreatedList().size();
double[] exec = new double[vsize];
for (int i = 0; i < vsize; i++) {
Vm vm = getVmsCreatedList().get(i);
// Cloudlet/task properties
Cloudlet cloudlet1 = cloudletList.get(0); // Single cloudlet
long length = cloudlet1.getCloudletLength();
double expectedExecutionTime = (double) length / vm.getMips(); // Simplified calculation, can be modified
exec[i] = expectedExecutionTime;
Log.printLine("Expected Execution Time for VM" + (i + 1) + " is: " + exec[i]);
}
}
/**
* Get the VMs created list.
*
* @return the list of created VMs
*/
private static List getVmsCreatedList() {
return vmlist;
}
}