-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimRunnerRandom.java
More file actions
164 lines (119 loc) · 5.81 KB
/
SimRunnerRandom.java
File metadata and controls
164 lines (119 loc) · 5.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
package com.IEEEpaper.examples;
import org.cloudbus.cloudsim.Cloudlet;
import org.cloudbus.cloudsim.CloudletSchedulerDynamicWorkload;
import org.cloudbus.cloudsim.CloudletSchedulerTimeShared;
import org.cloudbus.cloudsim.Log;
import org.cloudbus.cloudsim.Vm;
import org.cloudbus.cloudsim.VmAllocationPolicySimple;
import org.cloudbus.cloudsim.core.CloudSim;
import org.cloudbus.cloudsim.ex.DatacenterBrokerEX;
import org.cloudbus.cloudsim.power.PowerDatacenterNonPowerAware;
import org.cloudbus.cloudsim.power.PowerHost;
import org.cloudbus.cloudsim.power.PowerVm;
import org.cloudbus.cloudsim.power.PowerVmAllocationPolicySimple;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.*;
public class SimRunnerRandom {
/**
* The main method.
*
* @param args the arguments
* @throws IOException Signals that an I/O exception has occurred.
*/
public static void main(String[] args) throws IOException {
// Create a folder for the sequence of simulations
String simName = new SimpleDateFormat("yyyyMMdd'_'HHmmss").format(new Date());
File outputFolder = new File("output/" + simName);
if (!outputFolder.mkdir()) {
System.err.println("Folder could not be created: " + outputFolder.getAbsolutePath());
System.exit(1);
}
int[] hosts = {100};
int[] cloudlets = {500};
for (int hostCount : hosts) {
for (int cloudletCount : cloudlets) {
runSim(outputFolder.getAbsolutePath(), hostCount, cloudletCount);
}
}
}
private static void runSim(String outputPrefix, int hostCount, int cloudletCount) throws FileNotFoundException {
String expName = hostCount + "_" + cloudletCount;
String outFolderPath = outputPrefix + "/" + expName;
Util.init(outFolderPath, expName);
Log.setOutput(new FileOutputStream(Util.outFileOut));
Log.printLine("Starting " + expName);
try {
CloudSim.init(1, Calendar.getInstance(), false);
DatacenterBrokerEX broker = Helper.createBroker();
int brokerId = broker.getId();
List<Cloudlet> cloudletList = Helper.createCloudletList(brokerId, cloudletCount);
int vms = 150;/// number of vms
List<Vm> vmList = Helper.createVmList(brokerId, vms);
List<PowerHost> hostList = Helper.createHostList(hostCount);
PowerDatacenterNonPowerAware datacenter = (PowerDatacenterNonPowerAware) Helper.createDatacenter(
"Datacenter",
MyDatacenter.class,
hostList,
new PowerVmAllocationPolicySimple(hostList));
// datacenter.setDisableMigrations(true);
/////////////////////////////////////////////////////////////////////////////////////
// adding vms dynamically
for(int i=150 ; i<250 ; i++){
// Random ran1 = new Random();
Vm vm = new PowerVm(
i,
brokerId,
Constants.VM_MIPS[0],
Constants.VM_PES[0],
Constants.VM_RAM[0],
Constants.VM_BW,
Constants.VM_SIZE,
1,
"Xen",
new CloudletSchedulerDynamicWorkload(Constants.VM_MIPS[0], Constants.VM_PES[0]),
Constants.SCHEDULING_INTERVAL);
// submit vm to the broker after i+20 seconds
broker.createVmsAfter(Collections.singletonList(vm), i + 20);
}
///////////////////////////////////////////////////////////////////////////////////////
broker.submitVmList(vmList);
// broker.submitCloudletList(cloudletList);
submitCloudletsRandomly(broker, cloudletList);
String delim = ", ";
String data = hostList.size() + delim + cloudletList.size();
CloudSim.startSimulation();
CloudSim.stopSimulation();
List<Cloudlet> newList = broker.getCloudletReceivedList();
Log.printLine("Received " + newList.size() + " cloudlets");
// Recieved Cloudlets Count
data += delim + newList.size();
Util.writeRowToDat(data);
// Cloudlet Execution time
for (Cloudlet c : newList) {
Util.writeRowToDat(c.getCloudletId() + delim // Cloudlet Id
+ c.getVmId() + delim // vm id
+ c.getCloudletLength() + delim
+ c.getActualCPUTime() + delim // Actual CPU Time
+ c.getExecStartTime() + delim // Start Time
+ c.getFinishTime()); // Finish Time
}
DelayExample1.printCloudletList(newList);
} catch (Exception e) {
e.printStackTrace();
Log.printLine("The simulation has been terminated due to an unexpected error");
System.exit(0);
}
Log.printLine("Finished " + expName);
}
private static void submitCloudletsRandomly(DatacenterBrokerEX broker, List<Cloudlet> cloudletList) {
Random random = new Random(Constants.CLOUDLET_DELAY_SEED);
for (Cloudlet cloudlet : cloudletList) {
double delay = (1 + random.nextInt(Constants.CLOUDLET_DELAY_BOUND)) * 10;
broker.submitCloudletList(Collections.singletonList(cloudlet), delay);
}
}
}