Skip to content
VirtualLP Virtual Learning Platform

CloudSim: Simulator, Architecture and Working Platform

15 min read Topic 18 of 34 1 hands-on lab

Suppose you want to compare two ways of assigning jobs to servers. Buying many servers just for this test would cost money. A simulation lets you test a model first.

CloudSim is a Java library for modelling data centres, hosts, VMs (Virtual Machines) and tasks. You choose their settings, run the model and compare results. It does not start real cloud servers.

flight simulator

Pilots practise in a flight simulator before flying a real plane: it is cheap, safe, and you can repeat the same storm again and again. CloudSim is a flight simulator for clouds.

Introduction to simulation

Simulation

A simulation uses a model to study how a system behaves over time. You can test changes without changing the real system.

Why simulate a cloud?

Real cloud experiments Simulation
Expensive – you pay for every VM-hour Free – runs on a laptop
Hard to repeat – other customers, network noise Fully repeatable – same input, same result
Limited size – you can't rent 10,000 servers Model thousands of servers and VMs
Slow – real hours pass Hours of simulated time pass in milliseconds
Risky – can affect live systems No risk
You cannot change the provider's internal rules Change any rule (VM placement, scheduling, pricing)

Discrete-event simulation

CloudSim uses a discrete-event simulation. It keeps a time-ordered list of events, such as creating a VM or finishing a task. It takes the next event, moves the simulation clock to that time and sends the event to the correct object.

flowchart LR
    Q[(Future event queue<br/>sorted by time)] -->|next event| C[Advance clock] --> D[Deliver to entity<br/>Datacenter / Broker] --> N[Entity processes it<br/>and schedules new events] --> Q

What is CloudSim?

CloudSim

CloudSim is an open-source Java library for simulating clouds. You model data centres, hosts, VMs and tasks in code, then read the simulation results. The classic examples in these lessons use CloudSim 3.0.3.

Features

  • Models large data centres, physical servers (hosts), VMs and application tasks (cloudlets).
  • Supports VM placement (allocation) policies, VM schedulers and cloudlet schedulers (time-shared and space-shared).
  • Models federated clouds (several data centres) and brokers (agents acting for users).
  • Energy-aware simulation – power usage models, power-saving data centres and VM migration.
  • Network topology (BRITE) with delays between entities.
  • Cost models – prices for processing, memory, storage and bandwidth.
  • Easy to extend: you plug in your own policies by extending its classes.

CloudSim architecture

CloudSim separates cloud objects from the event-processing engine. Earlier versions used GridSim and SimJava. Later versions use CloudSim's own core engine. The layer diagram shows which part depends on which.

flowchart TB
    subgraph UC[User code]
        U1[Simulation specification:<br/>cloud scenarios, user requirements,<br/>application configuration]
        U2[Scheduling policy:<br/>User / Datacenter Broker]
    end
    subgraph CS[CloudSim]
        L1[User interface structures:<br/>Cloudlet · Virtual Machine]
        L2[VM services:<br/>Cloudlet execution · VM management]
        L3[Cloud services:<br/>VM provisioning · CPU · memory ·<br/>storage · bandwidth allocation]
        L4[Cloud resources:<br/>Events handling · Sensor ·<br/>Cloud coordinator · Data center]
        L5[Network:<br/>Network topology · Message delay calculation]
    end
    subgraph GS[GridSim]
        G1[Grid services, resources,<br/>network, traffic generation]
    end
    subgraph SJ[SimJava / CloudSim core simulation engine]
        S1[Discrete event simulation:<br/>entities, events, queues, clock]
    end
    UC --> CS --> GS --> SJ
Layer What it does
User code The top layer – your program. It defines the hosts, VMs, cloudlets, number of users, data centres and the broker's scheduling policy. Example: CloudSimExample1.
CloudSim layer Models the cloud parts: user interface structures (Cloudlet, Vm), VM services (running cloudlets, managing VMs), cloud services (creating VMs and sharing CPU (Central Processing Unit), memory, storage and bandwidth), cloud resources (data centres, event handling, sensors, cloud coordinator) and network (topology and delays).
GridSim layer Provides grid parts – resources, network and traffic generation – reused by early CloudSim.
SimJava (core simulation engine) The discrete-event engine: entities, event queue, clock and messages between entities. Replaced by org.cloudbus.cloudsim.core from CloudSim 2.0.
Frequently asked

“Explain the architecture of CloudSim with a neat diagram.” Draw the four layers (User code → CloudSim → GridSim → SimJava) and list the sub-parts of the CloudSim layer. Mention that newer versions replaced SimJava with their own core engine.

Core classes (the CloudSim object model)

classDiagram
    CloudSim ..> SimEntity : runs
    SimEntity <|-- Datacenter
    SimEntity <|-- DatacenterBroker
    SimEntity <|-- CloudInformationService
    Datacenter "1" --> "1" DatacenterCharacteristics
    Datacenter "1" --> "1" VmAllocationPolicy
    DatacenterCharacteristics "1" --> "*" Host
    Host "1" --> "*" Pe
    Host "1" --> "1" VmScheduler
    Host "1" --> "*" Vm
    Vm "1" --> "1" CloudletScheduler
    DatacenterBroker "1" --> "*" Vm
    DatacenterBroker "1" --> "*" Cloudlet
