Changeset 4121 for branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Experiment/3.3/HiveExperiment.cs
- Timestamp:
- 07/30/10 13:56:28 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Experiment/3.3/HiveExperiment.cs
r4120 r4121 52 52 private const string itemName = "Hive Experiment"; 53 53 private const string itemDescription = "An experiment which contains multiple batch runs of algorithms which are executed in the Hive."; 54 private const int resultPollingIntervalMs = 1 0000;54 private const int resultPollingIntervalMs = 15000; 55 55 56 56 private object locker = new object(); … … 128 128 129 129 public override IDeepCloneable Clone(Cloner cloner) { 130 log.LogMessage("I am beeing cloned");130 LogMessage("I am beeing cloned"); 131 131 HiveExperiment clone = (HiveExperiment)base.Clone(cloner); 132 132 clone.resourceIds = this.resourceIds; … … 148 148 private void AfterDeserialization() { 149 149 InitTimer(); 150 log.LogMessage("I was deserialized.");150 LogMessage("I was deserialized."); 151 151 } 152 152 … … 224 224 ResponseObject<JobDto> response = executionEngineFacade.AddJobWithGroupStrings(serializedJob, groups); 225 225 pendingOptimizers.Add(response.Obj.Id, optimizer); 226 StartResultPollingThread(response.Obj);227 226 228 227 JobItem jobItem = new JobItem() { … … 236 235 jobItems.Add(jobItem); 237 236 238 log.LogMessage("Sent job to server (jobId: " + response.Obj.Id + ")"); 237 LogMessage("Sent job to server (jobId: " + response.Obj.Id + ")"); 238 } 239 240 // start results polling after sending sending the jobs to the server (to avoid race conflicts at the optimizers-collection) 241 foreach (JobItem jobItem in jobItems) { 242 StartResultPollingThread(jobItem.JobDto); 239 243 } 240 244 }); … … 256 260 257 261 private void ReplaceOptimizer(IOptimizer originalOptimizer, IOptimizer newOptimizer) { 258 int originalOptimizerIndex = experiment.Optimizers.IndexOf(originalOptimizer); 259 experiment.Optimizers[originalOptimizerIndex] = newOptimizer; 262 lock (locker) { 263 int originalOptimizerIndex = experiment.Optimizers.IndexOf(originalOptimizer); 264 experiment.Optimizers[originalOptimizerIndex] = newOptimizer; 265 } 260 266 } 261 267 … … 308 314 do { 309 315 Thread.Sleep(resultPollingIntervalMs); 310 lock (locker) {316 //lock (locker) { [chn] try without locking for better performance 311 317 if (stopPending) return; 312 313 ResponseObject<SerializedJob> response = executionEngineFacade.GetLastSerializedResult(job.Id, false, false); 314 log.LogMessage("Received response for job: " + response.StatusMessage + " (jobId: " + job.Id + ")"); 315 318 319 ResponseObject<JobDto> response = executionEngineFacade.GetJobById(job.Id); 320 LogMessage("Response: " + response.StatusMessage + " (jobId: " + job.Id + ")"); 321 322 if (response.Obj != null) { 323 UpdateJobItem(response.Obj); 324 } 316 325 317 326 // loop while … … 320 329 // 3. no result for the job is available yet (response.Obj==null) 321 330 // 4. the result that we get from the server is a snapshot and not the final result 322 if (response.Success && response.Obj != null && response.StatusMessage != ApplicationConstants.RESPONSE_JOB_RESULT_NOT_YET_HERE) { 323 restoredObject = XmlParser.Deserialize<IJob>(new MemoryStream(response.Obj.SerializedJobData)); 331 if (response.Success && response.Obj != null && response.Obj.State == State.Finished) { 332 ResponseObject<SerializedJob> jobResponse = executionEngineFacade.GetLastSerializedResult(job.Id, false, false); 333 restoredObject = XmlParser.Deserialize<IJob>(new MemoryStream(jobResponse.Obj.SerializedJobData)); 334 UpdateSnapshot(jobResponse); 324 335 } 325 }336 //} 326 337 } while (restoredObject == null || restoredObject.ExecutionState != Core.ExecutionState.Stopped); 327 338 328 log.LogMessage("Job finished (jobId: " + job.Id + ")");339 LogMessage("Job finished (jobId: " + job.Id + ")"); 329 340 // job retrieved... replace the existing optimizers with the finished one 330 341 IOptimizer originalOptimizer = pendingOptimizers[job.Id]; … … 340 351 } 341 352 }); 342 343 Logger.Debug("HiveEngine: Starting results-polling thread");344 353 t.Start(); 354 } 355 356 private void UpdateJobItem(JobDto jobDto) { 357 JobItem jobItem = jobItems.Single(x => x.JobDto.Id == jobDto.Id); 358 jobItem.JobDto = jobDto; 359 } 360 361 private void UpdateSnapshot(ResponseObject<SerializedJob> response) { 362 JobItem jobItem = jobItems.Single(x => x.JobDto.Id == response.Obj.JobInfo.Id); 363 jobItem.LatestSnapshot = response; 364 } 365 366 private void LogMessage(string message) { 367 // HeuristicLab.Log is not Thread-Safe, so lock every call 368 lock (locker) { 369 log.LogMessage(message); 370 } 345 371 } 346 372 … … 440 466 public event EventHandler ExecutionStateChanged; 441 467 private void OnExecutionStateChanged() { 442 log.LogMessage("ExecutionState changed to " + executionState.ToString());468 LogMessage("ExecutionState changed to " + executionState.ToString()); 443 469 EventHandler handler = ExecutionStateChanged; 444 470 if (handler != null) handler(this, EventArgs.Empty); … … 449 475 public event EventHandler Started; 450 476 private void OnStarted() { 451 log.LogMessage("Started");477 LogMessage("Started"); 452 478 timer.Start(); 453 479 EventHandler handler = Started; … … 458 484 private void OnStopped() { 459 485 timer.Stop(); 460 log.LogMessage("Stopped");486 LogMessage("Stopped"); 461 487 EventHandler handler = Stopped; 462 488 if (handler != null) handler(this, EventArgs.Empty); … … 466 492 private void OnPaused() { 467 493 timer.Stop(); 468 log.LogMessage("Paused");494 LogMessage("Paused"); 469 495 EventHandler handler = Paused; 470 496 if (handler != null) handler(this, EventArgs.Empty); … … 473 499 public event EventHandler Prepared; 474 500 protected virtual void OnPrepared() { 475 log.LogMessage("Prepared");501 LogMessage("Prepared"); 476 502 EventHandler handler = Prepared; 477 503 if (handler != null) handler(this, EventArgs.Empty); … … 486 512 public event EventHandler ExperimentChanged; 487 513 protected virtual void OnExperimentChanged() { 488 log.LogMessage("Experiment changed");514 LogMessage("Experiment changed"); 489 515 EventHandler handler = ExperimentChanged; 490 516 if (handler != null) handler(this, EventArgs.Empty);
Note: See TracChangeset
for help on using the changeset viewer.