- Timestamp:
- 07/16/17 13:13:49 (7 years ago)
- Location:
- stable
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
stable
- Property svn:mergeinfo changed
/trunk/sources merged: 15004
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Clients.Hive.Slave/3.3/Executor.cs
r14186 r15263 185 185 #endregion 186 186 187 public Tuple<TaskData, DateTime> GetTaskDataSnapshot() {188 if (taskDataInvalid) return null;189 190 Tuple<TaskData, DateTime> snapshot = null;191 if (task == null) {192 if (CurrentException == null) {193 CurrentException = new Exception("Task with id " + this.TaskId + " is null, sending empty task");194 }195 } else {196 var taskData = new TaskData();197 198 var pausedTrigger = new EventWaitHandle(false, EventResetMode.ManualReset);199 EventHandler pausedHandler = null;200 pausedHandler = (s, e) => {201 task.TaskPaused -= pausedHandler;202 task.TaskPaused += Task_TaskPaused;203 pausedTrigger.Set();204 };205 206 task.TaskPaused -= Task_TaskPaused;207 task.TaskPaused += pausedHandler;208 task.Pause();209 pausedTrigger.WaitOne();210 211 taskData.Data = PersistenceUtil.Serialize(task);212 var timestamp = DateTime.Now;213 214 EventHandler startedHandler = null;215 startedHandler = (s, e) => {216 task.TaskStarted -= startedHandler;217 task.TaskStarted += Task_TaskStarted;218 };219 220 task.TaskStarted -= Task_TaskStarted;221 task.TaskStarted += startedHandler;222 task.Start();223 224 taskData.TaskId = TaskId;225 snapshot = Tuple.Create(taskData, timestamp);226 }227 228 return snapshot;229 }230 231 187 public TaskData GetTaskData() { 232 188 if (taskDataInvalid) return null; -
stable/HeuristicLab.Clients.Hive.Slave/3.3/Manager/TaskManager.cs
r14186 r15263 37 37 public class TaskManager { 38 38 private static readonly ReaderWriterLockSlim slaveTasksLocker = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion); 39 private readonly Dictionary<Guid, SnapshotInfo> slaveTasks;39 private readonly Dictionary<Guid, Tuple<SlaveTask, DateTime>> slaveTasks; 40 40 private readonly ILog log; 41 41 private readonly PluginManager pluginManager; … … 43 43 private readonly CancellationToken ct; 44 44 private readonly AutoResetEvent waitHandle; 45 private readonly WcfService wcfService;46 45 private readonly TimeSpan checkpointInterval; 47 46 private readonly TimeSpan checkpointCheckInterval; … … 70 69 this.pluginManager = pluginCache; 71 70 this.log = log; 72 this.slaveTasks = new Dictionary<Guid, SnapshotInfo>();71 this.slaveTasks = new Dictionary<Guid, Tuple<SlaveTask, DateTime>>(); 73 72 74 73 cts = new CancellationTokenSource(); 75 74 ct = cts.Token; 76 75 waitHandle = new AutoResetEvent(true); 77 wcfService = WcfService.Instance;78 76 checkpointInterval = Settings.Default.CheckpointInterval; 79 77 checkpointCheckInterval = Settings.Default.CheckpointCheckInterval; … … 85 83 private void Checkpointing() { 86 84 while (!ct.IsCancellationRequested) { 87 slaveTasksLocker.Enter WriteLock();85 slaveTasksLocker.EnterUpgradeableReadLock(); 88 86 try { 89 87 foreach (var entry in slaveTasks) { 90 var taskId = entry.Key; 91 var snapshotInfo = entry.Value; 92 93 if (DateTime.Now - snapshotInfo.LastSnapshot <= checkpointInterval) continue; 94 95 var task = wcfService.GetTask(taskId); 96 var snapshot = snapshotInfo.Task.GetTaskDataSnapshot(); 97 98 if (snapshot == null) continue; 99 100 slaveTasks[taskId].LastSnapshot = snapshot.Item2; 101 var slaveId = ConfigManager.Instance.GetClientInfo().Id; 102 wcfService.UpdateTaskData(task, snapshot.Item1, slaveId, TaskState.Calculating); 88 if (DateTime.Now - entry.Value.Item2 > checkpointInterval) 89 PauseTaskAsync(entry.Key); 103 90 } 104 } finally { slaveTasksLocker.Exit WriteLock(); }91 } finally { slaveTasksLocker.ExitUpgradeableReadLock(); } 105 92 waitHandle.WaitOne(checkpointCheckInterval); 106 93 } … … 146 133 try { 147 134 if (!slaveTasks.ContainsKey(taskId)) throw new TaskNotRunningException(taskId); 148 SlaveTask slaveTask = slaveTasks[taskId]. Task;135 SlaveTask slaveTask = slaveTasks[taskId].Item1; 149 136 slaveTask.PauseTask(); 150 137 } … … 156 143 try { 157 144 if (!slaveTasks.ContainsKey(taskId)) throw new TaskNotRunningException(taskId); 158 SlaveTask slaveTask = slaveTasks[taskId]. Task;145 SlaveTask slaveTask = slaveTasks[taskId].Item1; 159 146 slaveTask.StopTask(); 160 147 } … … 167 154 try { 168 155 if (!slaveTasks.ContainsKey(taskId)) throw new TaskNotRunningException(taskId); 169 slaveTask = slaveTasks[taskId]. Task;156 slaveTask = slaveTasks[taskId].Item1; 170 157 if (!slaveTask.IsPrepared) throw new AppDomainNotCreatedException(); 171 158 RemoveSlaveTask(taskId, slaveTask); … … 181 168 try { 182 169 foreach (var slaveTask in slaveTasks.Values) { 183 slaveTask. Task.PauseTask();170 slaveTask.Item1.PauseTask(); 184 171 } 185 172 } … … 191 178 try { 192 179 foreach (var slaveTask in slaveTasks.Values) { 193 slaveTask. Task.StopTask();180 slaveTask.Item1.StopTask(); 194 181 } 195 182 } … … 201 188 try { 202 189 foreach (var slaveTask in slaveTasks.Values.ToArray()) { 203 AbortTask(slaveTask. Task.TaskId);190 AbortTask(slaveTask.Item1.TaskId); 204 191 } 205 192 } … … 212 199 slaveTasksLocker.EnterWriteLock(); 213 200 try { 214 slaveTasks.Add(task.Id, new SnapshotInfo { Task = slaveTask, LastSnapshot = task.DateCreated.GetValueOrDefault() });201 slaveTasks.Add(task.Id, Tuple.Create(slaveTask, DateTime.Now)); 215 202 RegisterSlaveTaskEvents(slaveTask); 216 203 } … … 247 234 slaveTasksLocker.EnterUpgradeableReadLock(); 248 235 try { 249 slaveTask = slaveTasks[e.Value]. Task;236 slaveTask = slaveTasks[e.Value].Item1; 250 237 } 251 238 finally { slaveTasksLocker.ExitUpgradeableReadLock(); } … … 259 246 slaveTasksLocker.EnterUpgradeableReadLock(); 260 247 try { 261 slaveTask = slaveTasks[e.Value]. Task;248 slaveTask = slaveTasks[e.Value].Item1; 262 249 RemoveSlaveTask(e.Value, slaveTask); 263 250 } … … 281 268 slaveTasksLocker.EnterUpgradeableReadLock(); 282 269 try { 283 slaveTask = slaveTasks[e.Value]. Task;270 slaveTask = slaveTasks[e.Value].Item1; 284 271 RemoveSlaveTask(e.Value, slaveTask); 285 272 } … … 303 290 slaveTasksLocker.EnterUpgradeableReadLock(); 304 291 try { 305 slaveTask = slaveTasks[e.Value]. Task;292 slaveTask = slaveTasks[e.Value].Item1; 306 293 RemoveSlaveTask(e.Value, slaveTask); 307 294 } … … 353 340 slaveTasksLocker.EnterReadLock(); 354 341 try { 355 return slaveTasks.ToDictionary(x => x.Key, x => x.Value. Task.ExecutionTime);342 return slaveTasks.ToDictionary(x => x.Key, x => x.Value.Item1.ExecutionTime); 356 343 } 357 344 finally { slaveTasksLocker.ExitReadLock(); } 358 }359 360 private sealed class SnapshotInfo {361 public SlaveTask Task { get; set; }362 public DateTime LastSnapshot { get; set; }363 345 } 364 346 } -
stable/HeuristicLab.Clients.Hive.Slave/3.3/SlaveTask.cs
r14186 r15263 165 165 } 166 166 167 public Tuple<TaskData, DateTime> GetTaskDataSnapshot() {168 Tuple<TaskData, DateTime> snapshot = null;169 try {170 snapshot = executor.GetTaskDataSnapshot();171 if (snapshot == null) return Tuple.Create(originalTaskData, DateTime.Now);172 }173 catch (Exception ex) {174 EventLogManager.LogException(ex);175 }176 return snapshot;177 }178 179 167 public TaskData GetTaskData() { 180 168 TaskData data = null;
Note: See TracChangeset
for help on using the changeset viewer.