forked from cloudsimplus/cloudsimplus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DynamicCloudletsArrival1.java
258 lines (230 loc) · 9.54 KB
/
DynamicCloudletsArrival1.java
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
/*
* CloudSim Plus: A modern, highly-extensible and easier-to-use Framework for
* Modeling and Simulation of Cloud Computing Infrastructures and Services.
* http://cloudsimplus.org
*
* Copyright (C) 2015-2016 Universidade da Beira Interior (UBI, Portugal) and
* the Instituto Federal de Educação Ciência e Tecnologia do Tocantins (IFTO, Brazil).
*
* This file is part of CloudSim Plus.
*
* CloudSim Plus is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* CloudSim Plus is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with CloudSim Plus. If not, see <http://www.gnu.org/licenses/>.
*/
package org.cloudsimplus.examples;
import org.cloudsimplus.builders.tables.CloudletsTableBuilder;
import java.util.ArrayList;
import java.util.List;
import org.cloudbus.cloudsim.cloudlets.Cloudlet;
import org.cloudbus.cloudsim.cloudlets.CloudletSimple;
import org.cloudbus.cloudsim.datacenters.Datacenter;
import org.cloudbus.cloudsim.datacenters.DatacenterSimple;
import org.cloudbus.cloudsim.brokers.DatacenterBroker;
import org.cloudbus.cloudsim.brokers.DatacenterBrokerSimple;
import org.cloudbus.cloudsim.datacenters.DatacenterCharacteristics;
import org.cloudbus.cloudsim.datacenters.DatacenterCharacteristicsSimple;
import org.cloudbus.cloudsim.hosts.Host;
import org.cloudbus.cloudsim.hosts.HostSimple;
import org.cloudbus.cloudsim.util.Log;
import org.cloudbus.cloudsim.resources.Pe;
import org.cloudbus.cloudsim.resources.PeSimple;
import org.cloudbus.cloudsim.utilizationmodels.UtilizationModel;
import org.cloudbus.cloudsim.utilizationmodels.UtilizationModelFull;
import org.cloudbus.cloudsim.vms.Vm;
import org.cloudbus.cloudsim.vms.VmSimple;
import org.cloudbus.cloudsim.allocationpolicies.VmAllocationPolicySimple;
import org.cloudbus.cloudsim.core.CloudSim;
import org.cloudbus.cloudsim.provisioners.PeProvisionerSimple;
import org.cloudbus.cloudsim.provisioners.ResourceProvisionerSimple;
import org.cloudbus.cloudsim.schedulers.cloudlet.CloudletSchedulerTimeShared;
import org.cloudbus.cloudsim.schedulers.vm.VmSchedulerSpaceShared;
/**
* An example showing how to delay the submission of cloudlets.
* Although there is enough resources to run all cloudlets simultaneously,
* the example delays the creation and execution of some cloudlets inside a VM,
* simulating the dynamic arrival of cloudlets.
* It first creates a set of cloudlets without delay and
* another set of cloudlets all with the same submission delay.
*
* @author Manoel Campos da Silva Filho
* @since CloudSim Plus 1.0
*/
public class DynamicCloudletsArrival1 {
/**
* Number of Processor Elements (CPU Cores) of each Host.
*/
private static final int HOST_PES_NUMBER = 4;
/**
* Number of Processor Elements (CPU Cores) of each VM and cloudlet.
*/
private static final int VM_PES_NUMBER = HOST_PES_NUMBER;
/**
* Number of Cloudlets to create simultaneously.
* Other cloudlets will be enqueued.
*/
private static final int NUMBER_OF_CLOUDLETS = VM_PES_NUMBER*2;
private final List<Host> hostList;
private final List<Vm> vmList;
private final List<Cloudlet> cloudletList;
private final DatacenterBroker broker;
private final Datacenter datacenter;
private final CloudSim simulation;
/**
* Starts the example execution, calling the class constructor\
* to build and run the simulation.
*
* @param args command line parameters
*/
public static void main(String[] args) {
new DynamicCloudletsArrival1();
}
/**
* Default constructor that builds and starts the simulation.
*/
public DynamicCloudletsArrival1() {
int numberOfUsers = 1; // number of cloud users/customers (brokers)
Log.printFormattedLine("Starting %s ...", getClass().getSimpleName());
simulation = new CloudSim();
this.hostList = new ArrayList<>();
this.vmList = new ArrayList<>();
this.cloudletList = new ArrayList<>();
this.datacenter = createDatacenter();
this.broker = new DatacenterBrokerSimple(simulation);
Vm vm = createAndSubmitVmAndCloudlets();
/*Defines a delay of 5 seconds and creates another group of cloudlets
that will start executing inside a VM only after this delay expires.*/
double submissionDelay = 5;
//createAndSubmitCloudlets(vm, submissionDelay);
runSimulationAndPrintResults();
Log.printFormattedLine("%s finished!", getClass().getSimpleName());
}
private void runSimulationAndPrintResults() {
simulation.start();
List<Cloudlet> cloudlets = broker.getCloudletFinishedList();
new CloudletsTableBuilder(cloudlets).build();
}
/**
* Creates cloudlets and submit them to the broker, applying
* a submission delay for each one (simulating the dynamic cloudlet arrival).
*
* @param vm Vm to run the cloudlets to be created
* @param submissionDelay the delay the broker has to include when submitting the Cloudlets
*
* @see #createCloudlet(int, Vm, DatacenterBroker)
*/
private void createAndSubmitCloudlets(Vm vm, double submissionDelay) {
int cloudletId = cloudletList.size();
List<Cloudlet> list = new ArrayList<>(NUMBER_OF_CLOUDLETS);
for(int i = 0; i < NUMBER_OF_CLOUDLETS; i++){
Cloudlet cloudlet = createCloudlet(cloudletId++, vm, broker);
list.add(cloudlet);
}
broker.submitCloudletList(list, submissionDelay);
cloudletList.addAll(list);
}
/**
* Creates one Vm and a group of cloudlets to run inside it,
* and submit the Vm and its cloudlets to the broker.
* @return the created VM
*
* @see #createVm(int, org.cloudbus.cloudsim.brokers.DatacenterBroker)
*/
private Vm createAndSubmitVmAndCloudlets() {
List<Vm> list = new ArrayList<>();
Vm vm = createVm(this.vmList.size(), broker);
list.add(vm);
broker.submitVmList(list);
this.vmList.addAll(list);
//Submit cloudlets without delay
createAndSubmitCloudlets(vm, 0);
return vm;
}
/**
* Creates a VM with pre-defined configuration.
*
* @param id the VM id
* @param broker the broker that will be submit the VM
* @return the created VM
*
*/
private Vm createVm(int id, DatacenterBroker broker) {
int mips = 1000;
long size = 10000; // image size (MEGABYTE)
int ram = 512; // vm memory (MEGABYTE)
long bw = 1000;
return new VmSimple(id, mips, VM_PES_NUMBER)
.setRam(ram).setBw(bw).setSize(size)
.setCloudletScheduler(new CloudletSchedulerTimeShared());
}
/**
* Creates a cloudlet with pre-defined configuration.
*
* @param id Cloudlet id
* @param vm vm to run the cloudlet
* @param broker the broker that will submit the cloudlets
* @return the created cloudlet
*/
private Cloudlet createCloudlet(int id, Vm vm, DatacenterBroker broker) {
long fileSize = 300;
long outputSize = 300;
long length = 10000; //in number of Million Instructions (MI)
int pesNumber = 1;
UtilizationModel utilizationModel = new UtilizationModelFull();
Cloudlet cloudlet = new CloudletSimple(id, length, pesNumber)
.setFileSize(fileSize)
.setOutputSize(outputSize)
.setUtilizationModel(utilizationModel)
.setVm(vm);
return cloudlet;
}
/**
* Creates a Datacenter with pre-defined configuration.
*
* @return the created Datacenter
*/
private Datacenter createDatacenter() {
Host host = createHost(0);
hostList.add(host);
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 Datacenter
double costPerBw = 0.0; // the cost of using bw in this resource
DatacenterCharacteristics characteristics =
new DatacenterCharacteristicsSimple(hostList)
.setCostPerSecond(cost)
.setCostPerMem(costPerMem)
.setCostPerStorage(costPerStorage)
.setCostPerBw(costPerBw);
return new DatacenterSimple(simulation, characteristics, new VmAllocationPolicySimple());
}
/**
* Creates a host with pre-defined configuration.
*
* @param id The Host id
* @return the created host
*/
private Host createHost(int id) {
List<Pe> peList = new ArrayList<>();
long mips = 1000;
for(int i = 0; i < HOST_PES_NUMBER; i++){
peList.add(new PeSimple(mips, new PeProvisionerSimple()));
}
long ram = 2048; // host memory (MEGABYTE)
long storage = 1000000; // host storage (MEGABYTE)
long bw = 10000; //Megabits/s
return new HostSimple(ram, bw, storage, peList)
.setRamProvisioner(new ResourceProvisionerSimple())
.setBwProvisioner(new ResourceProvisionerSimple())
.setVmScheduler(new VmSchedulerSpaceShared());
}
}