Changeset 2145
- Timestamp:
- 07/07/09 12:49:24 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.CEDMA.Server/3.3/GridExecuter.cs
r2128 r2145 53 53 } 54 54 55 private TimeSpan WaitForNewJobsInterval { 56 get { return TimeSpan.FromSeconds(3); } 57 } 58 55 59 public GridExecuter(IDispatcher dispatcher, IStore store, IGridServer server) 56 60 : base(dispatcher, store) { … … 83 87 } 84 88 } 85 WaitHandle[] whArr = asyncResults.Keys.ToArray(); 86 int readyHandleIndex = WaitAny(whArr, WaitForFinishedJobsTimeout); 87 if (readyHandleIndex != WaitHandle.WaitTimeout) { 88 WaitHandle readyHandle = whArr[readyHandleIndex]; 89 IAlgorithm finishedAlgorithm = null; 90 AsyncGridResult finishedResult = null; 91 lock (activeAlgorithms) { 92 finishedResult = asyncResults[readyHandle]; 93 finishedAlgorithm = activeAlgorithms[finishedResult]; 94 activeAlgorithms.Remove(finishedResult); 95 asyncResults.Remove(readyHandle); 89 if (asyncResults.Count > 0) { 90 WaitHandle[] whArr = asyncResults.Keys.ToArray(); 91 int readyHandleIndex = WaitAny(whArr, WaitForFinishedJobsTimeout); 92 if (readyHandleIndex != WaitHandle.WaitTimeout) { 93 WaitHandle readyHandle = whArr[readyHandleIndex]; 94 IAlgorithm finishedAlgorithm = null; 95 AsyncGridResult finishedResult = null; 96 lock (activeAlgorithms) { 97 finishedResult = asyncResults[readyHandle]; 98 finishedAlgorithm = activeAlgorithms[finishedResult]; 99 activeAlgorithms.Remove(finishedResult); 100 asyncResults.Remove(readyHandle); 101 } 102 OnChanged(); 103 try { 104 IEngine finishedEngine = jobManager.EndExecuteEngine(finishedResult); 105 SetResults(finishedEngine.GlobalScope, finishedAlgorithm.Engine.GlobalScope); 106 StoreResults(finishedAlgorithm); 107 } 108 catch (Exception badEx) { 109 HeuristicLab.Tracing.Logger.Error("CEDMA Executer: Exception in job execution thread. " + badEx.Message); 110 } 96 111 } 97 OnChanged(); 98 try { 99 IEngine finishedEngine = jobManager.EndExecuteEngine(finishedResult); 100 SetResults(finishedEngine.GlobalScope, finishedAlgorithm.Engine.GlobalScope); 101 StoreResults(finishedAlgorithm); 102 } 103 catch (Exception badEx) { 104 HeuristicLab.Tracing.Logger.Error("CEDMA Executer: Exception in job execution thread. " + badEx.Message); 105 } 112 } else { 113 Thread.Sleep(WaitForNewJobsInterval); 106 114 } 107 115 } 116 108 117 catch (Exception ex) { 109 118 HeuristicLab.Tracing.Logger.Warn("CEDMA Executer: Exception in job-management thread. " + ex.Message); … … 112 121 } 113 122 114 123 // wait until any job is finished 115 124 private int WaitAny(WaitHandle[] wh, TimeSpan WaitForFinishedJobsTimeout) { 116 125 if (wh.Length <= 64) {
Note: See TracChangeset
for help on using the changeset viewer.