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

Revision 1593, 14.3 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_RandomPluginFansMngDynamicFuture extends BaseLocalSchedulingPlugin {
41
42
43        private Random rand;
44       
45        public FCFSBF_RandomPluginFansMngDynamicFuture() {
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                       
102                double Tin = EnvironmentConditions.ROOM_TEMPERATURE;
103                double Pcpu = cr.getPowerInterface().getRecentPowerUsage().getValue();
104               
105               
106               
107                /*************/
108               
109                double R = 0;
110                double Rb = 0;
111                double Rcv = 0;
112                try{
113                        Rb = Double.valueOf(cr.getPowerInterface().getParameters().get("thermalResistance").get(0).getContent()).doubleValue();
114                } catch (Exception e){
115                        //
116                }
117               
118                double k = 0;
119                try{
120                        k = Double.valueOf(cr.getPowerInterface().getParameters().get("k").get(0).getContent()).doubleValue();
121                } catch (Exception e){
122                        //
123                }
124               
125                double a = 0;
126                try{
127                        a = Double.valueOf(cr.getPowerInterface().getParameters().get("a").get(0).getContent()).doubleValue();
128                } catch (Exception e){
129                        a = 1;
130                }
131
132                double V = 0;
133       
134                //System.out.println("------ " + cr.getFullName());
135                for(Device device: cr.getParent().getParent().getResourceCharacteristic().getDevices()){
136                        if(device.getType().equals(StandardResourceType.Fan)){
137                                int fanId = Integer.valueOf(device.getName().split("_")[1]).intValue();
138                                int nodeId = Integer.valueOf(cr.getParent().getName().split("_")[1]).intValue();
139                                //System.out.println(device.getName() + "; " + cpu.getParent().getName());
140                                //System.out.println(fanId + "; " + cpuId);
141                                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*/){
142                                        //System.out.println("********");
143                                        Fan fan = (Fan) device;
144                                        V = fan.getAirflowInterface().getRecentAirflow().getValue();
145                                        break;
146                                }
147                        }
148                }
149                //System.out.println("V: " + V);
150                Rcv =  1/ (k * Math.pow(V, a));
151                R = Rb + Rcv;
152                double C = 0;
153                try{
154                        C = Double.valueOf(cr.getPowerInterface().getParameters().get("thermalCapacity").get(0).getContent()).doubleValue();
155                } catch (Exception e){
156                        //
157                }
158               
159               
160               
161                double objective_temperature =  Pcpu * R + Tin;
162               
163               
164               
165               
166                double delta_t = 15;
167               
168                /*************/
169               
170                double nextTemp = objective_temperature - (objective_temperature - temp) * Math.exp(-delta_t/(R * C));
171               
172                if(cr.getThermalInterface().getTemperatureHistory().size() == 1)
173                        prevTemp = temp;
174                else {
175                        prevTemp = cr.getThermalInterface().getTemperatureHistory().get(cr.getThermalInterface().getTemperatureHistory().size() - 2).getValue();
176                }
177                //System.out.println(Sim_system.clock() + "; " + prevTemp +": " +temp + ": " + objective_temperature + ": " + nextTemp+"; " + Pcpu);
178
179                //System.out.println(Sim_system.clock() + " === " + prevTemp+  ";  " + temp);
180                boolean getingHotter = prevTemp < temp;
181                boolean getingColder = prevTemp > temp;
182                Node n = (Node) cr.getParent();
183                List<ComputingResource> neighbours = n.getParent().getChildren();
184                for(Device d: n.getParent().getResourceCharacteristic().getDevices()){
185                        //System.out.println(d.getName() + "; " + n.getName());
186                        int fanId = Integer.valueOf(d.getName().split("_")[1]).intValue();
187                        int nodeId = Integer.valueOf(n.getName().split("_")[1]).intValue();
188                        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*/){
189                                Fan f = (Fan) d;
190                                int speed;
191                                try{
192                                        speed= Integer.valueOf(f.getAirflowInterface().getAirflowState().getLabel().split("_")[1]).intValue();
193                                } catch(Exception e){
194                                        speed = 0;
195                                }
196                                for(ComputingResource neighbour: neighbours){
197                                        int neighbourId = Integer.valueOf(neighbour.getName().split("_")[1]).intValue();
198                                        if(neighbourId > (fanId - 1) * EnvironmentConditions.NODES_IN_A_COLUMN && neighbourId <= fanId * EnvironmentConditions.NODES_IN_A_COLUMN){
199                                                double neighbourTemp = neighbour.getChildren().get(0).getThermalInterface().getRecentTemperature().getValue();
200                                                if(neighbourTemp > temp){
201                                                        return;
202                                                }
203                                        }
204                                }
205                               
206                                //System.out.println("getingHotter: "+ (prevTemp < temp));
207                                if(getingHotter){
208                                        if(nextTemp > temp)
209                                        temp = nextTemp;
210                                        if(temp > EnvironmentConditions._30_2_40- EnvironmentConditions.tempShift && temp < EnvironmentConditions._40_2_50- EnvironmentConditions.tempShift ){
211                                                if(speed < 40){
212                                                        //System.out.println("+++++++++ 30 to 40");
213                                                        f.getAirflowInterface().setAirflowState(new CustomAirflowStateName("ON_40"));
214                                                }
215                                        } else if(temp > EnvironmentConditions._40_2_50- EnvironmentConditions.tempShift && temp < EnvironmentConditions._50_2_60- EnvironmentConditions.tempShift ){
216                                                if(speed < 50){
217                                                        //System.out.println("++++++++ 40 to 50");
218                                                        f.getAirflowInterface().setAirflowState(new CustomAirflowStateName("ON_50"));
219                                                }
220                                        } else if(temp > EnvironmentConditions._50_2_60- EnvironmentConditions.tempShift && temp < EnvironmentConditions._60_2_70- EnvironmentConditions.tempShift ){
221                                                if(speed < 60){
222                                                //System.out.println("++++++++ 50 to 60");
223                                                        f.getAirflowInterface().setAirflowState(new CustomAirflowStateName("ON_60"));
224                                                }
225                                        } else if(temp > EnvironmentConditions._60_2_70- EnvironmentConditions.tempShift && temp < EnvironmentConditions._70_2_80- EnvironmentConditions.tempShift ){
226                                                if(speed < 70){
227                                                        //System.out.println("++++++++ 60 to 70");
228                                                        f.getAirflowInterface().setAirflowState(new CustomAirflowStateName("ON_70"));
229                                                }
230                                        } else if(temp > EnvironmentConditions._70_2_80- EnvironmentConditions.tempShift && temp < EnvironmentConditions._80_2_90- EnvironmentConditions.tempShift ){
231                                                if(speed < 80){
232                                                        //System.out.println("++++++++ 70 to 80");
233                                                        f.getAirflowInterface().setAirflowState(new CustomAirflowStateName("ON_80"));
234                                                }
235                                        } else if(temp > EnvironmentConditions._80_2_90- EnvironmentConditions.tempShift && temp < EnvironmentConditions._90_2_100- EnvironmentConditions.tempShift ){
236                                                if(speed < 90){
237                                                        //System.out.println("++++++++ 80 to 90");
238                                                        f.getAirflowInterface().setAirflowState(new CustomAirflowStateName("ON_90"));
239                                                }
240                                        } else if(temp > EnvironmentConditions._90_2_100- EnvironmentConditions.tempShift ){
241                                                if(speed < 100){
242                                                        //System.out.println("++++++++ 90 to 100");
243                                                        f.getAirflowInterface().setAirflowState(new CustomAirflowStateName("ON_100"));
244                                                }
245                                        }                                               
246                                } else if (getingColder){
247                                        if(temp > EnvironmentConditions._90_2_80 && temp < EnvironmentConditions._100_2_90){
248                                                if(speed == 100){
249                                                        //System.out.println("-------- 100 to 90");
250                                                        f.getAirflowInterface().setAirflowState(new CustomAirflowStateName("ON_90"));
251                                                }
252                                        } else if(temp > EnvironmentConditions._80_2_70 && temp < EnvironmentConditions._90_2_80){
253                                                if(speed >= 90){
254                                                        //System.out.println("-------- 90 to 80");
255                                                        f.getAirflowInterface().setAirflowState(new CustomAirflowStateName("ON_80"));           
256                                                }
257                                        } else if(temp > EnvironmentConditions._70_2_60 && temp < EnvironmentConditions._80_2_70){
258                                                if(speed >= 80){
259                                                        //System.out.println("-------- 80 to 70");
260                                                        f.getAirflowInterface().setAirflowState(new CustomAirflowStateName("ON_70"));           
261                                                }
262                                        } else if(temp > EnvironmentConditions._60_2_50 && temp < EnvironmentConditions._70_2_60){
263                                                if(speed >= 70){
264                                                        //System.out.println("-------- 70 to 60");
265                                                        f.getAirflowInterface().setAirflowState(new CustomAirflowStateName("ON_60"));           
266                                                }
267                                        } else if(temp > EnvironmentConditions._50_2_40 && temp < EnvironmentConditions._60_2_50){
268                                                if(speed >= 60){
269                                                        //System.out.println("-------- 60 to 50");
270                                                        f.getAirflowInterface().setAirflowState(new CustomAirflowStateName("ON_50"));           
271                                                }
272                                        } else if(temp > EnvironmentConditions._40_2_30 && temp < EnvironmentConditions._50_2_40){
273                                                if(speed >= 50){
274                                                        //System.out.println("-------- 60 to 40");
275                                                        f.getAirflowInterface().setAirflowState(new CustomAirflowStateName("ON_40"));           
276                                                }
277                                        }  else if (temp < EnvironmentConditions._40_2_30) {
278                                                if(speed >= 40){
279                                                        //System.out.println("-------- 40 to 30");
280                                                        f.getAirflowInterface().setAirflowState(new CustomAirflowStateName("ON_30"));   
281                                                }
282                                        }
283                                }
284                        }
285                }
286        }
287        private Map<ResourceUnitName, ResourceUnit> chooseResourcesForExecution(
288                        List<Node> nodes, TaskInterface<?> task) {
289
290                Map<ResourceUnitName, ResourceUnit> map = new HashMap<ResourceUnitName, ResourceUnit>(1);
291
292                int cpuRequest;
293                try {
294                        cpuRequest = Double.valueOf(task.getCpuCntRequest()).intValue();
295                } catch (NoSuchFieldException e) {
296                        cpuRequest = 0;
297                }
298
299                List<Node> filteredNodes = filterNodes(nodes, task);
300                if(filteredNodes.size()==0)
301                        return null;
302                Node node = chooseRandomNode(filteredNodes);
303                while(node.getFreeCores().size() < cpuRequest){
304                        node = chooseRandomNode(nodes);
305                }
306               
307                if (cpuRequest != 0) {
308
309                        if (node.getFreeCores().size() < cpuRequest) {
310                                return null;
311                        }
312
313                        List<Processor>  processors = node.getProcessors();
314                        List<Core> cores = node.getCores();
315                        List<ComputingResource> choosenResources = new ArrayList<ComputingResource>(cpuRequest);                               
316                        for (int i = 0; i < cores.size() && cpuRequest > 0; i++) {
317                                if (cores.get(i).getStatus() == ResourceStatus.FREE) {
318                                        choosenResources.add(cores.get(i));
319                                        cpuRequest--;
320                                }
321                        }
322                        if (cpuRequest > 0) {
323                                return null;
324                        }
325
326                        ProcessingElements pe = new ProcessingElements();
327                        pe.addAll(choosenResources);
328                        map.put(StandardResourceUnitName.PE, pe);
329                        return map;
330                }
331
332                return null;
333        }
334
335       
336        private List<Node> filterNodes(List<Node> nodes, TaskInterface<?> task){
337                List<Node> filteredNodes = new ArrayList<Node>();
338                int cpuRequest;
339                try {
340                        cpuRequest = Double.valueOf(task.getCpuCntRequest()).intValue();
341                } catch (NoSuchFieldException e) {
342                        cpuRequest = 0;
343                }
344                for (Node node : nodes) {
345
346                        if (cpuRequest != 0) {
347
348                                List<Core> cores = node.getCores();
349                                if (cores.size() < cpuRequest) {
350                                        if(cores.size() == 0){
351                                                if(node.getProcessors().size() < cpuRequest)
352                                                        continue;
353                                        }
354                                }
355
356                                int freeCores = 0;
357                                for(Core core: cores){
358                                        if(core.getStatus() == ResourceStatus.FREE)
359                                                freeCores++;
360                                }
361                               
362                                if(freeCores < cpuRequest)
363                                        continue;
364                               
365                                filteredNodes.add(node);
366                        }
367                }
368               
369                return filteredNodes;
370        }
371       
372
373        private Node chooseRandomNode(List<Node> nodes) {
374                int nodeIdx = rand.nextInt(nodes.size());
375                return nodes.get(nodeIdx);
376        }
377
378
379}
380
Note: See TracBrowser for help on using the repository browser.