forked from cloudsimplus/cloudsimplus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
LinuxCompletelyFairSchedulerExample.java
193 lines (164 loc) · 7.52 KB
/
LinuxCompletelyFairSchedulerExample.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
/*
* 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 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.allocationpolicies.VmAllocationPolicySimple;
import org.cloudbus.cloudsim.schedulers.vm.VmSchedulerTimeShared;
import org.cloudbus.cloudsim.vms.VmSimple;
import org.cloudbus.cloudsim.core.CloudSim;
import org.cloudbus.cloudsim.provisioners.PeProvisionerSimple;
import org.cloudbus.cloudsim.provisioners.ResourceProvisionerSimple;
import org.cloudbus.cloudsim.schedulers.cloudlet.CloudletSchedulerCompletelyFair;
import org.cloudsimplus.builders.tables.PriorityCloudletsTableBuilder;
/**
* An example that uses an implementation of the {@link CloudletSchedulerCompletelyFair Completely Fair Scheduler}
* used in the Linux Kernel for scheduling of Cloudlets execution inside a Vm.
*
* <p>It is strongly recommended to read the {@link CloudletSchedulerCompletelyFair} class documentation
* to understand how this scheduler works.</p>
*
* @author Manoel Campos da Silva Filho
* @see <a href="https://en.wikipedia.org/wiki/Completely_Fair_Scheduler">Completely Fair Scheduler (CFS)</a>
* @since CloudSim Plus 1.0
*
*/
public class LinuxCompletelyFairSchedulerExample {
private static final int HOSTS_NUMBER = 1;
private static final long HOST_MIPS = 1000;
private static final int HOST_PES = 3;
private static final int VMS_NUMBER = 1;
private static final int VM_PES = HOST_PES;
private static final long VM_MIPS = HOST_MIPS;
private static final int CLOUDLETS_NUMBER = HOST_PES*2;
private static final int CLOUDLET_PES = 1;
private static final int CLOUDLET_LEN = 10000; //in MI
private final CloudSim simulation;
private List<Cloudlet> cloudletList;
private List<Vm> vmList;
private int numberOfCreatedCloudlets = 0;
private int numberOfCreatedVms = 0;
private int numberOfCreatedHosts = 0;
/**
* Starts the simulation.
* @param args
*/
public static void main(String[] args) {
new LinuxCompletelyFairSchedulerExample();
}
/**
* Default constructor where the simulation is built.
*/
public LinuxCompletelyFairSchedulerExample() {
Log.printFormattedLine("Starting %s...", getClass().getSimpleName());
//Number of cloud customers
int numberOfCloudUsers = 1;
simulation = new CloudSim();
Datacenter datacenter0 = createDatacenter();
DatacenterBroker broker0 = new DatacenterBrokerSimple(simulation);
createAndSubmitVms(broker0);
createAndSubmitCloudlets(broker0);
for(int i = 0; i < CLOUDLETS_NUMBER/2; i++){
cloudletList.get(i).setPriority(4);
}
simulation.start();
List<Cloudlet> finishedCloudlets = broker0.getCloudletFinishedList();
new PriorityCloudletsTableBuilder(finishedCloudlets).build();
Log.printFormattedLine("%s finished!", getClass().getSimpleName());
}
private void createAndSubmitCloudlets(DatacenterBroker broker0) {
this.cloudletList = new ArrayList<>(CLOUDLETS_NUMBER);
for(int i = 0; i < CLOUDLETS_NUMBER; i++){
this.cloudletList.add(createCloudlet(broker0));
}
broker0.submitCloudletList(cloudletList);
}
private void createAndSubmitVms(DatacenterBroker broker0) {
this.vmList = new ArrayList<>(VMS_NUMBER);
for(int i = 0; i < VMS_NUMBER; i++){
this.vmList.add(createVm(broker0));
}
broker0.submitVmList(vmList);
}
private Datacenter createDatacenter() {
List<Host> hostList = new ArrayList<>(HOSTS_NUMBER);
for(int i = 0; i < HOSTS_NUMBER; i++){
hostList.add(createHost());
}
DatacenterCharacteristics characteristics = new DatacenterCharacteristicsSimple(hostList);
return new DatacenterSimple(simulation, characteristics, new VmAllocationPolicySimple());
}
private Host createHost() {
final long ram = 2048; // host memory (MEGABYTE)
final long storage = 1000000; // host storage
final long bw = 10000;
List<Pe> peList = createHostPesList(HOST_MIPS);
return new HostSimple(ram, bw, storage, peList)
.setRamProvisioner(new ResourceProvisionerSimple())
.setBwProvisioner(new ResourceProvisionerSimple())
.setVmScheduler(new VmSchedulerTimeShared());
}
private List<Pe> createHostPesList(long mips) {
List<Pe> cpuCoresList = new ArrayList<>(HOST_PES);
for(int i = 0; i < HOST_PES; i++){
cpuCoresList.add(new PeSimple(mips, new PeProvisionerSimple()));
}
return cpuCoresList;
}
private Vm createVm(DatacenterBroker broker) {
final long storage = 10000; // vm image size (MEGABYTE)
final int ram = 512; // vm memory (MEGABYTE)
final long bw = 1000; // vm bandwidth
return new VmSimple(numberOfCreatedVms++, VM_MIPS, VM_PES)
.setRam(ram).setBw(bw).setSize(storage)
.setCloudletScheduler(new CloudletSchedulerCompletelyFair());
}
private Cloudlet createCloudlet(DatacenterBroker broker) {
final long fileSize = 300; //Size (in bytes) before execution
final long outputSize = 300; //Size (in bytes) after execution
//Defines how CPU, RAM and Bandwidth resources are used
//Sets the same utilization model for all these resources.
UtilizationModel utilization = new UtilizationModelFull();
return new CloudletSimple(numberOfCreatedCloudlets++, CLOUDLET_LEN, CLOUDLET_PES)
.setFileSize(fileSize)
.setOutputSize(outputSize)
.setUtilizationModel(utilization);
}
}