source: DCWoRMS/branches/coolemall/src/experiments/e2dc2015/models/i5/FCFSBF_RandomPluginFansMngDynamic.java @ 1593

Revision 1593, 11.9 KB checked in by wojtekp, 8 years ago (diff)
  • Property svn:mime-type set to text/plain
Line 
1package experiments.e2dc2015.models.i5;
2
3import java.util.ArrayList;
4import java.util.HashMap;
5import java.util.List;
6import java.util.Map;
7import java.util.Random;
8
9import schedframe.events.scheduling.SchedulingEvent;
10import schedframe.resources.ResourceStatus;
11import schedframe.resources.StandardResourceType;
12import schedframe.resources.computing.ComputingResource;
13import schedframe.resources.computing.Core;
14import schedframe.resources.computing.Node;
15import schedframe.resources.computing.Processor;
16import schedframe.resources.computing.profiles.energy.ResourceEvent;
17import schedframe.resources.computing.profiles.energy.ResourceEventType;
18import schedframe.resources.computing.profiles.energy.airthroughput.CustomAirflowStateName;
19import schedframe.resources.devices.Device;
20import schedframe.resources.devices.Fan;
21import schedframe.resources.units.ProcessingElements;
22import schedframe.resources.units.ResourceUnit;
23import schedframe.resources.units.ResourceUnitName;
24import schedframe.resources.units.StandardResourceUnitName;
25import schedframe.scheduling.manager.resources.ClusterResourceManager;
26import schedframe.scheduling.manager.resources.ResourceManager;
27import schedframe.scheduling.manager.tasks.JobRegistry;
28import schedframe.scheduling.plan.SchedulingPlanInterface;
29import schedframe.scheduling.plan.impl.SchedulingPlan;
30import schedframe.scheduling.plugin.ModuleList;
31import schedframe.scheduling.queue.TaskQueue;
32import schedframe.scheduling.queue.TaskQueueList;
33import schedframe.scheduling.tasks.TaskInterface;
34import simulator.DataCenterWorkloadSimulator;
35import eduni.simjava.Sim_system;
36import example.localplugin.BaseLocalSchedulingPlugin;
37import experiments.e2dc2015.EnvironmentConditions;
38import gridsim.dcworms.DCWormsTags;
39
40public class FCFSBF_RandomPluginFansMngDynamic extends BaseLocalSchedulingPlugin {
41
42
43        private Random rand;
44       
45        public FCFSBF_RandomPluginFansMngDynamic() {
46                rand = new Random(5);
47        }
48
49        public SchedulingPlanInterface<?> schedule(SchedulingEvent event, TaskQueueList queues, JobRegistry jobRegistry,
50                        ResourceManager resManager, ModuleList modules) {
51
52
53                ClusterResourceManager resourceManager = (ClusterResourceManager) resManager;
54                List<Node> nodes = resourceManager.getNodes();
55                SchedulingPlan plan = new SchedulingPlan();
56
57                // choose the events types to serve.
58                // Different actions for different events are possible.
59                switch (event.getType()) {
60               
61               
62                case TIMER:
63
64                        System.out.println("##" + Sim_system.clock());
65                        DataCenterWorkloadSimulator.getEventManager().sendToResources(StandardResourceType.Processor, 0.0, new ResourceEvent(ResourceEventType.TIMER, null));
66                        //DataCenterWorkloadSimulator.getEventManager().sendToAllSchedulers(EnvironmentConditions.SYSTEM_UDPATE_INTERVAL, DCWormsTags.TIMER, "Test");
67                        break;
68                       
69                case START_TASK_EXECUTION:
70                case TASK_FINISHED:
71
72                        // our tasks are placed only in first queue (see BaseLocalSchedulingPlugin.placeJobsInQueues() method)
73                        TaskQueue q = queues.get(0);
74                        // check all tasks in queue
75
76                        for (int i = 0; i < q.size(); i++) {
77                                TaskInterface<?> task = q.get(i);
78                                // if status of the tasks in READY
79                                if (task.getStatus() == DCWormsTags.READY) {
80                                        Map<ResourceUnitName, ResourceUnit> choosenResources = chooseResourcesForExecution(nodes, task);
81                                        if (choosenResources != null) {
82                                                addToSchedulingPlan(plan, task, choosenResources);
83                                        }
84                                }
85                        }
86
87                        break;
88                case RESOURCE_TEMPERATURE_LIMIT_EXCEEDED:
89                        manageFans(resourceManager.getResourceByName(event.getSource()));
90                        break;
91
92                }       
93
94                return plan;
95        }
96       
97        private void manageFans(ComputingResource cr ){
98                //System.out.println("tuning fans");
99                double temp = cr.getThermalInterface().getRecentTemperature().getValue();
100                double prevTemp;
101                if(cr.getThermalInterface().getTemperatureHistory().size() == 1)
102                        prevTemp = temp;
103                else {
104                        prevTemp = cr.getThermalInterface().getTemperatureHistory().get(cr.getThermalInterface().getTemperatureHistory().size() - 2).getValue();
105                }
106
107                //System.out.println(Sim_system.clock() + " === " + prevTemp+  ";  " + temp);
108                boolean getingHotter = prevTemp < temp;
109                boolean getingColder = prevTemp > temp;
110                Node n = (Node) cr.getParent();
111                List<ComputingResource> neighbours = n.getParent().getChildren();
112                for(Device d: n.getParent().getResourceCharacteristic().getDevices()){
113                        //System.out.println(d.getName() + "; " + n.getName());
114                        int fanId = Integer.valueOf(d.getName().split("_")[1]).intValue();
115                        int nodeId = Integer.valueOf(n.getName().split("_")[1]).intValue();
116                        if(nodeId > (fanId - 1) * EnvironmentConditions.NODES_IN_A_COLUMN && nodeId <= fanId * EnvironmentConditions.NODES_IN_A_COLUMN /*|| Integer.valueOf(device.getName().split("_")[1]) == Integer.valueOf(cpu.getParent().getName().split("_")[1]) - EnvironmentConditions.NODES_IN_A_ROW*/){
117                                Fan f = (Fan) d;
118                                int speed;
119                                try{
120                                        speed= Integer.valueOf(f.getAirflowInterface().getAirflowState().getLabel().split("_")[1]).intValue();
121                                } catch(Exception e){
122                                        speed = 0;
123                                }
124                                for(ComputingResource neighbour: neighbours){
125                                        int neighbourId = Integer.valueOf(neighbour.getName().split("_")[1]).intValue();
126                                        if(neighbourId > (fanId - 1) * EnvironmentConditions.NODES_IN_A_COLUMN && neighbourId <= fanId * EnvironmentConditions.NODES_IN_A_COLUMN){
127                                                double neighbourTemp = neighbour.getChildren().get(0).getThermalInterface().getRecentTemperature().getValue();
128                                                if(neighbourTemp > temp){
129                                                        return;
130                                                }
131                                        }
132                                }
133                                //System.out.println("getingHotter: "+ (prevTemp < temp));
134                                if(getingHotter){
135                                        if(temp > EnvironmentConditions._30_2_40- EnvironmentConditions.tempShift && temp < EnvironmentConditions._40_2_50- EnvironmentConditions.tempShift ){
136                                                if(speed < 40){
137                                                        //System.out.println("+++++++++ 30 to 40");
138                                                        f.getAirflowInterface().setAirflowState(new CustomAirflowStateName("ON_40"));
139                                                }
140                                        } else if(temp > EnvironmentConditions._40_2_50- EnvironmentConditions.tempShift && temp < EnvironmentConditions._50_2_60- EnvironmentConditions.tempShift ){
141                                                if(speed < 50){
142                                                        //System.out.println("++++++++ 40 to 50");
143                                                        f.getAirflowInterface().setAirflowState(new CustomAirflowStateName("ON_50"));
144                                                }
145                                        } else if(temp > EnvironmentConditions._50_2_60- EnvironmentConditions.tempShift && temp < EnvironmentConditions._60_2_70- EnvironmentConditions.tempShift ){
146                                                if(speed < 60){
147                                                        //System.out.println("++++++++ 50 to 60");
148                                                        f.getAirflowInterface().setAirflowState(new CustomAirflowStateName("ON_60"));
149                                                }
150                                        } else if(temp > EnvironmentConditions._60_2_70- EnvironmentConditions.tempShift && temp < EnvironmentConditions._70_2_80- EnvironmentConditions.tempShift ){
151                                                if(speed < 70){
152                                                        //System.out.println("++++++++ 60 to 70");
153                                                        f.getAirflowInterface().setAirflowState(new CustomAirflowStateName("ON_70"));
154                                                }
155                                        } else if(temp > EnvironmentConditions._70_2_80- EnvironmentConditions.tempShift && temp < EnvironmentConditions._80_2_90- EnvironmentConditions.tempShift ){
156                                                if(speed < 80){
157                                                        //System.out.println("++++++++ 70 to 80");
158                                                        f.getAirflowInterface().setAirflowState(new CustomAirflowStateName("ON_80"));
159                                                }
160                                        } else if(temp > EnvironmentConditions._80_2_90- EnvironmentConditions.tempShift && temp < EnvironmentConditions._90_2_100- EnvironmentConditions.tempShift ){
161                                                if(speed < 90){
162                                                        //System.out.println("++++++++ 80 to 90");
163                                                        f.getAirflowInterface().setAirflowState(new CustomAirflowStateName("ON_90"));
164                                                }
165                                        } else if(temp > EnvironmentConditions._90_2_100- EnvironmentConditions.tempShift ){
166                                                if(speed < 100){
167                                                        //System.out.println("++++++++ 90 to 100");
168                                                        f.getAirflowInterface().setAirflowState(new CustomAirflowStateName("ON_100"));
169                                                }
170                                        }                                               
171                                } else if (getingColder){
172                                        if(temp > EnvironmentConditions._90_2_80 && temp < EnvironmentConditions._100_2_90){
173                                                if(speed == 100){
174                                                        //System.out.println("-------- 100 to 90");
175                                                        f.getAirflowInterface().setAirflowState(new CustomAirflowStateName("ON_90"));
176                                                }
177                                        } else if(temp > EnvironmentConditions._80_2_70 && temp < EnvironmentConditions._90_2_80){
178                                                if(speed >= 90){
179                                                        //System.out.println("-------- 90 to 80");
180                                                        f.getAirflowInterface().setAirflowState(new CustomAirflowStateName("ON_80"));           
181                                                }
182                                        } else if(temp > EnvironmentConditions._70_2_60 && temp < EnvironmentConditions._80_2_70){
183                                                if(speed >= 80){
184                                                        //System.out.println("-------- 80 to 70");
185                                                        f.getAirflowInterface().setAirflowState(new CustomAirflowStateName("ON_70"));           
186                                                }
187                                        } else if(temp > EnvironmentConditions._60_2_50 && temp < EnvironmentConditions._70_2_60){
188                                                if(speed >= 70){
189                                                        //System.out.println("-------- 70 to 60");
190                                                        f.getAirflowInterface().setAirflowState(new CustomAirflowStateName("ON_60"));           
191                                                }
192                                        } else if(temp > EnvironmentConditions._50_2_40 && temp < EnvironmentConditions._60_2_50){
193                                                if(speed >= 60){
194                                                        //System.out.println("-------- 60 to 50");
195                                                        f.getAirflowInterface().setAirflowState(new CustomAirflowStateName("ON_50"));           
196                                                }
197                                        } else if(temp > EnvironmentConditions._40_2_30 && temp < EnvironmentConditions._50_2_40){
198                                                if(speed >= 50){
199                                                        //System.out.println("-------- 60 to 40");
200                                                        f.getAirflowInterface().setAirflowState(new CustomAirflowStateName("ON_40"));           
201                                                }
202                                        }  else if (temp < EnvironmentConditions._40_2_30) {
203                                                if(speed >= 40){
204                                                        //System.out.println("-------- 40 to 30");
205                                                        f.getAirflowInterface().setAirflowState(new CustomAirflowStateName("ON_30"));   
206                                                }
207                                        }
208                                }
209                        }
210                }
211        }
212        private Map<ResourceUnitName, ResourceUnit> chooseResourcesForExecution(
213                        List<Node> nodes, TaskInterface<?> task) {
214
215                Map<ResourceUnitName, ResourceUnit> map = new HashMap<ResourceUnitName, ResourceUnit>(1);
216
217                int cpuRequest;
218                try {
219                        cpuRequest = Double.valueOf(task.getCpuCntRequest()).intValue();
220                } catch (NoSuchFieldException e) {
221                        cpuRequest = 0;
222                }
223
224                List<Node> filteredNodes = filterNodes(nodes, task);
225                if(filteredNodes.size()==0)
226                        return null;
227                Node node = chooseRandomNode(filteredNodes);
228                while(node.getFreeCores().size() < cpuRequest){
229                        node = chooseRandomNode(nodes);
230                }
231               
232                if (cpuRequest != 0) {
233
234                        if (node.getFreeCores().size() < cpuRequest) {
235                                return null;
236                        }
237
238                        List<Processor>  processors = node.getProcessors();
239                        List<Core> cores = node.getCores();
240                        List<ComputingResource> choosenResources = new ArrayList<ComputingResource>(cpuRequest);                               
241                        for (int i = 0; i < cores.size() && cpuRequest > 0; i++) {
242                                if (cores.get(i).getStatus() == ResourceStatus.FREE) {
243                                        choosenResources.add(cores.get(i));
244                                        cpuRequest--;
245                                }
246                        }
247                        if (cpuRequest > 0) {
248                                return null;
249                        }
250
251                        ProcessingElements pe = new ProcessingElements();
252                        pe.addAll(choosenResources);
253                        map.put(StandardResourceUnitName.PE, pe);
254                        return map;
255                }
256
257                return null;
258        }
259
260       
261        private List<Node> filterNodes(List<Node> nodes, TaskInterface<?> task){
262                List<Node> filteredNodes = new ArrayList<Node>();
263                int cpuRequest;
264                try {
265                        cpuRequest = Double.valueOf(task.getCpuCntRequest()).intValue();
266                } catch (NoSuchFieldException e) {
267                        cpuRequest = 0;
268                }
269                for (Node node : nodes) {
270
271                        if (cpuRequest != 0) {
272
273                                List<Core> cores = node.getCores();
274                                if (cores.size() < cpuRequest) {
275                                        if(cores.size() == 0){
276                                                if(node.getProcessors().size() < cpuRequest)
277                                                        continue;
278                                        }
279                                }
280
281                                int freeCores = 0;
282                                for(Core core: cores){
283                                        if(core.getStatus() == ResourceStatus.FREE)
284                                                freeCores++;
285                                }
286                               
287                                if(freeCores < cpuRequest)
288                                        continue;
289                               
290                                filteredNodes.add(node);
291                        }
292                }
293               
294                return filteredNodes;
295        }
296       
297
298        private Node chooseRandomNode(List<Node> nodes) {
299                int nodeIdx = rand.nextInt(nodes.size());
300                return nodes.get(nodeIdx);
301        }
302
303
304}
305
Note: See TracBrowser for help on using the repository browser.