Beginners Guide to Cloudsim Project Structure

The Cloudsim Simulation Toolkit is an API that is written using the Java programming language and its classes are structured in a very specific way. This article will serve as a guide to the Cloudsim project structure and will help you understand how the Cloudsim architecture is divided into different packages and their important classes that facilitate the cloud simulation using Cloudsim.

Let us first explore and understand the structure of this simulation project. I assume that you have already set up the cloudsim using Ecplise if not you may follow my previous article on “Cloudsim Setup using Eclipse“.

Let proceed further and your eclipse project explorer should contain 6 folders and 7 files.

Eclipse Project Explorer representing Cloudsim project structure
CloudSim Project Structure

The readme.txt file contains the necessary information about this project, like how to install and run the cloudsim, what is the basic directory structure, if you are not using any IDE then how to build the project source code.

Cloudsim Readme.txt file content
Readme.txt file

Now, let us look at the directory structure in detail and understand the various namespaces available in the “Source” folder

Source Folder namespace/packages
Cloudsim Source folder namespace/package view

There exist 12 namespaces; each namespace has a set of classes with specific correlated functions as discussed below:

  • Org.cloudbus.cloudsim: It contains the model classes of various basic hardware components, their groups, and the allocation/utilization methods, etc. Here, the model means that the classes contain the implementation of the various attributes and behaviors of the real-life cloud computing hardware component as a collection of Java methods. Once these classes initiate during the simulation, they are going to simulate the behavior of the real-life cloud-based system component.
List of org.cloudbus.cloudsim classes
  • Org.cloudbus.cloudsim.core: This namespace contains the implementation of the simulation engine where the cloudsim.java class is the main class and is responsible for the start and stop of the simulation process. Similarly, the simentity.java class is for maintaining the state of the simulated cloud components. Simevent.java, futurequeue.java, and defferedqueue.java are responsible for maintaining the inter-entity(cloud component) related event call during the simulation process.
Class list of org.cloudbus.cloudsim.core
  • Org.cloudbus.cloudsim.core.predicates: contains the classes related to the selection of events from the defferedqueue.java to be processed during the simulation event processing.
Class List of Org.cloudbus.cloudsim.core.predicates
  • Org.cloudbus.cloudsim.distribution: It contains the implementation of the various distribution function but is not used anywhere in the cloudsim. These classes might be for future purposes.
Class list of Org.cloudbus.cloudsim.distribution
  • Org.cloudbus.cloudsim.lists: It contains the implementation of lists to be used globally during the simulation process. These are the specialized set of classes, where sorting and comparison operation implemented. There exist the list class for the host, processing element, cloudlet, virtual machine, and resources.
Class list of Org.cloudbus.cloudsim.lists
  • Org.cloudbus.cloudsim.network: it contains the implementation for the network related simulations purpose, and if you are working on a research work based on network optimization techniques then this is the best set of classes to extend for simulation.
Class list of Org.cloudbus.cloudsim.Network
  • Org.cloudbus.cloudsim.network.datacenter: This namespace contains the extended implementation of the basic cloud hardware components which can support the simulation of federated cloud functions distributed across the regions.
Class list of Org.cloudbus.cloudsim.Network.datacenter
  • Org.cloudbus.cloudsim.power: This package contains the extended implementation of cloud components, which can simulate the green or power-aware computing scenarios. This namespace implements the VM migration related classes where extensive algorithm codes for virtual machine selection and allocation related to migrations are available.
Class list of Org.cloudbus.cloudsim.power
  • Org.cloudbus.cloudsim.power.lists: This namespace contains only the implementation of powervmlist.java, which is an extended version of the VmList.java class of org.cloudbus.cloudsim.list namespace.
Class list of Org.cloudbus.cloudsim.power.lists
  • Org.cloudbus.cloudsim.power.models: It contains the set of classes that specifies the power configurations of servers as model classes. These classes imitate the actual working of the various server machine brands available in the market and help in determining the power consumption by such machines during the simulation process.
Class list of Org.cloudbus.cloudsim.power.models
  • Org.cloudbus.cloudsim.provisioners: This namespace contains the behavior implementation regarding how the specified cloud component provisioned to requesting virtual resources.
Class list of Org.cloudbus.cloudsim.provisioners
  • Org.cloudbus.cloudsim.util: this namespace contains the implementation of essential calculation functions and a general utility set.
Class list of Org.cloudbus.cloudsim.utils

Now let’s look at the “examples” folder. It contains 7 namespaces, and each namespace contains a particular type of scenario implementations.

