Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
12/21/10 18:16:24 (13 years ago)
Author:
cneumuel
Message:

#1260

  • increased timeouts for sent jobs (which are needed if the jobs take long time to deserialize on slave)
  • added DeleteJob to ClientService
  • made optimizer actually Pause instead of Stop when stop is called explicitly (so they can be resumed later)
  • temporarily disabled job-abortion from server because it aborted jobs which took too long to deserialize on slaves (this issue needs to be investigated)
  • reduced locking of engines on slave so that the deserialization does not block heartbeats

#1347

  • worked on HiveEngine
  • added test project for HiveEngine
Location:
branches/HeuristicLab.Hive-3.3/sources/HeuristicLab.Hive/HeuristicLab.HiveEngine/3.3
Files:
5 added
2 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Hive-3.3/sources/HeuristicLab.Hive/HeuristicLab.HiveEngine/3.3/HeuristicLab.HiveEngine-3.3.csproj

    r5136 r5153  
    3232    <WarningLevel>4</WarningLevel>
    3333  </PropertyGroup>
     34  <PropertyGroup>
     35    <SignAssembly>true</SignAssembly>
     36  </PropertyGroup>
     37  <PropertyGroup>
     38    <AssemblyOriginatorKeyFile>HeuristicLab.snk</AssemblyOriginatorKeyFile>
     39  </PropertyGroup>
    3440  <ItemGroup>
    3541    <Reference Include="HeuristicLab.Clients.Common-3.3">
     
    4854      <HintPath>..\..\..\..\..\..\..\..\Program Files\HeuristicLab 3.3\HeuristicLab.Core-3.3.dll</HintPath>
    4955    </Reference>
     56    <Reference Include="HeuristicLab.Core.Views-3.3">
     57      <HintPath>..\..\..\..\..\..\..\..\Program Files\HeuristicLab 3.3\HeuristicLab.Core.Views-3.3.dll</HintPath>
     58    </Reference>
     59    <Reference Include="HeuristicLab.MainForm-3.3">
     60      <HintPath>..\..\..\..\..\..\..\..\Program Files\HeuristicLab 3.3\HeuristicLab.MainForm-3.3.dll</HintPath>
     61    </Reference>
     62    <Reference Include="HeuristicLab.MainForm.WindowsForms-3.3">
     63      <HintPath>..\..\..\..\..\..\..\..\Program Files\HeuristicLab 3.3\HeuristicLab.MainForm.WindowsForms-3.3.dll</HintPath>
     64    </Reference>
     65    <Reference Include="HeuristicLab.Optimization.Views-3.3">
     66      <HintPath>..\..\..\..\..\..\..\..\Program Files\HeuristicLab 3.3\HeuristicLab.Optimization.Views-3.3.dll</HintPath>
     67    </Reference>
    5068    <Reference Include="HeuristicLab.Persistence-3.3">
    5169      <HintPath>..\..\..\..\..\..\..\..\Program Files\HeuristicLab 3.3\HeuristicLab.Persistence-3.3.dll</HintPath>
     
    5371    <Reference Include="HeuristicLab.PluginInfrastructure-3.3">
    5472      <HintPath>..\..\..\..\..\..\..\..\Program Files\HeuristicLab 3.3\HeuristicLab.PluginInfrastructure-3.3.dll</HintPath>
     73    </Reference>
     74    <Reference Include="HeuristicLab.Random-3.3">
     75      <HintPath>..\..\..\..\..\..\..\..\Program Files\HeuristicLab 3.3\HeuristicLab.Random-3.3.dll</HintPath>
    5576    </Reference>
    5677    <Reference Include="HeuristicLab.SequentialEngine-3.3">
     
    6081    <Reference Include="System.Core" />
    6182    <Reference Include="System.Drawing" />
     83    <Reference Include="System.Windows.Forms" />
    6284    <Reference Include="System.Xml.Linq" />
    6385    <Reference Include="System.Data.DataSetExtensions" />
     
    6789  <ItemGroup>
    6890    <Compile Include="ScopeMergeException.cs" />
     91    <Compile Include="Views\HiveEngineView.cs">
     92      <SubType>UserControl</SubType>
     93    </Compile>
     94    <Compile Include="Views\HiveEngineView.Designer.cs">
     95      <DependentUpon>HiveEngineView.cs</DependentUpon>
     96    </Compile>
     97    <None Include="HeuristicLab.snk" />
    6998    <None Include="Properties\AssemblyInfo.cs.frame" />
    7099    <None Include="HeuristicLabHiveEnginePlugin.cs.frame" />
     
    92121    </ProjectReference>
    93122  </ItemGroup>
     123  <ItemGroup>
     124    <EmbeddedResource Include="Views\HiveEngineView.resx">
     125      <DependentUpon>HiveEngineView.cs</DependentUpon>
     126    </EmbeddedResource>
     127  </ItemGroup>
    94128  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
    95129  <PropertyGroup>
  • branches/HeuristicLab.Hive-3.3/sources/HeuristicLab.Hive/HeuristicLab.HiveEngine/3.3/HiveEngine.cs

    r5136 r5153  
    1313using HeuristicLab.Hive.Contracts.ResponseObjects;
    1414using System.Threading;
     15using HeuristicLab.Random;
    1516
    1617namespace HeuristicLab.HiveEngine {
     
    1920  /// </summary>
    2021  [StorableClass]
    21   [Item("Hive Parallel Engine", "Engine for parallel execution on the hive.")]
     22  [Item("Hive Engine", "Engine for parallel execution on the hive. You need enable `Parallel` for at least one operator in your operator graph to have all childoperations parallelized. Also those childoperations must not have sideeffects on a higher scope.")]
    2223  public class HiveEngine : Engine {
     24    [Storable]
    2325    private IOperator currentOperator;
    2426
     27    [Storable]
     28    public string ResourceIds { get; set; }
     29
    2530    #region constructors and cloning
    26     public HiveEngine() { }
     31    public HiveEngine() {
     32      ResourceIds = "HEAL";
     33    }
    2734    [StorableConstructor]
    2835    protected HiveEngine(bool deserializing) : base(deserializing) { }
    2936    protected HiveEngine(HiveEngine original, Cloner cloner)
    3037      : base(original, cloner) {
     38      this.ResourceIds = original.ResourceIds;
     39      this.currentOperator = cloner.Clone(original.currentOperator);
    3140    }
    3241    public override IDeepCloneable Clone(Cloner cloner) {
     
    4251      while (coll != null) {
    4352        if (coll.Parallel) {
    44           IScope scope = ((IAtomicOperation)coll.Where(x => x is IAtomicOperation).First()).Scope;
    45           IEnumerable<IOperation> finishedOperations = ExecuteOnHive(coll.Select(op => new OperationJob(op)));
    46           foreach (IOperation op in finishedOperations) {
    47             ReIntegrateScope(scope, op);
     53          IDictionary<IOperation, OperationJob> jobs = new Dictionary<IOperation, OperationJob>();
     54          foreach (IOperation op in coll) {
     55            jobs.Add(op, new OperationJob(op));
     56          }
     57
     58          ExecuteOnHive(jobs);
     59
     60          foreach (var kvp in jobs) {
     61            if (kvp.Key is IAtomicOperation) {
     62              ReIntegrateScope(kvp.Value.Operation as IAtomicOperation, kvp.Key as IAtomicOperation);
     63            } else if (kvp.Key is OperationCollection) {
     64              // todo
     65            }
    4866          }
    4967        } else {
     
    7391    }
    7492
    75     private static void ReIntegrateScope(IScope scope, IOperation operation) {
    76       if (operation is IAtomicOperation) {
    77         MergeScopes(scope, ((IAtomicOperation)operation).Scope);
    78       } else if (operation is OperationCollection) {
    79         foreach (IOperation op in (OperationCollection)operation) {
    80           ReIntegrateScope(scope, op);
     93    private IRandom FindRandomParameter(IExecutionContext ec) {
     94      try {
     95        if (ec == null)
     96          return null;
     97
     98        foreach (var p in ec.Parameters) {
     99          if (p.Name == "Random" && p is IValueParameter)
     100            return ((IValueParameter)p).Value as IRandom;
    81101        }
     102        return FindRandomParameter(ec.Parent);
    82103      }
     104      catch { return null; }
    83105    }
    84106
    85     private static void MergeScopes(IScope target, IScope source) {
    86       foreach (IVariable variable in source.Variables) {
    87         if (target.Variables.ContainsKey(variable.Name)) {
    88           if (target.Variables[variable.Name] != source.Variables[variable.Name]) {
    89             // problem: ResultCollection are not equal altough they contain the same values.
    90             //             - either implement ResultCollection.Equals, or consider ResultCollection as special case here
    91             //throw new ScopeMergeException(string.Format("Variable {0} already exists in target scope and has a different value ({1}, {2}).", variable.Name, target.Variables[variable.Name].Value, variable.Value));
    92           }
    93         } else {
    94           target.Variables.Add(variable);
    95         }
    96       }
    97 
    98       //this is not useful on the parentscope of the initial scope
    99       //foreach (IScope subScope in source.SubScopes) {
    100       //  target.SubScopes.Add(subScope);
    101       //}
    102 
    103       if (target.Parent != null && source.Parent != null)
    104         MergeScopes(target.Parent, source.Parent);
     107    private static void ReIntegrateScope(IAtomicOperation source, IAtomicOperation target) {
     108      ExchangeScope(source.Scope, target.Scope);
    105109    }
    106110
    107 
    108     private IEnumerable<IOperation> TestExecuteOnHive(IEnumerable<OperationJob> operationJobs) {
    109       //var clonedJobs = operationJobs.Select(x => (OperationJob)x.Clone()).ToArray();
    110       var results = new List<IOperation>();
    111 
    112       foreach (var job in operationJobs) {
    113         job.Start();
    114         while (job.ExecutionState != Core.ExecutionState.Stopped) {
    115           Thread.Sleep(100);
    116         }
    117         results.Add(job.Operation);
    118       }
    119       return results;
     111    private static void ExchangeScope(IScope source, IScope target) {
     112      target.Variables.Clear();
     113      target.Variables.AddRange(source.Variables);
     114      target.SubScopes.Clear();
     115      target.SubScopes.AddRange(source.SubScopes);
     116      // TODO: validate if parent scopes match - otherwise source is invalid
    120117    }
    121118
    122     private IEnumerable<IOperation> ExecuteOnHive(IEnumerable<OperationJob> operationJobs) {
    123       IEnumerable<Guid> jobIds;
     119    /// <summary>
     120    /// This method blocks until all jobs are finished
     121    /// </summary>
     122    /// <param name="jobDict"></param>
     123    private void ExecuteOnHive(IDictionary<IOperation, OperationJob> jobDict) {
     124      Log.LogMessage(string.Format("Executing {0} operations on the hive.", jobDict.Count));
     125      IDictionary<Guid, IOperation> jobIds = new Dictionary<Guid, IOperation>();
    124126      JobResultList results;
    125 
    126127
    127128      using (Disposable<IClientFacade> service = ServiceLocator.Instance.StreamedClientFacadePool.GetService()) {
    128129        List<JobDto> jobs = new List<JobDto>();
    129         foreach (OperationJob operationJob in operationJobs) {
    130           var groups = new string[] { "HEAL" };
     130        foreach (var kvp in jobDict) {
     131          // shuffle random variable to avoid the same random sequence in each operation
     132          IRandom random = FindRandomParameter(kvp.Key as IExecutionContext);
     133          if (random != null)
     134            random.Reset(random.Next());
     135
     136          var groups = ResourceIds.Split(';');
    131137          SerializedJob serializedJob = new SerializedJob();
    132           serializedJob.SerializedJobData = SerializedJob.Serialize(operationJob);
     138          serializedJob.SerializedJobData = SerializedJob.Serialize(kvp.Value);
    133139          serializedJob.JobInfo = new JobDto();
    134140          serializedJob.JobInfo.State = JobState.Offline;
     
    137143          ResponseObject<JobDto> response = service.Obj.AddJobWithGroupStrings(serializedJob, groups);
    138144          jobs.Add(response.Obj);
     145          jobIds.Add(response.Obj.Id, kvp.Key);
    139146        }
    140         jobIds = jobs.Select(x => x.Id);
    141         results = service.Obj.GetJobResults(jobIds).Obj;
     147        results = service.Obj.GetJobResults(jobIds.Keys).Obj;
    142148      }
    143149
     
    148154        Thread.Sleep(5000);
    149155        using (Disposable<IClientFacade> service = ServiceLocator.Instance.StreamedClientFacadePool.GetService()) {
    150           results = service.Obj.GetJobResults(jobIds).Obj;
     156          results = service.Obj.GetJobResults(jobIds.Keys).Obj;
    151157        }
    152158      }
    153159
    154160      // all finished
    155       List<OperationJob> finishedJobs = new List<OperationJob>();
    156161      using (Disposable<IClientFacade> service = ServiceLocator.Instance.StreamedClientFacadePool.GetService()) {
    157         foreach (Guid jobId in jobIds) {
     162        foreach (Guid jobId in jobIds.Keys) {
    158163          SerializedJob serializedJob = service.Obj.GetLastSerializedResult(jobId).Obj;
    159164          OperationJob operationJob = SerializedJob.Deserialize<OperationJob>(serializedJob.SerializedJobData);
    160           finishedJobs.Add(operationJob);
     165          jobDict[jobIds[jobId]] = operationJob;
    161166        }
    162167      }
    163168
    164169      // delete jobs
    165       // TODO
     170      using (Disposable<IClientFacade> service = ServiceLocator.Instance.StreamedClientFacadePool.GetService()) {
     171        foreach (Guid jobId in jobIds.Keys) {
     172          service.Obj.DeleteJob(jobId);
     173        }
     174      }
    166175
    167       return finishedJobs.Select(x => x.Operation);
     176      Log.LogMessage(string.Format("Operations on the hive finished.", jobDict.Count));
    168177    }
    169178
     
    176185      if (currentOperator != null) currentOperator.Abort();
    177186    }
     187
    178188  }
    179189}
Note: See TracChangeset for help on using the changeset viewer.