source: DCWoRMS/branches/coolemall/src/test/thermal/recs/plugins/scheduling/RecsExclusivenessTempIncrOptSP.java @ 1399

Revision 1399, 7.5 KB checked in by wojtekp, 11 years ago (diff)
  • Property svn:mime-type set to text/plain
Line 
1package test.thermal.recs.plugins.scheduling;
2
3import gridsim.dcworms.DCWormsTags;
4
5import java.io.FileInputStream;
6import java.io.FileNotFoundException;
7import java.io.IOException;
8import java.util.ArrayList;
9import java.util.Collections;
10import java.util.Comparator;
11import java.util.HashMap;
12import java.util.List;
13import java.util.Map;
14import java.util.MissingResourceException;
15import java.util.PropertyResourceBundle;
16import java.util.ResourceBundle;
17
18import schedframe.events.scheduling.SchedulingEvent;
19import schedframe.resources.ResourceStatus;
20import schedframe.resources.computing.Node;
21import schedframe.resources.computing.ComputingResource;
22import schedframe.resources.computing.Core;
23import schedframe.resources.computing.Processor;
24import schedframe.resources.computing.profiles.energy.power.StandardPowerStateName;
25import schedframe.resources.units.ProcessingElements;
26import schedframe.resources.units.ResourceUnit;
27import schedframe.resources.units.ResourceUnitName;
28import schedframe.resources.units.StandardResourceUnitName;
29import schedframe.scheduling.manager.resources.ClusterResourceManager;
30import schedframe.scheduling.manager.resources.ResourceManager;
31import schedframe.scheduling.manager.tasks.JobRegistry;
32import schedframe.scheduling.plan.SchedulingPlanInterface;
33import schedframe.scheduling.plan.impl.SchedulingPlan;
34import schedframe.scheduling.plugin.ModuleList;
35import schedframe.scheduling.queue.TaskQueue;
36import schedframe.scheduling.queue.TaskQueueList;
37import schedframe.scheduling.tasks.TaskInterface;
38import test.thermal.recs.utils.AppType;
39import test.thermal.recs.plugins.energy.ThermalConstants;
40
41public class RecsExclusivenessTempIncrOptSP extends RecsSP {
42
43        private static String TIME_DATA_FILE_NAME = "src/test/thermal/recs/data/time_data.properties";
44        private static String POWER_DATA_FILE_NAME = "src/test/thermal/recs/data/power_data.properties";
45       
46        private ResourceBundle powBundle;
47        private ResourceBundle timeBundle;
48       
49        public SchedulingPlanInterface<?> schedule(SchedulingEvent event, TaskQueueList queues, JobRegistry jobRegistry,
50                        ResourceManager resManager, ModuleList modules) {
51
52                ClusterResourceManager resourceManager = (ClusterResourceManager) resManager;
53                SchedulingPlan plan = new SchedulingPlan();
54                // choose the events types to serve.
55                // Different actions for different events are possible.
56                switch (event.getType()) {
57                case START_TASK_EXECUTION:
58                case TASK_FINISHED:
59                //case TIMER:
60                        // our tasks are placed only in first queue (see BaseLocalSchedulingPlugin.placeJobsInQueues() method)
61                        TaskQueue q = queues.get(0);
62                        // check all tasks in queue
63
64                        for (int i = 0; i < q.size(); i++) {
65                                TaskInterface<?> task = q.get(i);
66                                initApplicationType(task);
67                               
68                                // if status of the tasks in READY
69                                if (task.getStatus() == DCWormsTags.READY) {
70                                        Map<ResourceUnitName, ResourceUnit> choosenResources = chooseResourcesForExecution(resourceManager, task);
71                                        if (choosenResources != null) {
72                                                addToSchedulingPlan(plan, task, choosenResources);
73                                        }
74                                }
75                        }
76
77                        break;
78                }
79                return plan;
80        }
81
82        private Map<ResourceUnitName, ResourceUnit> chooseResourcesForExecution(
83                        ClusterResourceManager resourceManager, TaskInterface<?> task) {
84
85                Map<ResourceUnitName, ResourceUnit> map;
86                List<Node> nodes = resourceManager.getNodes();
87                Collections.shuffle(nodes);
88                Collections.sort(nodes, new TemperatureComparator(task));
89                for (Node node : nodes) {
90                        int cpuRequest;
91                        try {
92                                cpuRequest = Double.valueOf(task.getCpuCntRequest()).intValue();
93                        } catch (NoSuchFieldException e) {
94                                cpuRequest = 0;
95                        }
96
97                        if (cpuRequest != 0) {
98
99                                List<Core> cores = node.getProcessors().get(0).getCores();
100                                if (cores.size() < cpuRequest/* || node.getProcessors().get(0).filterDescendants(properties).size() != cores.size()*/) {
101                                        continue;
102                                }
103
104                                int freeCores = 0;
105                                for(Core core: cores){
106                                        if(core.getStatus() == ResourceStatus.FREE)
107                                                freeCores++;
108                                }
109                               
110                                if(freeCores != cores.size())
111                                        continue;
112                               
113                                try {
114                                        if(!getExecutiveness(createExecutivenessQuery(task, node)))
115                                                continue;
116                                } catch (FileNotFoundException e) {
117                                        continue;
118                                } catch (IOException e) {
119                                        continue;
120                                } catch (MissingResourceException e){
121                                        continue;
122                                }
123                               
124                                List<ComputingResource> choosenResources = new ArrayList<ComputingResource>();                         
125                                for (int i = 0; i < cores.size(); i++) {
126                                        if (cores.get(i).getStatus() == ResourceStatus.FREE) {
127                                                //choosenResources.add(cores.get(i));
128                                                cpuRequest--;
129                                        }
130                                }
131                                choosenResources.add(node);
132                                if (cpuRequest > 0) {
133                                        //continue;
134                                }
135                                map = new HashMap<ResourceUnitName, ResourceUnit>();
136                                ProcessingElements pe = new ProcessingElements();
137                                pe.addAll(choosenResources);
138                                map.put(StandardResourceUnitName.PE, pe);
139                                return map;
140
141                        }
142                }
143       
144                return null;
145        }
146       
147        protected String createQuery(TaskInterface<?> task, Node node) {
148                String query;
149                query = getApplicationType(task) + "." + getNodeCategory(node) + "." + getFrequency(node) + "." + getCoreCnt(task);
150                return query;
151        }
152       
153        protected double getMeasuredPower(String query) throws FileNotFoundException, IOException{
154                ResourceBundle powBundle = getPowBundle();
155                return Double.valueOf(powBundle.getString(query)).doubleValue();
156        }
157       
158        private ResourceBundle getPowBundle() throws FileNotFoundException, IOException{
159                if(powBundle == null){
160                         powBundle = new PropertyResourceBundle(new FileInputStream(POWER_DATA_FILE_NAME));
161                }
162                return powBundle;
163        }
164       
165        protected double getMeasuredTime(String query) throws FileNotFoundException, IOException{
166                ResourceBundle timeBundle = getTimeBundle();
167                return Double.valueOf(timeBundle.getString(query)).doubleValue();
168        }
169
170        private ResourceBundle getTimeBundle() throws FileNotFoundException, IOException{
171                if(timeBundle == null){
172                        timeBundle = new PropertyResourceBundle(new FileInputStream(TIME_DATA_FILE_NAME));
173                }
174                return timeBundle;
175        }
176       
177        class TemperatureComparator implements Comparator<Node>{
178                private TaskInterface<?> task;
179               
180                public TemperatureComparator(TaskInterface<?> task){
181                        this.task = task;
182                }
183               
184            public int compare(Node node1, Node node2){   
185               
186                double power1 = 0;
187                double power2 = 0;
188                try{
189                        power1 = Math.abs(getMeasuredPower(createQuery(task, node1)) - node1.getPowerInterface().getPowerConsumption(StandardPowerStateName.ON));
190                        power2 = Math.abs(getMeasuredPower(createQuery(task, node2)) - node2.getPowerInterface().getPowerConsumption(StandardPowerStateName.ON));
191                } catch (FileNotFoundException e) {
192       
193                        } catch (IOException e) {
194       
195                        } catch (MissingResourceException e){
196                               
197                } catch (NoSuchFieldException e) {
198
199                }
200               
201                Integer id1 = Integer.parseInt(node1.getName().split("_")[1]);
202                Integer id2 = Integer.parseInt(node2.getName().split("_")[1]);
203               
204                double deltaOne = 1, deltaTwo = 1;
205                if (id1 >= 1 && id1 <= 9) // outlet
206                        deltaOne = ThermalConstants.delta2;
207                else if (id1 >= 10 && id1 <= 18) // inlet
208                        deltaOne = ThermalConstants.delta1;
209                if (id2 >= 1 && id2 <= 9) // outlet
210                        deltaTwo = ThermalConstants.delta2;
211                else if (id2 >= 10 && id2 <= 18) // inlet
212                        deltaTwo = ThermalConstants.delta1;
213               
214                double extraNode1Temp =  deltaOne * (power1/(ThermalConstants.Q * ThermalConstants.C * ThermalConstants.ro));
215                double extraNode2Temp =  deltaTwo * (power2/(ThermalConstants.Q * ThermalConstants.C * ThermalConstants.ro));
216               
217                if (extraNode1Temp > extraNode2Temp)
218                                return 1;
219                        else if (extraNode1Temp < extraNode2Temp)
220                                return -1;
221                        else
222                                return 0;
223           
224            }
225        }
226}
Note: See TracBrowser for help on using the repository browser.