Cloudsim Tutorials

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:

int num_user = 1; // number of cloud users
Calendar calendar = Calendar.getInstance();
boolean trace_flag = false; 
CloudSim.init(num_user, calendar, trace_flag);
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;
}
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;
}
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);
broker.submitVmList(vmlist);
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);	
broker.submitCloudletList(cloudletList);
CloudSim.startSimulation();
CloudSim.stopSimulation();
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

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

Learn More

Also, To quickly get started with the Cloudsim Simulation Toolkit, Feel free to join our learners community for an online self-paced course named “Essential Cloudsim Tutorials” I would be interested in interacting with you. for further discussion. 

Reference link to study material:

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