Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/16/11 00:06:54 (13 years ago)
Author:
cneumuel
Message:

#1233

  • created events when statelog changed
  • fixed memory leak in hiveengine
  • extended timeout for long running transactions and database contexts (when jobdata is stored)
  • replaced random guids in database with sequential guids for performance reasons
  • minor fixes and cleanups
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/Executor.cs

    r6381 r6419  
    3131  /// </summary>
    3232  public class Executor : MarshalByRefObject, IDisposable {
    33     public Guid JobId { get; set; }
    34     private IJob Job { get; set; }
    35     public int CoresNeeded { get; set; }
    36     public int MemoryNeeded { get; set; }
    3733    private bool wasJobAborted = false;
    3834    private Semaphore pauseStopSem = new Semaphore(0, 1);
    3935    private Semaphore startJobSem = new Semaphore(0, 1);
    40     //make pause or stop wait until start is finished
    41     private Semaphore jobStartedSem = new Semaphore(0, 1);
     36    private Semaphore jobStartedSem = new Semaphore(0, 1); // make pause or stop wait until start is finished
    4237    private ExecutorQueue executorQueue;
    43     public ExecutorQueue ExecutorCommandQueue {
    44       get {
    45         return executorQueue;
    46       }
    47     }
     38    private bool jobDataInvalid = false; // if true, the jobdata is not sent when the job is failed
     39    private IJob job;
     40    private DateTime creationTime;
     41
     42    public Guid JobId { get; set; }
     43    public int CoresNeeded { get; set; }
     44    public int MemoryNeeded { get; set; }
    4845    public bool IsStopping { get; set; }
    4946    public bool IsPausing { get; set; }
    50     private DateTime CreationTime { get; set; }
     47
    5148    private Exception currentException;
    5249    public String CurrentException {
     
    6057    }
    6158
     59    public ExecutorQueue ExecutorCommandQueue {
     60      get { return executorQueue; }
     61    }
     62
    6263    private ExecutionState ExecutionState {
    63       get {
    64         return Job != null ? Job.ExecutionState : HeuristicLab.Core.ExecutionState.Stopped;
    65       }
     64      get { return job != null ? job.ExecutionState : HeuristicLab.Core.ExecutionState.Stopped; }
    6665    }
    6766
    6867    public TimeSpan ExecutionTime {
    69       get {
    70         return Job != null ? Job.ExecutionTime : new TimeSpan(0, 0, 0);
    71       }
     68      get { return job != null ? job.ExecutionTime : new TimeSpan(0, 0, 0); }
    7269    }
    7370
     
    8077    public void Start(byte[] serializedJob) {
    8178      try {
    82         CreationTime = DateTime.Now;
    83         Job = PersistenceUtil.Deserialize<IJob>(serializedJob);
     79        creationTime = DateTime.Now;
     80        job = PersistenceUtil.Deserialize<IJob>(serializedJob);
    8481
    8582        RegisterJobEvents();
    8683
    87         Job.Start();
    88         if (!jobStartedSem.WaitOne(TimeSpan.FromSeconds(15))) {
     84        job.Start();
     85        if (!jobStartedSem.WaitOne(TimeSpan.FromSeconds(25))) {
     86          jobDataInvalid = true;
    8987          throw new TimeoutException("Timeout when starting the job. JobStarted event was not fired.");
    9088        }
     
    10199      // wait until job is started. if this does not happen, the Job is null an we give up
    102100      jobStartedSem.WaitOne(TimeSpan.FromSeconds(15));
    103       if (Job == null) {
     101      if (job == null) {
    104102        currentException = new Exception("Pausing job " + this.JobId + ": Job is null");
    105103        return;
    106104      }
    107105
    108       if (Job.ExecutionState == ExecutionState.Started) {
     106      if (job.ExecutionState == ExecutionState.Started) {
    109107        try {
    110           Job.Pause();
     108          job.Pause();
    111109          //we need to block the pause...
    112110          pauseStopSem.WaitOne();
     
    122120      // wait until job is started. if this does not happen, the Job is null an we give up
    123121      jobStartedSem.WaitOne(TimeSpan.FromSeconds(15));
    124       if (Job == null) {
     122      if (job == null) {
    125123        currentException = new Exception("Stopping job " + this.JobId + ": Job is null");
    126124      }
     
    129127      if ((ExecutionState == ExecutionState.Started) || (ExecutionState == ExecutionState.Paused)) {
    130128        try {
    131           Job.Stop();
     129          job.Stop();
    132130          pauseStopSem.WaitOne();
    133131        }
     
    139137
    140138    private void RegisterJobEvents() {
    141       Job.JobStopped += new EventHandler(Job_JobStopped);
    142       Job.JobFailed += new EventHandler(Job_JobFailed);
    143       Job.JobPaused += new EventHandler(Job_JobPaused);
    144       Job.JobStarted += new EventHandler(Job_JobStarted);
     139      job.JobStopped += new EventHandler(Job_JobStopped);
     140      job.JobFailed += new EventHandler(Job_JobFailed);
     141      job.JobPaused += new EventHandler(Job_JobPaused);
     142      job.JobStarted += new EventHandler(Job_JobStarted);
    145143    }
    146144
    147145    private void DeregisterJobEvents() {
    148       Job.JobStopped -= new EventHandler(Job_JobStopped);
    149       Job.JobFailed -= new EventHandler(Job_JobFailed);
    150       Job.JobPaused -= new EventHandler(Job_JobPaused);
    151       Job.JobStarted -= new EventHandler(Job_JobStarted);
     146      job.JobStopped -= new EventHandler(Job_JobStopped);
     147      job.JobFailed -= new EventHandler(Job_JobFailed);
     148      job.JobPaused -= new EventHandler(Job_JobPaused);
     149      job.JobStarted -= new EventHandler(Job_JobStarted);
    152150    }
    153151
     
    182180
    183181    public JobData GetJobData() {
    184       if (Job.ExecutionState == ExecutionState.Started) {
     182      if (jobDataInvalid) return null;
     183
     184      if (job.ExecutionState == ExecutionState.Started) {
    185185        throw new InvalidStateException("Job is still running");
    186186      } else {
    187187        JobData jobData = new JobData();
    188         if (Job == null) {
     188        if (job == null) {
    189189          //send empty job and save exception
    190190          jobData.Data = PersistenceUtil.Serialize(new JobData());
     
    193193          }
    194194        } else {
    195           jobData.Data = PersistenceUtil.Serialize(Job);
     195          jobData.Data = PersistenceUtil.Serialize(job);
    196196        }
    197197        jobData.JobId = JobId;
     
    201201
    202202    public void Dispose() {
    203       if (Job != null)
     203      if (job != null)
    204204        DeregisterJobEvents();
    205       Job = null;
     205      job = null;
    206206    }
    207207  }
Note: See TracChangeset for help on using the changeset viewer.