You are on page 1of 19

CloudSim

200948Gridbus
CloudSimSimJava
WindowsLinuxCloudSimGridSim

Cloud-Bursts
CloudSim GridSim

CloudSim

CloudSim CloudSim
CISCloud Information Service DataCenterBroker
DataCenterBroker

1CloudSim
(1)Cloudlet
(2)DataCenter
VMProvisioner
(3)DataCenterBroker

(4)Host (PE)
Host
(5)VirtualMachine Host
VMScheduler

(6)VMScheduler

(7)VMCharacteristics
(8)VMMAllocationPolicy Host

(9)VMProvisioner

2CloudSim
(1)JDK
http://www.oracle.com/technetwork/java/javase/downloads/index.html JDK
jdk1.7.0_02CloudSim JDK1.6 JDK
Path C:/Program Files/Java/jdk1.7.0_02/bin;
ClassPath C:/Program Files/Java/jdk1.7.0_02/lib/dt.jar;
C:/Program Files/Java/jdk1.7.0_02/lib/tools.jar;
(2)CloudSim
http://code.google.com/p/cloudsim/downloads/list CloudSim 3.0
(3.0.1,3.0.2) Zip tar.gz

(3) Eclipse Cloudsim


1.Eclipse->File->new->java project->
2.project name :cloudsim
3. create project from exiting source, cloudsim

4.
(4) Netbeans Cloudsim 6

3CloudSim
CloudSim windows Xp linux
CloudSim

http://ant.apache.org/ Ant D:/apache-ant-1.8.3


PATH D:/apache-ant-1.8.3/bin;
CloudSim build.xml D:/CloudSim>ant
CloudSim build.xml
D:/CloudSim>ant makejar
new_cloudsim.jar CloudSim
ClassPath
D:/CloudSim/jars/new_cloudsim.jar;D:/CloudSim/jars/cloudsim.jar;D:/CloudSim/jars/
g-ridsim.jar; D:/CloudSim/jars/simjava2.jar;

4 CloudSim
(1) CloudSim
CloudSim.init(num_user, calendar, trace_flag);
(2) CloudSim

Machine Machine PEs CPUs


Datacenter datacenter0 = createDatacenter("Datacenter_0");
(3) Broker
DatacenterBroker broker = createBroker();
int brokerId = broker.getId();
(4)
vmlist = new ArrayList<Vm>();
//VM
int vmid = 0;
int mips = 250;
long size = 10000;
int ram = 512;
long bw = 1000;
int pesNumber = 1;
String vmm = "Xen";
// Broker
Vm vm1 = new Vm(vmid, brokerId, mips, pesNumber, ram, bw, size,
vmm, new CloudletSchedulerTimeShared());
//

vmlist.add(vm1);
// Broker
broker.submitVmList(vmlist);
(5)

cloudletList = new ArrayList<Cloudlet>();


// ID,BrokerID
//Cloudlet
int id = 0;
pesNumber=1;
long length = 250000;
long fileSize = 300;
long outputSize = 300;

new
UtilizationModel utilizationModel =new
UtilizationModelFull();
Cloudlet cloudlet1 = new Cloudlet(id, length, pesNumber,
fileSize, outputSize, utilizationModel, utilizationModel,
utilizationModel);
cloudlet1.setUserId(brokerId);

//
cloudletList.add(cloudlet1);

//Broker
broker.submitCloudletList(cloudletList);
(6)
CloudSim.startSimulation();
(7)
List<Cloudlet> newList = broker.getCloudletReceivedList();
CloudSim.stopSimulation();
printCloudletList(newList);
datacenter0.printDebts();

5
DatacenterBroker
,
Cloudsim MI
MIPS T=MI / MIPS
MI MIPS
a

1
DatacenterBroker bindCloudletsToVmsSimple()

2
DatacenterBroker bindCloudletsToVmsTimeAwared()
time[i][j] i j
time MI MIPS

DatacenterBroker bindCloudletToVm(int cloudletId, int vmId)

public void bindCloudletsToVmsSimple(){


int vmNum = vmList.size();
int cloudletNum = cloudletList.size();
int idx = 0;
for
int i=0;i<cloudletNum;i++){
for(int
cloudletList.get(i).setVmId(vmList.get(idx).getId());
idx = (idx+1)%vmNum;
}
}