Class list of Org.cloudbus.cloudsim.examples and relevant namespaces

Examples.txt gives you an overview of various basic example scenarios that are available in this folder. The file contains the instructions for the compile and execution of example classes.

Workload.planetlab: It contains a real dataset containing a set of CPU utilization traces from PlanetLab VMs collected during the 10 random days in March & April of 2011. The PlanetLab dataset is used as a benchmark dataset for the validation of various research scenarios.

Now let’s move to the other folders:

  • JRE system library: It is automatically created during the first build process of the CloudSim by the eclipse.
cloudsim project JRE automated compiled dependencies.
  • Reference Libraries: It contains the various dependency jars again automatically added by the eclipse during the first build process.
cloudsim reference libraries
  • Docs: Contains the minimalist documentation of the cloudsim class API and is automatically generated from the inline comments.
cloudsim documentation
  • Jars: This folder is supplied with the source zip file and contains the pre-compiled build of the cloudsim 3.0.3. It can be used for creating custom project scenarios whenever required. We will work on this in further blog posts.
cloudsim bundled jar provided with source code.
  • Build.xml is an ANT based XML file used during the console based builds.
  • Changelog.txt contains the history of the changes done to cloudsim during various version releases.
  • License.xml contans GNU-GPL notification.
  • Pom.xml is a maven configuration file used during the setup of cloudsim using eclipse.
  • Releasenotes.txt contains the note from the cloudsim development team.

You may also follow the detailed step by step demo to “Cloudsim Tutorial: Introduction to Package Intro (Part 2)

Learn More

You may subscribe to an online self-paced course named Learn Basics of Cloudsim, The content for this course which will be updated weekly till August 2021.

How to do Virtual machine and Task Scheduling in CloudSim

This article will help you understand the class hierarchies available in Cloudsim for Virtual Machine and Cloudlet Scheduling. This blog post is supported with a video lecture provided at the end, to have a better understanding of the implementation. Let’s start with the basic terms.

Basics of Scheduling

In computers, Scheduling is a process of arranging the submitted jobs/task into a very specific sequence of execution. It is an essential characteristic of any software operating environment, which is handled by a very special program known as a scheduler.

Scheduler’s main objective is to keep the underlined hardware resources(primarily processor) to be used effectively as well as efficient. In general, the scheduler may prefer to have any of the following scheduling approaches:

  • Space-shared: In this, the requested resources are allocated dedicatedly to the requesting workload for execution and will be released only on completion. Space-shared is also known as a batch process scheduling.
  • Time-shared: In this, the requested resources would be shared among more than one workload(task). The sharing is done based on time-sliced allocation where each workload is allocated with a required resource for a defined time(e.g., 200 milliseconds). Once the defined time slice is over, the current workload execution paused, and the resource is released. The released resource gets allocated to the next workload for the same defined time slice, and this cycle goes on till the time all the workloads execution is over. Time-shared is also known as round-robin scheduling.

Scheduling in Cloud

As cloud computing is the virtualized operating environment, and the virtual machines are the primary computing component which is responsible for the execution of the workloads(tasks). The virtual machine(s) are powered by a physical server host machine (i.e.) hardware. Depending on the requirement of the Virtual Machine(VM) there could be ‘one to one’ or ‘many to one’ mapping between the VM and host machine. That means in cloud computing the scheduling is done at both the mapping levels that are:

  • Virtual Machine to Host Machines
  • Tasks to Virtual Machines

Both of VM to Host as well as Workload(task) to VM mappings may utilize space-share or time-shared or any other specialized scheduling algorithm.

Scheduling in Cloudsim

The Cloudsim simulation toolkit framework has effectively addressed the Scheduling scenario and implemented it as a set of the programmable class hierarchies with parent class as:

  1. VmScheduler
  2. CloudletScheduler

Also, Virtual Machine(VM) and Task( Cloudlet) scheduling are one of the most important and the popular use case to be simulated by researchers using the CloudSim simulation toolkit.

Note: In cloudsim, the task is called as cloudlet, therefore in the following text instead of ‘task’ we will be using the ‘cloudlet’.

Cloudsim Virtual Machine Scheduling

The VmScheduler is an abstract class that defines and implements the policy used to share processing power among virtual machines running on a specified host. The hierarchy of the cloudsim virtual machine scheduler classes is as:

VmScheduler Class Hierarchy for virtual machine scheduling in cloudsim
Cloudsim Virtual Machine Scheduler Class Hierarchy

