- Timestamp:
- 08/07/09 16:50:07 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.CEDMA.Server/3.3/GridExecuter.cs
r2223 r2258 44 44 45 45 private TimeSpan StartJobInterval { 46 get { return TimeSpan.FromMilliseconds( 500); }46 get { return TimeSpan.FromMilliseconds(3000); } 47 47 } 48 48 … … 51 51 } 52 52 53 private TimeSpan WaitForNewJobsInterval { 54 get { return TimeSpan.FromSeconds(3); } 55 } 56 57 public GridExecuter(IDispatcher dispatcher, IGridServer server, IModelingDatabase databaseService) 53 public GridExecuter(IDispatcher dispatcher, IGridServer server, IModelingDatabase databaseService) 58 54 : base(dispatcher, databaseService) { 59 55 this.jobManager = new JobManager(server); … … 64 60 protected override void StartJobs() { 65 61 Dictionary<WaitHandle, AsyncGridResult> asyncResults = new Dictionary<WaitHandle, AsyncGridResult>(); 62 // inifinite loop: 63 // 1. try to dispatch one algo 64 // 2. when at least one run is dispatched try to get the result 65 // 3. sleep 66 66 while (true) { 67 67 try { 68 // start new jobs as long as there are less than MaxActiveJobs 69 while (asyncResults.Count < MaxActiveJobs) { 70 Thread.Sleep(StartJobInterval); 68 // if allowed then try to dispatch another run 69 if (asyncResults.Count < MaxActiveJobs) { 71 70 // get an execution from the dispatcher and execute in grid via job-manager 72 71 HeuristicLab.Modeling.IAlgorithm algorithm = Dispatcher.GetNextJob(); … … 85 84 } 86 85 } 86 // when there are active runs 87 87 if (asyncResults.Count > 0) { 88 88 WaitHandle[] whArr = asyncResults.Keys.ToArray(); 89 89 int readyHandleIndex = WaitAny(whArr, WaitForFinishedJobsTimeout); 90 // if the wait didn't timeout, a new result is ready 90 91 if (readyHandleIndex != WaitHandle.WaitTimeout) { 92 // request the finished run and clean up 91 93 WaitHandle readyHandle = whArr[readyHandleIndex]; 94 AsyncGridResult finishedResult = asyncResults[readyHandle]; 95 asyncResults.Remove(readyHandle); 92 96 HeuristicLab.Modeling.IAlgorithm finishedAlgorithm = null; 93 AsyncGridResult finishedResult = null;94 97 lock (activeAlgorithms) { 95 finishedResult = asyncResults[readyHandle];96 98 finishedAlgorithm = activeAlgorithms[finishedResult]; 97 99 activeAlgorithms.Remove(finishedResult); 98 asyncResults.Remove(readyHandle);99 100 } 100 101 OnChanged(); … … 105 106 } 106 107 catch (Exception badEx) { 107 HeuristicLab.Tracing.Logger.Error("CEDMA Executer: Exception in job execution thread. " + badEx.Message +Environment.NewLine+badEx.StackTrace);108 HeuristicLab.Tracing.Logger.Error("CEDMA Executer: Exception in job execution thread. " + badEx.Message + Environment.NewLine + badEx.StackTrace); 108 109 } 109 110 } 110 } else {111 Thread.Sleep(WaitForNewJobsInterval);112 111 } 112 // when there are no active runs then sleep until we try to start a new run (to prevent excessive looping) 113 Thread.Sleep(StartJobInterval); 113 114 } 114 115 115 catch (Exception ex) { 116 116 HeuristicLab.Tracing.Logger.Warn("CEDMA Executer: Exception in job-management thread. " + ex.Message + Environment.NewLine + ex.StackTrace); 117 117 } 118 } 118 } // end while(true) 119 119 } 120 120
Note: See TracChangeset
for help on using the changeset viewer.