Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
12/29/10 00:52:06 (14 years ago)
Author:
cneumuel
Message:

#1260

  • migrated to .NET 4.0
  • moved state-information about heartbeat timestamps into DB to reduce IIS-recycling issues
  • optimized memory usage of ExperimentManager when lots of large jobs are downloaded
File:
1 edited

Legend:

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

    r5171 r5179  
    534534        IsProgressing = true;
    535535        int totalJobCount = 0;
    536         int jobCount = 0;
    537536        JobResultList allResults;
    538         IDictionary<Guid, SerializedJob> allSerializedJobs = new Dictionary<Guid, SerializedJob>();
     537
    539538        progress.Status = "Connecting to Server...";
    540         using (Disposable<IClientFacade> service = ServiceLocator.Instance.StreamedClientFacadePool.GetService()) {
    541           // fetch all JobDto objects to create the full tree of tree of HiveJob objects
     539        using (Disposable<IClientFacade> service = ServiceLocator.Instance.ClientFacadePool.GetService()) {
    542540          progress.Status = "Downloading list of jobs...";
    543541          allResults = service.Obj.GetChildJobResults(rootJobId.Value, true, true).Obj;
    544542          totalJobCount = allResults.Count;
    545 
    546           // download them first
    547           foreach (JobResult jobResult in allResults) {
    548             jobCount++;
    549             progress.Status = string.Format("Downloading {0} of {1} jobs...", jobCount, totalJobCount);
    550             allSerializedJobs.Add(jobResult.Id, service.Obj.GetLastSerializedResult(jobResult.Id).Obj);
    551             progress.ProgressValue = (double)jobCount / totalJobCount;
    552           }
    553         }
    554 
    555         jobCount = 1;
    556         progress.Status = string.Format("Deserializing {0} of {1} jobs... ({2} kb)", jobCount, totalJobCount, allSerializedJobs[this.rootJobId.Value].SerializedJobData.Count() / 1024);
    557         this.HiveJob = new HiveJob(allSerializedJobs[this.rootJobId.Value], false);
    558         allSerializedJobs.Remove(this.rootJobId.Value); // reduce memory footprint
    559         progress.ProgressValue = (double)jobCount / totalJobCount;
     543        }
     544
     545        HiveJobDownloader downloader = new HiveJobDownloader(allResults.Select(x => x.Id));
     546        downloader.StartAsync();
     547
     548        while (!downloader.IsFinished) {
     549          progress.ProgressValue = downloader.FinishedCount / (double)totalJobCount;
     550          progress.Status = string.Format("Downloading/deserializing jobs... ({0}/{1} finished)", downloader.FinishedCount, totalJobCount);
     551          Thread.Sleep(500);
     552        }
     553        IDictionary<Guid, HiveJob> allHiveJobs = downloader.Results;
     554
     555        this.HiveJob = allHiveJobs[this.rootJobId.Value];
    560556
    561557        if (this.HiveJob.JobDto.DateFinished.HasValue) {
     
    571567        }
    572568
    573         // build child-job tree
    574         LoadChildResults(this.HiveJob, allResults, allSerializedJobs, progress, totalJobCount, ref jobCount);
     569        BuildHiveJobTree(this.HiveJob, allResults, allHiveJobs);
    575570        StartResultPolling();
    576571      }
     
    583578    }
    584579
    585     private void LoadChildResults(HiveJob parentHiveJob, JobResultList allResults, IDictionary<Guid, SerializedJob> allSerializedJobs, IProgress progress, int totalJobCount, ref int jobCount) {
     580    private void BuildHiveJobTree(HiveJob parentHiveJob, JobResultList allResults, IDictionary<Guid, HiveJob> allHiveJobs) {
    586581      IEnumerable<JobResult> childResults = from result in allResults
    587582                                            where result.ParentJobId.HasValue && result.ParentJobId.Value == parentHiveJob.JobDto.Id
     
    589584                                            select result;
    590585      foreach (JobResult jobResult in childResults) {
    591         jobCount++;
    592         progress.Status = string.Format("Deserializing {0} of {1} jobs ({2} kb)...", jobCount, totalJobCount, allSerializedJobs[jobResult.Id].SerializedJobData.Count() / 1024);
    593         OptimizerJob optimizerJob = null;
    594         try {
    595           optimizerJob = SerializedJob.Deserialize<OptimizerJob>(allSerializedJobs[jobResult.Id].SerializedJobData);
    596         }
    597         catch {
    598           optimizerJob = null;
    599         }
    600         progress.ProgressValue = (double)jobCount / totalJobCount;
    601         HiveJob childHiveJob = new HiveJob(optimizerJob, false);
     586        HiveJob childHiveJob = allHiveJobs[jobResult.Id];
    602587        parentHiveJob.AddChildHiveJob(childHiveJob);
    603         childHiveJob.JobDto = allSerializedJobs[jobResult.Id].JobInfo;
    604         allSerializedJobs.Remove(jobResult.Id); // reduce memory footprint
    605         if (jobCount % 10 == 0) GC.Collect(); // this is needed or otherwise HL takes over the system when the number of jobs is high
    606         LoadChildResults(childHiveJob, allResults, allSerializedJobs, progress, totalJobCount, ref jobCount);
     588        BuildHiveJobTree(childHiveJob, allResults, allHiveJobs);
    607589      }
    608590    }
Note: See TracChangeset for help on using the changeset viewer.