Skip to content
VirtualLP Virtual Learning Platform

Practical 10: Simulation of Multiple Data Centers

13 min read Topic 19 of 31 1 hands-on lab

Aim

Create multiple data centres, each with its own hosts. Run the simulation and check where the broker creates VMs (Virtual Machines) and runs cloudlets.

Theory

CloudSim can model more than one data centre. Each one registers with the Cloud Information Service (CIS), a directory the broker uses to find data centres.

Each data centre has its own capacity. In this example, the broker tries another data centre when the first cannot accept more VMs.

mall directory

The CIS is the directory board at a mall entrance listing every shop. The broker reads the board, goes to the first shop, buys as much as that shop has in stock, and goes to the next shop for the rest – it does not compare prices unless you teach it to.

How the default broker uses several data centres

sequenceDiagram
    participant B as DatacenterBroker
    participant CIS as Cloud Information Service
    participant D0 as Datacenter_0 (#2)
    participant D1 as Datacenter_1 (#3)
    B->>CIS: Which data centres exist?
    CIS-->>B: [#2, #3]
    B->>D0: Create VM 0, 1, 2, 3
    D0-->>B: VM 0, 1 created · VM 2, 3 failed (no capacity)
    B->>D1: Create VM 2, 3
    D1-->>B: VM 2, 3 created
    B->>D0: Cloudlets for VM 0, 1
    B->>D1: Cloudlets for VM 2, 3
  1. The broker asks the CIS for the list of data centres.
  2. It requests all VMs in the first data centre.
  3. VMs that fail (not enough hosts/PEs (Processing Elements)/RAM (Random Access Memory)) are requested in the next data centre, and so on.
  4. Cloudlets are sent to whichever data centre hosts their VM; the result table shows the Data center ID of each cloudlet.

Each data centre can have its own characteristics – OS (Operating System), VMM (Virtual Machine Monitor), time zone and prices – so the same cloudlet may cost differently depending on where it runs.

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

  1. In the project from Practical 4, create MultiDatacenterSimulation.java and copy the program below.
  2. Run it with Run As > Java Application. Read the Console output.
  3. Compare the IDs, task status and timing columns with the example output. Change one model setting, run again and explain the difference.

Program – MultiDatacenterSimulation.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 MultiDatacenterSimulation {

    public static void main(String[] args) {
        Log.printLine("Starting MultiDatacenterSimulation...");
        try {
            CloudSim.init(1, Calendar.getInstance(), false);

            // Two independent data centres: small one in Mumbai, bigger one in Singapore
            Datacenter dcMumbai    = createDatacenter("Datacenter_0", 1, 5.5, 3.0);
            Datacenter dcSingapore = createDatacenter("Datacenter_1", 2, 8.0, 2.0);

            DatacenterBroker broker = new DatacenterBroker("Broker");
            int brokerId = broker.getId();

            List<Vm> vms = new ArrayList<Vm>();
            for (int i = 0; i < 4; i++) {
                vms.add(new Vm(i, brokerId, 1000, 1, 512, 1000, 10000, "Xen", new CloudletSchedulerTimeShared()));
            }
            broker.submitVmList(vms);

            List<Cloudlet> cloudlets = new ArrayList<Cloudlet>();
            UtilizationModel full = new UtilizationModelFull();
            for (int i = 0; i < 8; i++) {
                Cloudlet c = new Cloudlet(i, 100000, 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("MultiDatacenterSimulation finished!");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /** Each host has 2 PEs of 1000 MIPS and 2 GB RAM. */
    private static Datacenter createDatacenter(String name, int hosts, double timeZone, double costPerSec) throws Exception {
        List<Host> hostList = new ArrayList<Host>();
        for (int h = 0; h < hosts; h++) {
            List<Pe> peList = new ArrayList<Pe>();
            peList.add(new Pe(0, new PeProvisionerSimple(1000)));
            peList.add(new Pe(1, new PeProvisionerSimple(1000)));
            hostList.add(new Host(h, new RamProvisionerSimple(2048), new BwProvisionerSimple(10000), 1000000, peList, new VmSchedulerSpaceShared(peList)));
        }
        DatacenterCharacteristics ch = new DatacenterCharacteristics("x86", "Linux", "Xen", hostList, timeZone, costPerSec, 0.05, 0.001, 0.0);
        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("Cloudlet ID" + indent + "STATUS" + indent + "Data center ID" + indent + "VM ID" + indent + "Time" + indent + "Start Time" + indent + "Finish Time" + indent + "Cost");
        for (Cloudlet c : list) {
            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())
                    + indent + dft.format(c.getProcessingCost()));
        }
    }
}

Virtual lab · CloudSim · 25 min

Simulation of multiple data centers

Model two independent data centres; watch the broker try the first one, fail when it is full and create the remaining VMs in the second.

Open lab

What the program does: it creates two data centres – Datacenter_0 with one small host (2 PEs) and CPU (Central Processing Unit) price 3.0, and Datacenter_1 with two hosts and CPU price 2.0 – then asks for 4 single-PE VMs and 4 cloudlets, and prints where each VM and cloudlet ended up.

Output (key lines)

Example output for the settings in this lesson:

0.0: Broker: Cloud Resource List received with 2 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.0: Broker: Trying to Create VM #3 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 #0
0.1: Broker: Creation of VM #2 failed in Datacenter #2
0.1: Broker: Creation of VM #3 failed in Datacenter #2
0.1: Broker: Trying to Create VM #2 in Datacenter_1
0.1: Broker: Trying to Create VM #3 in Datacenter_1
0.2: Broker: VM #2 has been created in Datacenter #3, Host #0
0.2: Broker: VM #3 has been created in Datacenter #3, Host #1

The results table shows cloudlets on VMs 0–1 with Data center ID 2 and those on VMs 2–3 with Data center ID 3; cloudlets in Datacenter_1 cost less because its CPU price is 2.0 instead of 3.0.

Observations

  • Datacenter_0 has one host with 2 PEs, so it can host only 2 single-PE VMs; the broker creates the rest in Datacenter_1.
  • The broker always fills data centres in order – it does not pick the cheapest or nearest one (a custom broker is needed for that).
  • Each data centre keeps independent hosts, time zones and prices.

Conclusion

Find both data centres in the output. Record which VMs ran in each one. Explain why later VM requests moved to the second data centre and compare the task results and costs.

Viva questions

  1. How does the DatacenterBroker discover data centres? It asks the Cloud Information Service, where every data centre registers.
  2. In which order does the default broker try data centres? In the order of the list – the first one first, then the next for VMs that failed.
  3. Why did VM 2 fail in Datacenter_0? Its only host had 2 PEs, already used by VMs 0 and 1.
  4. Why are the data centre IDs 2 and 3? IDs 0 and 1 belong to CloudSim's internal entities (shutdown entity and CIS), which are created first.
  5. How would you make the broker prefer the cheapest data centre? Write a custom broker (extend DatacenterBroker) that sorts data centres by their characteristics' cost before creating VMs.
  6. What is a federated cloud? Several clouds/data centres, possibly from different providers, that cooperate and share load.

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.