forked from cloudsimplus/cloudsimplus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
LinuxCompletelyFairSchedulerExample.java
executable file
·190 lines (161 loc) · 7.48 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
/*
* 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-2021 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.schedulers;
import org.cloudbus.cloudsim.allocationpolicies.VmAllocationPolicySimple;
import org.cloudbus.cloudsim.brokers.DatacenterBroker;
import org.cloudbus.cloudsim.brokers.DatacenterBrokerSimple;
import org.cloudbus.cloudsim.cloudlets.Cloudlet;
import org.cloudbus.cloudsim.cloudlets.CloudletSimple;
import org.cloudbus.cloudsim.core.CloudSim;
import org.cloudbus.cloudsim.datacenters.Datacenter;
import org.cloudbus.cloudsim.datacenters.DatacenterSimple;
import org.cloudbus.cloudsim.hosts.Host;
import org.cloudbus.cloudsim.hosts.HostSimple;
import org.cloudbus.cloudsim.provisioners.PeProvisionerSimple;
import org.cloudbus.cloudsim.provisioners.ResourceProvisionerSimple;
import org.cloudbus.cloudsim.resources.Pe;
import org.cloudbus.cloudsim.resources.PeSimple;
import org.cloudbus.cloudsim.schedulers.cloudlet.CloudletSchedulerCompletelyFair;
import org.cloudbus.cloudsim.schedulers.vm.VmSchedulerTimeShared;
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.cloudsimplus.builders.tables.CloudletsTableBuilder;
import org.cloudsimplus.builders.tables.TextTableColumn;
import java.util.ArrayList;
import java.util.List;
/**
* 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.
* It defines priority for some Cloudlets, so that they will have more time to use the CPU
* than other Cloudlets.
*
* <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;
public static void main(String[] args) {
new LinuxCompletelyFairSchedulerExample();
}
/**
* Default constructor which builds and runs the simulation.
*/
private LinuxCompletelyFairSchedulerExample() {
/*Enables just some level of log messages.
Make sure to import org.cloudsimplus.util.Log;*/
//Log.setLevel(ch.qos.logback.classic.Level.WARN);
System.out.println("Starting " + getClass().getSimpleName());
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 CloudletsTableBuilder(finishedCloudlets)
.addColumn(2, new TextTableColumn("Priority"), Cloudlet::getPriority)
.build();
System.out.println(getClass().getSimpleName() + " finished!");
}
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());
}
return new DatacenterSimple(simulation, hostList, 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.
final UtilizationModel utilization = new UtilizationModelFull();
return new CloudletSimple(numberOfCreatedCloudlets++, CLOUDLET_LEN, CLOUDLET_PES)
.setFileSize(fileSize)
.setOutputSize(outputSize)
.setUtilizationModel(utilization);
}
}