Changeset 245
- Timestamp:
- 05/13/08 23:03:56 (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified trunk/sources/HeuristicLab.Grid/EngineStore.cs ¶
r221 r245 31 31 private List<Guid> engineList; 32 32 private Dictionary<Guid, byte[]> waitingEngines; 33 private Dictionary<Guid, byte[]> runningEngines; 33 34 private Dictionary<Guid, ManualResetEvent> waitHandles; 34 35 private Dictionary<Guid, byte[]> results; 35 36 private Dictionary<Guid, DateTime> resultDate; 37 private Dictionary<Guid, DateTime> runningEngineDate; 38 private const int RESULT_EXPIRY_TIME_MIN = 10; 39 private const int RUNNING_JOB_EXPIRY_TIME_MIN = 10; 36 40 private object bigLock; 37 private ChannelFactory<IClient> clientChannelFactory;38 41 public int WaitingJobs { 39 42 get { … … 57 60 engineList = new List<Guid>(); 58 61 waitingEngines = new Dictionary<Guid, byte[]>(); 62 runningEngines = new Dictionary<Guid, byte[]>(); 59 63 waitHandles = new Dictionary<Guid, ManualResetEvent>(); 60 64 results = new Dictionary<Guid, byte[]>(); 61 65 resultDate = new Dictionary<Guid, DateTime>(); 66 runningEngineDate = new Dictionary<Guid, DateTime>(); 62 67 bigLock = new object(); 63 68 … … 68 73 binding.Security.Mode = SecurityMode.None; 69 74 70 clientChannelFactory = new ChannelFactory<IClient>(binding);71 75 } 72 76 … … 82 86 engine = waitingEngines[guid]; 83 87 waitingEngines.Remove(guid); 88 runningEngines[guid] = engine; 89 runningEngineDate[guid] = DateTime.Now; 84 90 return true; 85 91 } … … 90 96 lock(bigLock) { 91 97 // clear old results 92 List<Guid> expiredResults = FindExpiredResults(DateTime.Now.AddMinutes(- 10.0));98 List<Guid> expiredResults = FindExpiredResults(DateTime.Now.AddMinutes(-RESULT_EXPIRY_TIME_MIN)); 93 99 foreach(Guid expiredGuid in expiredResults) { 94 100 results.Remove(expiredGuid); … … 97 103 } 98 104 // add the new result 105 runningEngines.Remove(guid); 106 runningEngineDate.Remove(guid); 99 107 results[guid] = result; 100 108 resultDate[guid] = DateTime.Now; … … 111 119 } 112 120 return expiredResults; 121 } 122 private List<Guid> FindExpiredJobs(DateTime expirationDate) { 123 List<Guid> expiredJobs = new List<Guid>(); 124 foreach(Guid guid in runningEngines.Keys) { 125 if(runningEngineDate[guid] < expirationDate) { 126 expiredJobs.Add(guid); 127 } 128 } 129 return expiredJobs; 113 130 } 114 131 … … 139 156 // result not yet available, if there is also no wait-handle for that result then we will never have a result and can return null 140 157 if(!waitHandles.ContainsKey(guid)) return null; 141 142 158 // otherwise we have a wait-handle and can wait for the result 143 159 ManualResetEvent waitHandle = waitHandles[guid]; … … 150 166 return result; 151 167 } else { 152 // no result yet return without result 168 // no result yet, check for which jobs we waited too long and requeue those jobs 169 List<Guid> expiredJobs = FindExpiredJobs(DateTime.Now.AddMinutes(-RUNNING_JOB_EXPIRY_TIME_MIN)); 170 foreach(Guid expiredGuid in expiredJobs) { 171 engineList.Insert(0, expiredGuid); 172 waitingEngines[expiredGuid] = runningEngines[expiredGuid]; 173 runningEngines.Remove(expiredGuid); 174 runningEngineDate.Remove(expiredGuid); 175 } 153 176 return null; 154 177 } … … 158 181 159 182 internal void AbortEngine(Guid guid) { 160 lock(bigLock) { 161 if(waitingEngines.ContainsKey(guid)) { 162 byte[] engine = waitingEngines[guid]; 163 waitingEngines.Remove(guid); 164 engineList.Remove(guid); 165 waitHandles[guid].Set(); 166 results.Add(guid, engine); 167 } 168 } 183 throw new NotImplementedException(); 169 184 } 170 185
Note: See TracChangeset
for help on using the changeset viewer.