Guide to CloudsimExample1.java simulation workflow

Any Example provided in the ‘org.cloudbus.cloudsim.example’ Package under the example folder of the CloudSim project follows some standard steps to implement the specified configuration to start a simulation. To understand the working of the CloudSim simulation framework, knowledge about these steps is a must. This article will help you to get an understanding of CloudsimExample1.java simulation workflow.

Before you start, It is essential that the cloudsim should already installed/setup on your local computer machine. In case you are yet to install it, you may follow the process of Cloudsim setup using Eclipse IDE

The main() method is the pointer from where the execution of this example starts

public static void main(String[] args)

There are eleven steps that are followed in each example with some variation in them, specified as follows:

  • Set the Number of users for the current simulation. This user count is directly proportional to a number of brokers in the current simulation.
int num_user = 1; // number of cloud users
Calendar calendar = Calendar.getInstance();
boolean trace_flag = false; 
  • Initialize the simulation, provided with the current time, number of users and trace flag.
CloudSim.init(num_user, calendar, trace_flag);
  • Create a Datacenter.
Datacenter datacenter0 = createDatacenter("Datacenter_0");

where the createDatacenter() method itself initializes the various datacenter characteristics along with the host list. This is the most important entity without this there is no way the simulation of hosting the virtual machine is applicable.

private static Datacenter createDatacenter(String name) 
{
	List<Host> hostList = new ArrayList<Host>();
	List<Pe> peList = new ArrayList<Pe>();
	int mips = 1000;
	peList.add(new Pe(0, new PeProvisionerSimple(mips))); 
	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)
              		)
		); 
	String arch = "x86"; 
	String os = "Linux"; 
	String vmm = "Xen";
	double time_zone = 10.0; 
	double cost = 3.0; 
	double costPerMem = 0.05; 
	double costPerStorage = 0.001; 	
        double costPerBw = 0.0; 
	LinkedList<Storage> storageList = new LinkedList<Storage>();
	DatacenterCharacteristics characteristics = new 
                    DatacenterCharacteristics(arch, os, vmm, hostList, 
                                              time_zone, cost, costPerMem,
                 				costPerStorage, costPerBw);
	Datacenter datacenter = null;
	try {
		datacenter = new Datacenter(name, characteristics, new 
                                VmAllocationPolicySimple(hostList), 
                                  storageList, 0);
	} catch (Exception e) {
		e.printStackTrace();
         	}
	return datacenter;
}
  • Create a Datacenter broker.
DatacenterBroker broker = createBroker();
int brokerId = broker.getId();

Where the createBroker() method initializes the entity object from DatacenterBroker class

private static DatacenterBroker createBroker() 
{
	DatacenterBroker broker = null;
	try {
		broker = new DatacenterBroker("Broker");
	} catch (Exception e) {
		e.printStackTrace();
		return null;
	}
	return broker;
}
  • Create a Virtual Machine(s).
vmlist = new ArrayList<Vm>();
int vmid = 0;
int mips = 1000;
long size = 10000;
int ram = 512;
long bw = 1000;
int pesNumber = 1;
String vmm = "Xen";

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

vmlist.add(vm);
  • Submit Virtual Machine to Datacenter broker.
broker.submitVmList(vmlist);
  • Create Cloudlet(s) by specifying their characteristics.
cloudletList = new ArrayList<Cloudlet>();

int id = 0;
long length = 400000;
long fileSize = 300;
long outputSize = 300;
UtilizationModel utilizationModel = new UtilizationModelFull();

Cloudlet cloudlet = new Cloudlet(id, length, pesNumber, fileSize, 
                     outputSize, utilizationModel, utilizationModel, 
                      utilizationModel);

cloudlet.setUserId(brokerId);
cloudlet.setVmId(vmid);

cloudletList.add(cloudlet);	
  • Submit Cloudlets to Datacenter broker.
broker.submitCloudletList(cloudletList);
  • Send call to Start Simulation.
CloudSim.startSimulation();
  • Once no more event to execute, send the call to Stop Simulation.
CloudSim.stopSimulation();
  • Finally, print the final status of the Simulation.
List<Cloudlet> newList = broker.getCloudletReceivedList();
printCloudletList(newList);

Where printCloudletList() method formats the output to correctly display it on the console.

private static void printCloudletList(List<Cloudlet> list) 
{
	int size = list.size();
	Cloudlet cloudlet;
	String indent = "    ";
	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");

	DecimalFormat dft = new DecimalFormat("###.##");
	for (int i = 0; i < size; i++) 
        {
        	cloudlet = list.get(i);
		Log.print(indent + cloudlet.getCloudletId() + indent + 
                          indent);
		if (cloudlet.getCloudletStatus() == Cloudlet.SUCCESS) 
                {
			Log.print("SUCCESS");
			Log.printLine(indent + indent + 
                                     cloudlet.getResourceId()
				     + indent + indent + indent + 
                                     cloudlet.getVmId()
				     + indent + indent + 
                                     dft.format(cloudlet.getActualCPUTime()) 
                                     + indent + indent + 
                                     dft.format(cloudlet.getExecStartTime())
				     + indent + indent + 
                                     dft.format(cloudlet.getFinishTime()));
		}
	}
}

Once you Run the example the output for cloudsimExample1.java will be displayed like:

CloudsimExample1.java console output
CloudsimExample1.java console output

Also, the following video tutorial contains a detailed about cloudsimexample1.java and helps you to understand CloudsimExample1.java simulation workflow

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. Click here to get the applicable discount coupon codes.

Reference link to study material:

  1. http://www.buyya.com/papers/CloudSim2010.pdf.
  2. http://www.cloudbus.org/papers/CloudSim-HPCS2009.pdf.

Leave a Reply

Your email address will not be published. Required fields are marked *