Practical 5: Create and Simulate a Cloud Data Center using CloudSim
Aim
Write a CloudSim program that creates a data centre and its physical hosts. Choose their CPU (Central Processing Unit), memory, storage and network settings. Run a simulation and check where the VMs (Virtual Machines) are placed.
Theory
A CloudSim Datacenter represents a cloud provider's resources. It contains hosts, which represent physical servers. Each host has processing elements, memory, storage and network capacity.
Build the model from smaller parts: processing elements first, then hosts, then the data centre. A VM allocation policy chooses a host for each VM.
First you buy CPU cores (Pe), put them into computers (Host), write down the lab's details and rent prices on a notice board (DatacenterCharacteristics), and finally open the lab itself (Datacenter) with a seating rule (VmAllocationPolicy) that decides which computer each new student (VM) sits at.
flowchart TB
PE1[Pe 0<br/>1000 MIPS] & PE2[Pe 1<br/>1000 MIPS] --> H1[Host 0<br/>RAM 4096 MB · BW 10000 · 1 TB]
PE3[Pe 0] & PE4[Pe 1] --> H2[Host 1]
H1 & H2 --> DC[DatacenterCharacteristics<br/>x86 · Linux · Xen · time zone · costs]
DC --> D[Datacenter 'Datacenter_0'<br/>+ VmAllocationPolicySimple]
| Class | Purpose | Key constructor arguments |
|---|---|---|
Pe |
One CPU core | id, PeProvisionerSimple(mips) |
Host |
Physical server | id, RamProvisionerSimple(ram), BwProvisionerSimple(bw), storage, PE (Processing Element) list, VmScheduler |
DatacenterCharacteristics |
Static properties & price | arch, os, vmm, host list, time zone, cost per sec, cost per MB memory, cost per MB storage, cost per MB bandwidth |
Datacenter |
The entity | name, characteristics, VmAllocationPolicy, storage list (SAN (Storage Area Network)), scheduling interval |
VmAllocationPolicySimple |
Places VMs on hosts | host list – picks the host with the most free PEs |
Capacity of a data centre = Σ hosts × PEs × MIPS (Million Instructions Per Second) (add up every core's speed). A cloudlet’s execution time on a dedicated PE = length (MI (Million Instructions)) ÷ MIPS.
Requirements
Eclipse project with CloudSim 3.0.3 and Commons Math on the build path (Practical 4).
Procedure
- In the project from Practical 4, create
DataCenterSimulation.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 – DataCenterSimulation.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 DataCenterSimulation {
public static void main(String[] args) {
Log.printLine("Starting DataCenterSimulation...");
try {
CloudSim.init(1, Calendar.getInstance(), false);
// Data centre with 3 hosts, each with 4 PEs of 1000 MIPS
Datacenter dc = createDatacenter("Datacenter_0", 3, 4, 1000);
DatacenterBroker broker = new DatacenterBroker("Broker");
int brokerId = broker.getId();
List<Vm> vms = new ArrayList<Vm>();
for (int i = 0; i < 3; i++) {
vms.add(new Vm(i, brokerId, 1000, 2, 1024, 1000, 10000, "Xen", new CloudletSchedulerTimeShared()));
}
broker.submitVmList(vms);
List<Cloudlet> cloudlets = new ArrayList<Cloudlet>();
UtilizationModel full = new UtilizationModelFull();
for (int i = 0; i < 6; i++) {
Cloudlet c = new Cloudlet(i, 200000, 1, 300, 300, 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("DataCenterSimulation finished!");
} catch (Exception e) {
e.printStackTrace();
}
}
/** Builds a data centre with the given number of hosts, PEs per host and MIPS per PE. */
private static Datacenter createDatacenter(String name, int hosts, int pesPerHost, int mips) {
List<Host> hostList = new ArrayList<Host>();
for (int h = 0; h < hosts; h++) {
List<Pe> peList = new ArrayList<Pe>();
for (int p = 0; p < pesPerHost; p++) {
peList.add(new Pe(p, new PeProvisionerSimple(mips)));
}
int ram = 4096; // MB
long storage = 1000000; // MB
int bw = 10000; // Mbps
hostList.add(new Host(h, new RamProvisionerSimple(ram), new BwProvisionerSimple(bw),
storage, peList, new VmSchedulerTimeShared(peList)));
}
String arch = "x86", os = "Linux", vmm = "Xen";
double timeZone = 5.5; // India
double costPerSec = 3.0; // per second of CPU
double costPerMem = 0.05; // per MB of RAM
double costPerStorage = 0.001; // per MB of storage
double costPerBw = 0.0; // per MB of bandwidth
DatacenterCharacteristics characteristics = new DatacenterCharacteristics(
arch, os, vmm, hostList, timeZone, costPerSec, costPerMem, costPerStorage, costPerBw);
Datacenter datacenter = null;
try {
datacenter = new Datacenter(name, characteristics,
new VmAllocationPolicySimple(hostList), new LinkedList<Storage>(), 0);
} catch (Exception e) {
e.printStackTrace();
}
return datacenter;
}
private static void printCloudletList(List<Cloudlet> list) {
String indent = " ";
DecimalFormat dft = new DecimalFormat("###.##");
Log.printLine();
Log.printLine("========== OUTPUT ==========");
Log.printLine("Cloudlet ID" + indent + "STATUS" + indent + "Data center ID" + indent + "VM ID" + indent + "Time" + indent + "Start Time" + indent + "Finish Time");
for (Cloudlet c : list) {
if (c.getCloudletStatus() == Cloudlet.SUCCESS) {
Log.printLine(indent + c.getCloudletId() + indent + indent + "SUCCESS" + indent + indent + c.getResourceId()
+ indent + indent + indent + c.getVmId() + indent + indent + dft.format(c.getActualCPUTime())
+ indent + indent + dft.format(c.getExecStartTime()) + indent + indent + dft.format(c.getFinishTime()));
}
}
}
}
Virtual lab · CloudSim · 25 min
Create and simulate a cloud data center
Model a data centre in code: hosts, processing elements (PEs), RAM, bandwidth, storage and pricing – then grow it and observe the effect.
What the program does:
- Starts CloudSim for 1 user.
- Calls
createDatacenter("Datacenter_0", 3, 4, 1000)– 3 hosts, each with 4 cores of 1000 MIPS, 4 GB RAM (Random Access Memory), 1 TB storage, 10 000 Mbps bandwidth, and prices (₹-style costs per second, per MB of RAM/storage/bandwidth) with time zone 5.5 (India). - Creates a broker.
- Creates 3 VMs – each 1000 MIPS, 2 cores, 1 GB RAM.
- Creates 6 cloudlets – each 200 000 MI using 1 core.
- Runs the simulation and prints the result table.
Output (key lines)
Example output for the settings in this lesson:
0.0: Broker: Cloud Resource List received with 1 resource(s)
0.0: Broker: Trying to Create VM #0 in Datacenter_0
0.0: Broker: Trying to Create VM #1 in Datacenter_0
0.0: Broker: Trying to Create VM #2 in Datacenter_0
0.1: Broker: VM #0 has been created in Datacenter #2, Host #0
0.1: Broker: VM #1 has been created in Datacenter #2, Host #1
0.1: Broker: VM #2 has been created in Datacenter #2, Host #2
0.1: Broker: Sending cloudlet 0 to VM #0
...
200.1: Broker: Cloudlet 0 received
...
========== OUTPUT ==========
Cloudlet ID STATUS Data center ID VM ID Time Start Time Finish Time
0 SUCCESS 2 0 200 0.1 200.1
1 SUCCESS 2 1 200 0.1 200.1
...
Observations
VmAllocationPolicySimplespreads the VMs over hosts 0, 1 and 2 because each new VM goes to the host with the most free PEs.- Each VM has 2 PEs and receives 2 cloudlets of one PE each, so every cloudlet gets a full 1000 MIPS and finishes in 200,000 / 1000 = 200 s.
- Total capacity = 3 hosts × 4 PEs × 1000 MIPS = 12,000 MIPS.
Conclusion
Check that the simulation creates the data centre and hosts with your chosen settings. Find the VM placement messages. Then check that the cloudlets, which represent tasks, finish on those VMs.
Viva questions
- Which classes are used to create a data centre in CloudSim?
Pe,Host,DatacenterCharacteristics,VmAllocationPolicySimpleandDatacenter(plus the provisioners). - What is a PE? What does MIPS mean? A Processing Element – one CPU core; MIPS = Million Instructions Per Second, its speed.
- What information does
DatacenterCharacteristicsstore? Architecture, OS (Operating System), VMM (Virtual Machine Monitor), host list, time zone and the costs per second, per MB of RAM, storage and bandwidth. - How does
VmAllocationPolicySimplechoose a host? It places the VM on the host with the most free PEs. - What is the role of
RamProvisionerSimpleandBwProvisionerSimple? They hand out a host's RAM and bandwidth to VMs and refuse when there is not enough left. - Calculate the total MIPS of a data centre with 5 hosts, each having 8 PEs of 2500 MIPS. 5 × 8 × 2500 = 100 000 MIPS.
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.