Ignore:
Timestamp:
03/04/13 08:25:34 (12 years ago)
Author:
wojtekp
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • DCWoRMS/branches/coolemall/src/schedframe/scheduling/policy/local/LocalManagementSystem.java

    r822 r896  
    164164                        break; 
    165165                         
    166                 case DCWormsTags.PHASE_CHANGED: 
     166                case DCWormsTags.TASK_EXECUTION_CHANGED: 
    167167                        execTask = (ExecTask) ev.get_data(); 
    168                         //updatePhases(execTask); 
     168                        updateTaskExecution(execTask, SchedulingEventType.RESOURCE_STATE_CHANGED); 
    169169                        break; 
    170170                } 
     
    224224                removeFromQueue(task); 
    225225 
    226                 SchedulingEvent event = new SchedulingEvent(SchedulingEventType.START_TASK_EXECUTION); 
    227                 int time = Double.valueOf( 
    228                                 execTimeEstimationPlugin.execTimeEstimation(event, task, choosenResources, exec.getCompletionPercentage())).intValue(); 
    229                 log.debug(task.getJobId() + "_" + task.getId() + " starts executing on " + new DateTime() 
    230                                 + " will finish after " + time); 
    231  
    232                 if (time < 0.0) 
    233                         return; 
    234  
    235                 exec.setEstimatedDuration(time); 
     226                log.debug(task.getJobId() + "_" + task.getId() + " starts executing on " + new DateTime()); 
     227 
     228                //if (phaseDuration < 0.0) 
     229                //      return; 
     230 
     231                //exec.setEstimatedDuration(exec.getEstimatedDuration() + phaseDuration); 
    236232                DateTime currentTime = new DateTime(); 
    237233                ResourceHistoryItem resHistItem = new ResourceHistoryItem(choosenResources, currentTime); 
    238234                exec.addUsedResources(resHistItem); 
     235                 
    239236                try { 
    240237                        exec.setStatus(DCWormsTags.INEXEC); 
     
    244241                } 
    245242                 
    246                 //updatePhases(exec); 
    247                 scheduler.sendInternal(time, DCWormsTags.TASK_EXECUTION_FINISHED, exec); 
     243                updateTaskExecution(exec, SchedulingEventType.START_TASK_EXECUTION); 
     244                //scheduler.sendInternal(time, DCWormsTags.TASK_EXECUTION_FINISHED, exec); 
    248245 
    249246                try { 
     
    251248                        scheduler.sendInternal(expectedDuration, DCWormsTags.TASK_REQUESTED_TIME_EXPIRED, exec); 
    252249                } catch (NoSuchFieldException e) { 
    253                         double t = exec.getEstimatedDuration(); 
    254                         scheduler.sendInternal(t, DCWormsTags.TASK_REQUESTED_TIME_EXPIRED, exec); 
     250                        //double t = exec.getEstimatedDuration(); 
     251                        //scheduler.sendInternal(t, DCWormsTags.TASK_REQUESTED_TIME_EXPIRED, exec); 
    255252                } 
    256253 
     
    261258                notifyComputingResources(peUnit, EnergyEventType.TASK_STARTED, exec); 
    262259                 
    263                 /*if(peUnit instanceof ProcessingElements){ 
    264                         ProcessingElements pes = (ProcessingElements) peUnit; 
    265                         for (ComputingResource resource : pes) { 
    266                                 resource.handleEvent(new EnergyEvent(EnergyEventType.TASK_STARTED, exec)); 
    267                         } 
    268                 } else { 
    269                         ComputingResource resource = null; 
    270                         try { 
    271                                 resource = ResourceController.getComputingResourceByName(peUnit.getResourceId()); 
    272                         } catch (ResourceException e) { 
    273                                 return; 
    274                         } 
    275                         resource.handleEvent(new EnergyEvent(EnergyEventType.TASK_STARTED, exec)); 
    276                 } 
    277 */ 
    278  
    279                 /*for(ExecTaskInterface etask : jobRegistry.getRunningTasks()){ 
    280                         System.out.println(etask.getJobId()); 
    281                         for(String taskId: etask.getVisitedResources()) 
    282                                 System.out.println("====="+taskId); 
    283                 }*/ 
    284260        } 
    285261         
     
    323299                PEUnit peUnit = (PEUnit)lastUsed.get(StandardResourceUnitName.PE); 
    324300                notifyComputingResources(peUnit, EnergyEventType.TASK_FINISHED, exec); 
    325                 /*if(peUnit instanceof ProcessingElements){ 
    326                         ProcessingElements pes = (ProcessingElements) peUnit; 
    327                         for (ComputingResource resource : pes) { 
    328                                 resource.handleEvent(new EnergyEvent(EnergyEventType.TASK_FINISHED, exec)); 
    329                         } 
    330                 } else { 
    331                         ComputingResource resource = null; 
    332                         try { 
    333                                 resource = ResourceController.getComputingResourceByName(peUnit.getResourceId()); 
    334                         } catch (ResourceException e) { 
    335                                 return; 
    336                         } 
    337                         resource.handleEvent(new EnergyEvent(EnergyEventType.TASK_FINISHED, exec)); 
    338                 }*/ 
    339  
    340                 //sendFinishedWorkloadUnit(executable); 
    341301        } 
    342302         
     
    353313                        Executable exec = (Executable)task; 
    354314                        //exec.setCompletionPercentage(exec.getCompletionPercentage() + 100 * timeSpan/exec.getEstimatedDuration()); 
    355                         exec.setCompletionPercentage(exec.getCompletionPercentage() + (100 - exec.getCompletionPercentage()) * timeSpan/(exec.getEstimatedDuration() - new DateTime().getMillis()/1000 + exec.getExecStartTime() + timeSpan)); 
    356                          
     315                        exec.setCompletionPercentage(exec.getCompletionPercentage() + 100 * (timeSpan / exec.getEstimatedDuration())); 
    357316                        UsedResourcesList usedResourcesList = exec.getUsedResources(); 
    358317                        PEUnit peUnit = (PEUnit)usedResourcesList.getLast().getResourceUnits() 
     
    364323         
    365324        private void notifyComputingResources(PEUnit peUnit, EnergyEventType eventType, Object obj){ 
    366  
    367325                if(peUnit instanceof ProcessingElements){ 
    368326                        ProcessingElements pes = (ProcessingElements) peUnit; 
     
    409367                for (ExecTask execTask : jobRegistry.getRunningTasks()) { 
    410368                        Executable exec = (Executable)execTask; 
    411                         List<String> visitedResource = exec.getVisitedResources(); 
    412                         String originResource = ev.get_data().toString(); 
    413                         if(!ArrayUtils.contains(visitedResource.toArray(new String[visitedResource.size()]), originResource)){ 
    414                                 continue; 
    415                         } 
    416                          
     369 
    417370                        Map<ResourceUnitName, ResourceUnit> choosenResources = exec.getUsedResources().getLast().getResourceUnits(); 
    418                         int time = Double.valueOf(execTimeEstimationPlugin.execTimeEstimation(new SchedulingEvent(SchedulingEventType.RESOURCE_STATE_CHANGED),  
     371                        double lastTimeStamp = exec.getUsedResources().getLast().getTimeStamp().getMillis()/1000; 
     372                        int phaseDuration = Double.valueOf(execTimeEstimationPlugin.execTimeEstimation(new SchedulingEvent(SchedulingEventType.RESOURCE_STATE_CHANGED),  
    419373                                        execTask, choosenResources, exec.getCompletionPercentage())).intValue(); 
    420374 
    421                         //check if the new estimated end time is equal to the previous one; if yes the continue without update 
    422                         if(DoubleMath.subtract((exec.getExecStartTime() + exec.getEstimatedDuration()), (new DateTime().getMillis()/1000 + time)) == 0.0){ 
    423                                 continue; 
    424                         } 
    425                         //exec.setEstimatedDuration(time); 
    426                         exec.setEstimatedDuration(Long.valueOf(new DateTime().getMillis()/1000).intValue() - Double.valueOf(exec.getExecStartTime()).intValue() + time); 
    427                         ExecTaskFilter filter = new ExecTaskFilter(exec.getUniqueId(), DCWormsTags.TASK_EXECUTION_FINISHED); 
    428                         scheduler.sim_cancel(filter, null); 
    429                         scheduler.sendInternal(time, DCWormsTags.TASK_EXECUTION_FINISHED, execTask); 
     375                        if(DoubleMath.subtract((lastTimeStamp + exec.getEstimatedDuration()), (new DateTime().getMillis()/1000 + phaseDuration)) == 0.0){ 
     376                                return; 
     377                        } 
     378 
     379                        exec.setEstimatedDuration(phaseDuration); 
     380                        DateTime currentTime = new DateTime(); 
     381                        ResourceHistoryItem resHistItem = new ResourceHistoryItem(choosenResources, currentTime); 
     382                        exec.addUsedResources(resHistItem); 
     383                         
     384                        if(exec.getResourceConsumptionProfile().getCurrentResourceConsumption() == exec.getResourceConsumptionProfile().getResourceConsumptionList().getLast()){ 
     385                                ExecTaskFilter filter = new ExecTaskFilter(exec.getUniqueId(), DCWormsTags.TASK_EXECUTION_FINISHED); 
     386                                scheduler.sim_cancel(filter, null); 
     387                                scheduler.sendInternal(phaseDuration , DCWormsTags.TASK_EXECUTION_FINISHED, execTask); 
     388                                PEUnit peUnit = (PEUnit)exec.getUsedResources().getLast().getResourceUnits().get(StandardResourceUnitName.PE); 
     389                                notifyComputingResources(peUnit, EnergyEventType.RESOURCE_UTILIZATION_CHANGED, exec); 
     390                        } else{ 
     391                                ExecTaskFilter filter = new ExecTaskFilter(exec.getUniqueId(), DCWormsTags.TASK_EXECUTION_CHANGED); 
     392                                scheduler.sim_cancel(filter, null); 
     393                                scheduler.sendInternal(phaseDuration, DCWormsTags.TASK_EXECUTION_CHANGED, execTask); 
     394                                PEUnit peUnit = (PEUnit)exec.getUsedResources().getLast().getResourceUnits().get(StandardResourceUnitName.PE); 
     395                                notifyComputingResources(peUnit, EnergyEventType.RESOURCE_UTILIZATION_CHANGED, exec); 
     396                        } 
    430397                } 
    431398        }        
    432          
    433          
    434         /*protected void updatePhases(ExecTask execTask) { 
    435                 updateProcessingProgress(); 
     399 
     400        protected void updateTaskExecution(ExecTask execTask, SchedulingEventType schedEvType) { 
    436401 
    437402                if (execTask.getStatus() == DCWormsTags.INEXEC) { 
    438403                        Executable exec = (Executable)execTask; 
    439  
    440                         double phaseLength = 0; 
    441                         try{ 
    442                                 phaseLength = exec.getResourceConsumptionProfile().getResourceConsumption(exec.getCurrentPhase()).getResourceConsumptionTypeChoice().getPercentage()/100; 
    443                         } catch(Exception e){ 
    444                                 ExecTaskFilter filter = new ExecTaskFilter(exec.getUniqueId(), DCWormsTags.TASK_EXECUTION_FINISHED); 
    445                                 scheduler.sim_cancel(filter, null); 
    446                                 double t = DoubleMath.subtract((exec.getExecStartTime() + exec.getEstimatedDuration()), (new DateTime().getMillis()/1000)); 
    447                                 scheduler.sendInternal(t, DCWormsTags.TASK_EXECUTION_FINISHED, execTask); 
    448                                 PEUnit peUnit = (PEUnit)exec.getUsedResources().getLast().getResourceUnits().get(StandardResourceUnitName.PE); 
    449                                 notifyComputingResources(peUnit, EnergyEventType.RESOURCE_UTILIZATION_CHANGED, exec); 
    450                         } 
    451                         if(phaseLength != 0){                    
    452                                 exec.setCurrentPhase(exec.getCurrentPhase() + 1); 
    453                                 ExecTaskFilter filter = new ExecTaskFilter(exec.getUniqueId(), DCWormsTags.PHASE_CHANGED); 
    454                                 scheduler.sim_cancel(filter, null); 
    455                                 scheduler.sendInternal(phaseLength * exec.getEstimatedDuration(), DCWormsTags.PHASE_CHANGED, execTask); 
    456                                 PEUnit peUnit = (PEUnit)exec.getUsedResources().getLast().getResourceUnits().get(StandardResourceUnitName.PE); 
    457                                 notifyComputingResources(peUnit, EnergyEventType.RESOURCE_UTILIZATION_CHANGED, exec); 
    458                         }  
    459                         System.out.println("===" + exec.getJobId() + ":" + phaseLength); 
    460                 } 
    461         }       */ 
     404                         
     405                        try { 
     406                                exec.setStatus(DCWormsTags.NEW_EXEC_PHASE); 
     407                        } catch (Exception e) { 
     408                        } 
     409                         
     410                        Map<ResourceUnitName, ResourceUnit> choosenResources = exec.getUsedResources().getLast().getResourceUnits(); 
     411 
     412                        int phaseDuration = Double.valueOf(execTimeEstimationPlugin.execTimeEstimation(new SchedulingEvent(schedEvType),  
     413                                        execTask, choosenResources, exec.getCompletionPercentage())).intValue(); 
     414 
     415                        exec.setEstimatedDuration(phaseDuration); 
     416                         
     417                        if(exec.getResourceConsumptionProfile().getCurrentResourceConsumption() == exec.getResourceConsumptionProfile().getResourceConsumptionList().getLast()){ 
     418                                scheduler.sendInternal(phaseDuration, DCWormsTags.TASK_EXECUTION_FINISHED, execTask); 
     419                        } else { 
     420                                scheduler.sendInternal(phaseDuration, DCWormsTags.TASK_EXECUTION_CHANGED, execTask); 
     421                        } 
     422                } 
     423        }        
    462424 
    463425        public double calculateTotalLoad(int size) { 
Note: See TracChangeset for help on using the changeset viewer.