Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/30/10 13:56:28 (14 years ago)
Author:
cneumuel
Message:

Stabilization of Hive, Improvement HiveExperiment GUI (#1115)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Experiment/3.3/HiveExperiment.cs

    r4120 r4121  
    5252    private const string itemName = "Hive Experiment";
    5353    private const string itemDescription = "An experiment which contains multiple batch runs of algorithms which are executed in the Hive.";
    54     private const int resultPollingIntervalMs = 10000;
     54    private const int resultPollingIntervalMs = 15000;
    5555
    5656    private object locker = new object();
     
    128128
    129129    public override IDeepCloneable Clone(Cloner cloner) {
    130       log.LogMessage("I am beeing cloned");
     130      LogMessage("I am beeing cloned");
    131131      HiveExperiment clone = (HiveExperiment)base.Clone(cloner);
    132132      clone.resourceIds = this.resourceIds;
     
    148148    private void AfterDeserialization() {
    149149      InitTimer();
    150       log.LogMessage("I was deserialized.");
     150      LogMessage("I was deserialized.");
    151151    }
    152152
     
    224224          ResponseObject<JobDto> response = executionEngineFacade.AddJobWithGroupStrings(serializedJob, groups);
    225225          pendingOptimizers.Add(response.Obj.Id, optimizer);
    226           StartResultPollingThread(response.Obj);
    227226
    228227          JobItem jobItem = new JobItem() {
     
    236235          jobItems.Add(jobItem);
    237236
    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);
    239243        }
    240244      });
     
    256260
    257261    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      }
    260266    }
    261267
     
    308314        do {
    309315          Thread.Sleep(resultPollingIntervalMs);
    310           lock (locker) {
     316          //lock (locker) { [chn] try without locking for better performance
    311317            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            }
    316325           
    317326            // loop while
     
    320329            // 3. no result for the job is available yet (response.Obj==null)
    321330            // 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);
    324335            }
    325           }
     336          //}
    326337        } while (restoredObject == null || restoredObject.ExecutionState != Core.ExecutionState.Stopped);
    327338
    328         log.LogMessage("Job finished (jobId: " + job.Id + ")");
     339        LogMessage("Job finished (jobId: " + job.Id + ")");
    329340        // job retrieved... replace the existing optimizers with the finished one
    330341        IOptimizer originalOptimizer = pendingOptimizers[job.Id];
     
    340351        }
    341352      });
    342 
    343       Logger.Debug("HiveEngine: Starting results-polling thread");
    344353      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      }
    345371    }
    346372   
     
    440466    public event EventHandler ExecutionStateChanged;
    441467    private void OnExecutionStateChanged() {
    442       log.LogMessage("ExecutionState changed to " + executionState.ToString());
     468      LogMessage("ExecutionState changed to " + executionState.ToString());
    443469      EventHandler handler = ExecutionStateChanged;
    444470      if (handler != null) handler(this, EventArgs.Empty);
     
    449475    public event EventHandler Started;
    450476    private void OnStarted() {
    451       log.LogMessage("Started");
     477      LogMessage("Started");
    452478      timer.Start();
    453479      EventHandler handler = Started;
     
    458484    private void OnStopped() {
    459485      timer.Stop();
    460       log.LogMessage("Stopped");
     486      LogMessage("Stopped");
    461487      EventHandler handler = Stopped;
    462488      if (handler != null) handler(this, EventArgs.Empty);
     
    466492    private void OnPaused() {
    467493      timer.Stop();
    468       log.LogMessage("Paused");
     494      LogMessage("Paused");
    469495      EventHandler handler = Paused;
    470496      if (handler != null) handler(this, EventArgs.Empty);
     
    473499    public event EventHandler Prepared;
    474500    protected virtual void OnPrepared() {
    475       log.LogMessage("Prepared");
     501      LogMessage("Prepared");
    476502      EventHandler handler = Prepared;
    477503      if (handler != null) handler(this, EventArgs.Empty);
     
    486512    public event EventHandler ExperimentChanged;
    487513    protected virtual void OnExperimentChanged() {
    488       log.LogMessage("Experiment changed");
     514      LogMessage("Experiment changed");
    489515      EventHandler handler = ExperimentChanged;
    490516      if (handler != null) handler(this, EventArgs.Empty);
Note: See TracChangeset for help on using the changeset viewer.