public void bindCloudletsToVmsTimeAwared(){


int cloudletNum=cloudletList.size();
int vmNum=vmList.size();
//time[i][j] ij
new double
double
double[][] time=new
double[cloudletNum][vmNum];

//cloudletListMI, vmMIPS
new CloudletComparator());
Collections.sort(cloudletList,new
new VmComparator());
Collections.sort(vmList,new

//////////For test//////////////////////////////////
System.out.println("///////////For

test///////////////");

int i=0;i<cloudletNum;i++){
for
for(int

System.out.print(cloudletList.get(i).getCloudletId()+":"+cloudletList.get
(i).getCloudletLength()+" ");
}
System.out.println();
int i=0;i<vmNum;i++){
for
for(int

System.out.print(vmList.get(i).getId()+":"+vmList.get(i).getMips()+" ");
}
System.out.println();
System.out.println("//////////////////////////////////");

//////////////////////////////////////////////////////////////////////

for
int i=0;i<cloudletNum;i++){
for(int
int j=0;j<vmNum;j++){
for
for(int
time[i][j]=

double
(double
double)cloudletList.get(i).getCloudletLength()/vmList.get(j).getMips();

System.out.print("time["+i+"]["+j+"]="+time[i][j]+"
//For test
}
System.out.println();

//For test

double
new double
double[] vmLoad=new
double[vmNum];//
new int
int
int[] vmTasks=new
int[vmNum]; //Vm
double minLoad=0;//
int idx=0;//

//cloudletvm
vmLoad[vmNum-1]=time[0][vmNum-1];
vmTasks[vmNum-1]=1;
cloudletList.get(0).setVmId(vmList.get(vmNum-1).getId());

int i=1;i<cloudletNum;i++){
for
for(int
minLoad=vmLoad[vmNum-1]+time[i][vmNum-1];
idx=vmNum-1;
int j=vmNum-2;j>=0;j--){
for
for(int
//
if
if(vmLoad[j]==0){
if
if(minLoad>=time[i][j])idx=j;

");

break
break;
}

if
if(minLoad>vmLoad[j]+time[i][j]){
minLoad=vmLoad[j]+time[i][j];
idx=j;
}
//
else
if
if(minLoad==vmLoad[j]+time[i][j]&&vmTasks[j]<vmTasks[idx])
idx=j;
}
vmLoad[idx]+=time[i][idx];
vmTasks[idx]++;
cloudletList.get(i).setVmId(vmList.get(idx).getId());
System.out.print(i+"th

"+"vmLoad["+idx+"]="+vmLoad[idx]+"

minLoad="+minLoad);
System.out.println();
}
}

//CloudletMI
private class CloudletComparator implements Comparator<Cloudlet>{
public int compare(Cloudlet cl1,Cloudlet cl2){
int
return (int
int)(cl2.getCloudletLength()-cl1.getCloudletLength());
}
}

//VmMIPS
private class VmComparator implements Comparator<Vm>{
public int compare(Vm vm1,Vm vm2){
int
return (int
int)(vm1.getMips()-vm2.getMips());
}
}
/////////////////////////////////////////////////////////////////////////

t
org.cloudbus.cloudsim.examples MyAllocationTes
MyAllocationTest

package org.cloudbus.cloudsim.examples;
import java.text.DecimalFormat;

import
import
import
import

java.util.ArrayList;
java.util.Calendar;
java.util.LinkedList;
java.util.List;

import
import
import
import
import
import
import
import
import
import
import
import
import
import
import
import
import
import
import

org.cloudbus.cloudsim.Cloudlet;
org.cloudbus.cloudsim.CloudletSchedulerSpaceShared;
org.cloudbus.cloudsim.CloudletSchedulerTimeShared;
org.cloudbus.cloudsim.Datacenter;
org.cloudbus.cloudsim.DatacenterBroker;
org.cloudbus.cloudsim.DatacenterCharacteristics;
org.cloudbus.cloudsim.Host;
org.cloudbus.cloudsim.Log;
org.cloudbus.cloudsim.Pe;
org.cloudbus.cloudsim.Storage;
org.cloudbus.cloudsim.UtilizationModel;
org.cloudbus.cloudsim.UtilizationModelFull;
org.cloudbus.cloudsim.Vm;
org.cloudbus.cloudsim.VmAllocationPolicySimple;
org.cloudbus.cloudsim.VmSchedulerTimeShared;
org.cloudbus.cloudsim.core.CloudSim;
org.cloudbus.cloudsim.provisioners.BwProvisionerSimple;
org.cloudbus.cloudsim.provisioners.PeProvisionerSimple;
org.cloudbus.cloudsim.provisioners.RamProvisionerSimple;

public class MyAllocationTest {


/** The cloudlet list. */
private static List<Cloudlet> cloudletList;
private static int cloudletNum = 10;
/** The vmlist. */
private static List<Vm> vmlist;
private static int vmNum = 5;
/**
* Creates main() to run this example
*/
public static void main(String[] args) {
Log.printLine("Starting TestAllocation...");
try {
// First step: Initialize the CloudSim package. It should
be called

// before creating any entities.


int num_user = 1; // number of cloud users
Calendar calendar = Calendar.getInstance();
boolean trace_flag = false
false; // mean trace events
// Initialize the CloudSim library
CloudSim.init(num_user, calendar, trace_flag);
// Second step: Create Datacenters
//Datacenters are the resource providers in CloudSim.
We need at list one of them to run a CloudSim simulation
Datacenter
datacenter0
=
createDatacenter("Datacenter_0");
//Datacenter
createDatacenter("Datacenter_1");

datacenter1

//Third step: Create Broker


DatacenterBroker broker = createBroker();
int brokerId = broker.getId();
//VM description
int vmid = 0;
int
int[] mipss = new int
int[]{278,289,132,209,286};
long size = 10000;
int ram = 256;
long bw = 1000;
int pesNumber = 1;
String vmm = "Xen";
//Fourth step: Create one virtual machine
vmlist = new ArrayList<Vm>();
int i=0;i<vmNum;i++){
for
for(int
new
vmlist.add(new
new
Vm(vmid,brokerId,mipss[i],pesNumber,ram,bw,size,vmm,new
CloudletSchedulerSpaceShared()));
vmid++;
}
//submit vm list to the broker
broker.submitVmList(vmlist);
//Cloudlet properties
int id = 0;

long
long[]
lengths
=
long
long[]{19365,49809,32018,44157,16754,
18336,20045,31493,30727,31017};
long fileSize = 300;
long outputSize = 300;
UtilizationModel
utilizationModel
UtilizationModelFull();

new

//Fifth step: Create two Cloudlets


cloudletList = new ArrayList<Cloudlet>();
int i = 0;i < cloudletNum;i++){
for
for(int
Cloudlet
cloudlet
=
Cloudlet(id,lengths[i],pesNumber,fileSize,

new

new

outputSize,utilizationModel,utilizationModel,utilizationModel)
;
//add the cloudlets to the list
cloudlet.setUserId(brokerId);
cloudletList.add(cloudlet);
id++;
}
//submit cloudlet list to the broker
broker.submitCloudletList(cloudletList);

//bind the cloudlets to the vms. This way, the broker


// will submit the bound cloudlets only to the
specific VM
//broker.bindCloudletsToVmsSimple();
broker.bindCloudletsToVmsTimeAwared();
// Sixth step: Starts the simulation
CloudSim.startSimulation();
// Final step: Print results when simulation is over
List<Cloudlet>
newList
=
broker.getCloudletReceivedList();
CloudSim.stopSimulation();

printCloudletList(newList);
//Print the debt of each user to each datacenter

datacenter0.printDebts();
Log.printLine("TestAllocation finished!");
}
catch (Exception e) {
e.printStackTrace();
Log.printLine("Unwanted errors happen");
}
}
private static Datacenter createDatacenter(String name){
// Here are the steps needed to create a PowerDatacenter:
// 1. We need to create a list to store
//
our machine
List<Host> hostList = new ArrayList<Host>();
// PE and its properties
int mips = 1000;
int hostId=0;
int ram = 2048; //host memory (MB)
long storage = 1000000; //host storage
int bw = 10000;
// 2. A Machine contains one or more PEs or CPUs/Cores.
List<Pe> peList = new ArrayList<Pe>();
// 3. Create PEs and add these into a list.
new Pe(0, new PeProvisionerSimple(mips))); //
peList.add(new
need to store Pe id and MIPS Rating
//4. Create Host with its id and list of PEs and add them
to the list of machines

hostList.add(
new Host(
hostId,
new RamProvisionerSimple(ram),
new BwProvisionerSimple(bw),
storage,
peList,
new VmSchedulerTimeShared(peList)
)
); // This is our machine

// 5. Create a DatacenterCharacteristics object that stores


the
//

properties of a data center: architecture, OS, list

//

Machines, allocation policy: time- or space-shared,

of
time zone
//
and its price (G$/Pe time unit).
String arch = "x86";
// system architecture
String os = "Linux";
// operating system
String vmm = "Xen";
double time_zone = 10.0;
// time zone this resource
located
double cost = 3.0;
// the cost of using
processing in this resource
double costPerMem = 0.05;
// the cost of using memory
in this resource
double costPerStorage = 0.001;
// the cost of using
storage in this resource
double costPerBw = 0.0;
// the cost of using bw in
this resource
LinkedList<Storage>
storageList
=
new
LinkedList<Storage>(); //we are not adding SAN devices by now
//
DatacenterCharacteristics characteristics = new
DatacenterCharacteristics(
arch, os, vmm, hostList, time_zone, cost, costPerMem,
costPerStorage, costPerBw);

// 6. Finally, we need to create a PowerDatacenter object.


Datacenter datacenter = null
null;
try {
datacenter = new Datacenter(name, characteristics, new
VmAllocationPolicySimple(hostList), storageList, 0);
} catch (Exception e) {
e.printStackTrace();
}
return datacenter;
}

//We strongly encourage users to develop their own broker


policies, to submit vms and cloudlets according
//to the specific rules of the simulated scenario
private static DatacenterBroker createBroker(){
DatacenterBroker broker = null
null;
try {
broker = new DatacenterBroker("Broker");
} catch (Exception e) {
e.printStackTrace();
return null
null;
}
return broker;
}
/**
* Prints the Cloudlet objects
* @param list list of Cloudlets
*/
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("###.##");
int i = 0; i < size; i++) {
for (int
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

indent

indent

dft.format(cloudlet.getActualCPUTime()) +
dft.format(cloudlet.getExecStartTime())+
indent
+
dft.format(cloudlet.getFinishTime()));
}
}

indent

}
}

bindCloudletsToVmsSimple()
bindCloudletsToVmsSimple()
========== OUTPUT ==========
Cloudlet ID

STATUS

Data center ID

VM ID

Time

Start Time

Finish

Time
0

SUCCESS

69.66

0.1

SUCCESS

65.96

69.76

SUCCESS

172.35

0.1

172.45

SUCCESS

211.28

0.1

211.38

SUCCESS

69.36

172.45

SUCCESS

242.55

0.1

SUCCESS

147.01

211.38

358.39

SUCCESS

238.58

242.65

481.23

*****Datacenter: Datacenter_0*****
User id
3

Debt
91.2

**********************************
TestAllocation finished!

69.76
135.72

241.81
242.65

bindCloudletsToVmsTimeAwared()
bindCloudletsToVmsTimeAwared()
========== OUTPUT ==========
Cloudlet ID

STATUS

Data center ID

VM ID

Time

Start Time

Finish

Time
2

SUCCESS

115.17

0.1

115.27

SUCCESS

150.68

0.1

150.78

SUCCESS

154.39

0.1

154.49

SUCCESS

70.09

154.49

SUCCESS

111.57

115.27

SUCCESS

232.77

0.1

SUCCESS

87.73

150.78

238.51

SUCCESS

58.58

224.58

283.16

224.58
226.84
232.87

*****Datacenter: Datacenter_0*****
User id
3

Debt
91.2

**********************************
TestAllocation finished!

481.23 283.16 200

10 cloudlet5
8 cloudlet4

[VmScheduler.vmCreate] Allocation of VM #1 to Host #0 failed by


MIPS
0.1: Broker: Postponing execution of cloudlet 1: bount VM not
available

6
6.1 Eclipse
eclipse
File->new ->Project -> java Project
Project name finish;
project
Project explorer project->new->class
name java
finish Project explorer
project src ->run as->java application

6.2 flanagan
flanagan.jar
http://www.ee.ucl.ac.uk/~mflanaga/java/#down
flanagan.jar cloudsim jars Eclipse
jar Build Path Add to Build Path

7 Netbeans Cloudsim

Step1
open Netbeans (any version greater then 5.0) ,Go to file-->>new project

Step 2
select "Java" folder then select first option java Application ,Press next

Step3
Now give name to the project as you wish ,then un-check the "create main class" press next.

Step 4
Now your project is been created as shown.

Step5
Go to library ,right click on it ,a menu will come ,click on "Add jars/Folders"
Now browse the cloudsim folder which you have extracted from zip file .and go to "cloudsim-3.0.2\jars"
and select "cloudsim-3.0.2.jar" .

Step6
Now simply copy the "org" folder in "cloudsim-3.0.2\examples" and paste it to net beans source folder as
shown.go to source and right click select
Paste.

Step 7
To run the example go to source ->> org.cloudbus.cloudsim.examples->>select any example ,right click
on it and select "run" option the output will be displayed in the output window at the bottom.

TO RUN EXAMPLE CODE FROM SOURCE CODE


Step 1,2,3,4 remain the same in step 5 copy and paste "org" folder from "cloudsim-3.0.2\source" and paste
it into the source folder of your netbeans project as you copied the example folder.