These classes can be located in “org.cloudbus.cloudsim” package of cloudsim. The definition of this abstract class is extended to the following types of policies implemented as classes:

  • VmSchedulerTimeShared: This class implements the VM scheduling policy that allocates one or more processing elements to a single Virtual machine and allows the sharing of processing elements by multiple virtual machines with a specified time slice. This class also considers the overhead of VM allocation switching(similar to context switching) in policy definition. Here, the VM allocation will fail if the number of processing elements requested is not available. for example, if the VM request for quad-core processor whereas the allocated host has an only dual-core the allocation will fail.
  • VmSchedulerSpaceShared: This class implements the VM scheduling policy that allocates one or more processing elements to a single virtual machine, but this policy implementation does not support sharing of processing elements (i.e.) all the requested resources will be used by the allocated VM till the time the VM is not destroyed. Also, Under this allocation policy, if any virtual machine requests a processing element and is not available at that time, the allocation fails.
  • VmSchedulerTimeSharedOverSubscription: This is an extended implementation of VMSchedulerTimeShared VM scheduling policy, which allows over-subscription of processing elements by the virtual machine(s) (i.e.) the scheduler still allows the allocation of VMs that require more CPU capacity that is available. And this oversubscription results in performance degradation.

The application of the VmScheduler classes is while instantiating the host model. Following is the code snippet used in CloudsimExample1.java from line number 160 to 174:

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)
	)
); // This is our machine

This is where the processing element list is passed as a parameter to the VmSchedulerTimeShared() class call and during the simulation, the cloudsim will simulate the timeshare behavior for the virtual machines. Also, in case you want to test other VmScheduler you may replace it with VmSchedulerTimeShared() call with appropriate parameters, this includes your own designed custom virtual machine scheduler.

Cloudsim Cloudlet Scheduling

The “CloudletScheduleris an abstract class that defines the basic skeleton to implement the policy to be used for cloudlet scheduling to be performed by a virtual machine. The hierarchy of the cloudsim Cloudlet scheduler classes is as:

Cloudlet Scheduler Class Hierarchy for Task Scheduling in cloudsim
Cloudlet Scheduler Class Hierarchy

These classes again exist in “org.cloudbus.cloudsim” package of cloudsim. The definition of this abstract class is extended as the following types of policies implemented as three individual classes in cloudsim:

  • CloudletSchedulerSpaceShared: This class implements a policy of scheduling for Virtual machine to execute cloudlet(s) in space shared environment (i.e.) only one cloudlet will be executed on a virtual machine at a time. It means cloudlets share the same queue and requests are processed one at a time per computing core. Space-sharing is similar to batch processing.
  • CloudletSchedulerTimeShared: This class implements a policy of cloudlet scheduling for Virtual machines to execute cloudlets in a time-shared environment (i.e.) more than one cloudlet will be submitted to the virtual machine and each will get its specified share of time. It means several requests (cloudlets) are processed at once but they must share the computing power of that virtual machine(by simulating context switching), so they will affect each other’s processing time. It basically influences the completion time of a cloudlet in CloudSim. Time-sharing is probably referring to the concept of sharing executing power (such as CPU, logical processor, GPU) and is commonly known as the round-robin scheduling.
  • CloudletSchedulerDynamicWorkload: This implements a special policy of scheduling for virtual machine assuming that there is just one cloudlet which is working as an online service with a different requirement of workload as per the need of peak/offpeak user load at a specified period of time.

The application of the CloudletScheduler classes is while instantiating the Vm model. Following is the code snippet used in CloudsimExample1.java from line number 82 to 91:

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

Vm vm = new Vm(vmid, brokerId, mips, pesNumber, ram, bw, size, vmm, new CloudletSchedulerTimeShared()); // create VM

By instantiating the CloudletSchedulerTimeShared() class, the Virtual machine is decided to follow the timeshare(round-robin) approach while simulation for scheduling & executing the Cloudlets. Also, in case you want to test other CloudletScheduler you may replace it with CloudletSchedulerTimeShared() call with appropriate parameters, this includes your own designed custom cloudlet scheduler.

Now in case you want to implement your own scheduling policies with respect to Virtual Machine or Cloudlet(s), you may simply extend the VmScheduler or CloudletScheduler class to implement all the abstract methods as specified. This gives you the flexibility to design and implement your own set of algorithms and then later test & optimize during the repetitive simulation runs.

Learn More

In case you missed reading our popular article on Detailed introduction to Cloudsim you may follow CloudSim Simulation Toolkit: An Introduction.

You may subscribe to an online self-paced course named Learn Basics of Cloudsim, The content for this course which will be updated weekly till August 2021.