Class What it represents
CloudSim The simulation engine's front door – init(), startSimulation(), stopSimulation()
SimEntity, SimEvent The base class for things that act; the events they send each other
CloudInformationService (CIS) A directory where data centres register and brokers find them
Datacenter A data centre that contains hosts and handles VM and cloudlet requests
DatacenterCharacteristics The data centre's architecture, OS (Operating System), hypervisor, time zone and costs
Host One physical machine – its CPU cores (PEs), RAM (Random Access Memory), bandwidth, storage and VmScheduler
Pe Processing Element – one CPU core, with a speed in MIPS (million instructions per second)
Vm A virtual machine – MIPS, PEs, RAM, bandwidth, image size, hypervisor, CloudletScheduler
Cloudlet An application task – its length in MI (million instructions), PEs needed, input/output file sizes
DatacenterBroker Acts on behalf of the user: sends VMs and cloudlets, collects results
VmAllocationPolicy (…Simple) Decides which host gets a VM – "Simple" picks the host with the most free cores
VmScheduler (TimeShared/SpaceShared) Shares a host's cores among its VMs
CloudletScheduler (TimeShared/SpaceShared) Shares a VM's power among its cloudlets
Ram/Bw/PeProvisionerSimple Give RAM, bandwidth and MIPS to VMs
UtilizationModel (Full, Stochastic) How much of a resource a cloudlet uses over time

Time-shared vs space-shared scheduling

Space-shared Time-shared
Idea A core works on one task at a time until it finishes (first come, first served queue) All tasks run together, sharing the cores' power
Start time Later tasks wait in the queue All start immediately
Finish time Early tasks finish quickly and predictably All tasks move forward more slowly together
Everyday picture One ATM machine – people queue A teacher answering many students in turn, a little at a time

Run-time formula: a cloudlet of length L MI on a VM of M MIPS (alone) needs L / M seconds. Example: 400,000 MI ÷ 1,000 MIPS = 400 seconds.

The working platform – how a CloudSim program runs

Software needed

  • Java JDK (Java Development Kit) 8+ (JDK 17 also works with CloudSim 3.0.3 used as a library).
  • An IDE (Integrated Development Environment) – Eclipse or IntelliJ IDEA (or Maven / command line).
  • CloudSim 3.0.3 JAR (Java Archive) files (cloudsim-3.0.3.jar, the examples JAR) and Apache Commons Math 3.

The standard steps of every CloudSim program

Step Code
1. Start the CloudSim package CloudSim.init(numUsers, Calendar.getInstance(), traceFlag);
2. Create data centre(s) build Pe → Host → DatacenterCharacteristics → new Datacenter(...)
3. Create a broker DatacenterBroker broker = new DatacenterBroker("Broker");
4. Create VMs and send them new Vm(...); broker.submitVmList(vmList);
5. Create cloudlets and send them new Cloudlet(...); broker.submitCloudletList(cloudletList);
6. Run the simulation CloudSim.startSimulation();
7. Collect and print the results broker.getCloudletReceivedList(); then CloudSim.stopSimulation();
Remember this

Init → Datacenter → Broker → VMs → Cloudlets → Start → Results. "I Don't Buy Very Costly Sweets Regularly."

Typical output

Starting CloudSimExample1...
Initialising...
Starting CloudSim version 3.0
Datacenter_0 is starting...
Broker is starting...
Entities started.
0.0: Broker: Cloud Resource List received with 1 resource(s)
0.0: Broker: Trying to Create VM #0 in Datacenter_0
0.1: Broker: VM #0 has been created in Datacenter #2, Host #0
0.1: Broker: Sending cloudlet 0 to VM #0
400.1: Broker: Cloudlet 0 received
400.1: Broker: All Cloudlets executed. Finishing...
...
========== OUTPUT ==========
Cloudlet ID    STATUS    Data center ID    VM ID    Time    Start Time    Finish Time
    0        SUCCESS        2            0        400        0.1        400.1

How to read it: the VM was ready at 0.1 s, the cloudlet started then, ran for 400 s (400,000 MI on a 1,000 MIPS VM) and finished at 400.1 s.

Why "Datacenter #2"?

Entity IDs 0 and 1 are used internally (the shutdown entity and the Cloud Information Service), so the first data centre gets ID 2 and the broker gets the next ID.

Virtual lab · CloudSim · 20 min

Run and modify a CloudSim simulation

See the theory in action: run CloudSimExample1, change workload and capacity, and connect every log line to the CloudSim architecture.

Open lab

Applications of CloudSim

  • Testing VM placement and consolidation (packing VMs onto fewer servers) algorithms.
  • Task scheduling research (round robin, min-min, max-min, genetic algorithms).
  • Energy-saving data centre management.
  • Auto-scaling and load-balancing policies.
  • Cost and SLA (Service Level Agreement) analysis for brokers and federated clouds.
  • Teaching cloud concepts – trying scheduling and allocation ideas without real hardware.

Summary

  • Simulation lets us test cloud ideas cheaply, repeatably and at large scale; CloudSim is a discrete-event, Java-based cloud simulator from the University of Melbourne.
  • Architecture: User code → CloudSim (UI (User Interface) structures, VM services, cloud services, cloud resources, network) → GridSim → SimJava / core engine.
  • Key classes: Datacenter, Host, Pe, Vm, Cloudlet, DatacenterBroker, VmAllocationPolicy, VmScheduler, CloudletScheduler.
  • Every program: init → data centres → broker → VMs → cloudlets → start → results.

Practice questions

  1. What is simulation? Why is it needed for cloud computing research?
  2. What is CloudSim? List its features.
  3. Explain the layered architecture of CloudSim with a diagram.
  4. Explain the roles of Datacenter, Host, Pe, Vm, Cloudlet and DatacenterBroker.
  5. Differentiate time-shared and space-shared scheduling in CloudSim.
  6. Write the steps (with code fragments) of a basic CloudSim program.
  7. A cloudlet of 600,000 MI runs alone on a 1,500 MIPS VM created at 0.1 s. When does it finish?
Answer to Q7

Run time = 600,000 ÷ 1,500 = 400 s. It starts at 0.1 s, so it finishes at 400.1 s.

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.