Practical 8: Cloudlet Creation and Execution
Aim
Create cloudlets with chosen task lengths, input sizes and output sizes. Run them on VMs (Virtual Machines). Read the result table and explain the time and cost values.
Theory
A cloudlet represents a task that runs on a VM. Its length describes the amount of processing work, measured in million instructions (MI).
A longer task usually takes more time on the same VM. A faster VM can finish the same work sooner, if other settings stay the same.
A cloudlet is like a parcel job at a courier office: length = how much work it is (distance to deliver), fileSize = what you hand over at the counter, outputSize = the receipt you get back, and the utilisation model = how much of the van it fills (full or random).
Cloudlet c = new Cloudlet(id, length, pesNumber, fileSize, outputSize,
utilizationModelCpu, utilizationModelRam, utilizationModelBw);
| Parameter | Meaning |
|---|---|
id |
Unique cloudlet ID |
length |
Work to be done in Million Instructions (MI) |
pesNumber |
Number of PEs (Processing Elements) the cloudlet needs |
fileSize |
Input file size (bytes) transferred before execution |
outputSize |
Output file size after execution |
utilizationModelCpu/Ram/Bw |
Fraction of the resource used over time – UtilizationModelFull (100 %), UtilizationModelStochastic (random) |
Execution time (alone on a PE) = length / MIPS. A 250,000 MI cloudlet on a 1000 MIPS (Million Instructions Per Second) VM needs 250 000 ÷ 1000 = 250 s.
Cloudlet lifecycle
stateDiagram-v2
[*] --> CREATED
CREATED --> READY: submitted to broker
READY --> QUEUED: sent to VM (waiting – space-shared)
QUEUED --> INEXEC
READY --> INEXEC: starts executing
INEXEC --> SUCCESS: all MI processed
INEXEC --> FAILED
INEXEC --> CANCELED
SUCCESS --> [*]
Useful getters
| Method | Returns |
|---|---|
getCloudletId(), getVmId(), getResourceId() |
IDs of cloudlet, VM and data centre |
getCloudletStatus() / getCloudletStatusString() |
Status code / text |
getCloudletLength() |
Length in MI |
getExecStartTime(), getFinishTime() |
Start and finish clock times |
getActualCPUTime() |
finish − start |
getWaitingTime() |
Time spent queued |
getProcessingCost() |
Cost charged by the data centre |
Requirements
Use the CloudSim 3.0.3 project prepared in Practical 4, with its CloudSim and Commons Math library files on the classpath. Confirm that the first example runs before continuing.
Procedure
- In the project from Practical 4, create
CloudletExecution.javaand copy the program below. - Run it with Run As > Java Application. Read the Console output.
- Compare the IDs, task status and timing columns with the example output. Change one model setting, run again and explain the difference.
Program – CloudletExecution.java
package vlp.cloudsim;
import java.text.DecimalFormat;
import java.util.*;
import org.cloudbus.cloudsim.*;
import org.cloudbus.cloudsim.core.CloudSim;
import org.cloudbus.cloudsim.provisioners.*;
public class CloudletExecution {
public static void main(String[] args) {
Log.printLine("Starting CloudletExecution...");
try {
CloudSim.init(1, Calendar.getInstance(), false);
Datacenter dc = createDatacenter("Datacenter_0");
DatacenterBroker broker = new DatacenterBroker("Broker");
int brokerId = broker.getId();
List<Vm> vms = new ArrayList<Vm>();
vms.add(new Vm(0, brokerId, 1000, 1, 512, 1000, 10000, "Xen", new CloudletSchedulerSpaceShared()));
vms.add(new Vm(1, brokerId, 1000, 1, 512, 1000, 10000, "Xen", new CloudletSchedulerSpaceShared()));
broker.submitVmList(vms);
// Five cloudlets with different lengths and file sizes
long[] length = {100000, 250000, 150000, 400000, 50000};
long[] fileSize = {300, 500, 300, 1000, 100};
long[] outputSize = {300, 400, 200, 800, 100};
List<Cloudlet> cloudlets = new ArrayList<Cloudlet>();
UtilizationModel full = new UtilizationModelFull();
for (int i = 0; i < length.length; i++) {
Cloudlet c = new Cloudlet(i, length[i], 1, fileSize[i], outputSize[i], full, full, full);
c.setUserId(brokerId);
cloudlets.add(c);
}
broker.submitCloudletList(cloudlets);
CloudSim.startSimulation();
List<Cloudlet> done = broker.getCloudletReceivedList();
CloudSim.stopSimulation();
printCloudletList(done);
Log.printLine("CloudletExecution finished!");
} catch (Exception e) {
e.printStackTrace();
}
}
private static Datacenter createDatacenter(String name) throws Exception {
List<Pe> peList = new ArrayList<Pe>();
peList.add(new Pe(0, new PeProvisionerSimple(1000)));
peList.add(new Pe(1, new PeProvisionerSimple(1000)));
List<Host> hostList = new ArrayList<Host>();
hostList.add(new Host(0, new RamProvisionerSimple(2048), new BwProvisionerSimple(10000), 1000000, peList, new VmSchedulerSpaceShared(peList)));
DatacenterCharacteristics ch = new DatacenterCharacteristics("x86", "Linux", "Xen", hostList, 10.0, 3.0, 0.05, 0.001, 0.1);
return new Datacenter(name, ch, new VmAllocationPolicySimple(hostList), new LinkedList<Storage>(), 0);
}
private static void printCloudletList(List<Cloudlet> list) {
String indent = " ";
DecimalFormat dft = new DecimalFormat("###.##");
Log.printLine();
Log.printLine("========== OUTPUT ==========");
Log.printLine("ID" + indent + "STATUS" + indent + "DC" + indent + "VM" + indent + "Length" + indent + "Time" + indent + "Start" + indent + "Finish" + indent + "Cost");
for (Cloudlet c : list) {
Log.printLine(c.getCloudletId() + indent + c.getCloudletStatusString() + indent + c.getResourceId() + indent + c.getVmId()
+ indent + c.getCloudletLength() + indent + dft.format(c.getActualCPUTime())
+ indent + dft.format(c.getExecStartTime()) + indent + dft.format(c.getFinishTime())
+ indent + dft.format(c.getProcessingCost()));
}
}
}
Virtual lab · CloudSim · 20 min
Cloudlet creation and execution
Create cloudlets with defined length, file size and output size, execute them on VMs and read the execution report.
What the program does: it creates 2 space-shared VMs of 1000 MIPS and 5 cloudlets of different lengths (100 000 to 400 000 MI) with file and output sizes, submits them round-robin, runs the simulation and prints each cloudlet's status, times and processing cost.
Output
Example output for the settings in this lesson:
0.1: Broker: Sending cloudlet 0 to VM #0
0.1: Broker: Sending cloudlet 1 to VM #1
0.1: Broker: Sending cloudlet 2 to VM #0
0.1: Broker: Sending cloudlet 3 to VM #1
0.1: Broker: Sending cloudlet 4 to VM #0
100.1: Broker: Cloudlet 0 received
250.1: Broker: Cloudlet 1 received
250.1: Broker: Cloudlet 2 received
300.1: Broker: Cloudlet 4 received
650.1: Broker: Cloudlet 3 received
...
========== OUTPUT ==========
ID STATUS DC VM Length Time Start Finish Cost
0 SUCCESS 2 0 100000 100 0.1 100.1 360
1 SUCCESS 2 1 250000 250 0.1 250.1 840
2 SUCCESS 2 0 150000 150 100.1 250.1 500
4 SUCCESS 2 0 50000 50 250.1 300.1 170
3 SUCCESS 2 1 400000 400 250.1 650.1 1380
(Cost = CPU (Central Processing Unit) time × 3.0 + (file size + output size) × 0.1.)
Observations
- Cloudlets are assigned round-robin to VM 0 and VM 1.
- With space-shared VMs each cloudlet runs at the full 1000 MIPS, so CPU time = length / 1000.
- Later cloudlets on a VM start when the previous one finishes (for example cloudlet 2 starts at 100.1).
- Processing cost depends on CPU time and the data transferred.
Conclusion
Check the cloudlet status, VM ID, start time and finish time. Compare tasks with different lengths. Record any waiting time and the reported processing cost.
Viva questions
- What is a cloudlet? Explain the parameters of its constructor. A task that runs on a VM – id, length (MI), PEs, input file size, output size and three use models.
- What does length in MI represent? The amount of work in millions of instructions.
- What are use models? Name two. They say what fraction of CPU/RAM (Random Access Memory)/BW the task uses over time –
UtilizationModelFull,UtilizationModelStochastic. - List the states of a cloudlet. CREATED, READY, QUEUED, INEXEC, SUCCESS, FAILED, CANCELED (also PAUSED).
- How is the actual CPU time calculated? Finish time − execution start time.
- How is the processing cost of a cloudlet computed? CPU time × cost per second + data transferred × cost per MB of bandwidth (here 3.0 and 0.1).
Practise this topic
Hands-on virtual lab
Apply what you just read in a realistic, guided simulation. Free with a verified account.
Create a free account to track your progress and unlock virtual labs.