Free cookie consent management tool by TermsFeed Policy Generator

Changeset 245


Ignore:
Timestamp:
05/13/08 23:03:56 (16 years ago)
Author:
gkronber
Message:

fixed #150 (re-queueing of jobs that were not executed in time)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Grid/EngineStore.cs

    r221 r245  
    3131    private List<Guid> engineList;
    3232    private Dictionary<Guid, byte[]> waitingEngines;
     33    private Dictionary<Guid, byte[]> runningEngines;
    3334    private Dictionary<Guid, ManualResetEvent> waitHandles;
    3435    private Dictionary<Guid, byte[]> results;
    3536    private Dictionary<Guid, DateTime> resultDate;
     37    private Dictionary<Guid, DateTime> runningEngineDate;
     38    private const int RESULT_EXPIRY_TIME_MIN = 10;
     39    private const int RUNNING_JOB_EXPIRY_TIME_MIN = 10;
    3640    private object bigLock;
    37     private ChannelFactory<IClient> clientChannelFactory;
    3841    public int WaitingJobs {
    3942      get {
     
    5760      engineList = new List<Guid>();
    5861      waitingEngines = new Dictionary<Guid, byte[]>();
     62      runningEngines = new Dictionary<Guid, byte[]>();
    5963      waitHandles = new Dictionary<Guid, ManualResetEvent>();
    6064      results = new Dictionary<Guid, byte[]>();
    6165      resultDate = new Dictionary<Guid, DateTime>();
     66      runningEngineDate = new Dictionary<Guid, DateTime>();
    6267      bigLock = new object();
    6368
     
    6873      binding.Security.Mode = SecurityMode.None;
    6974
    70       clientChannelFactory = new ChannelFactory<IClient>(binding);
    7175    }
    7276
     
    8286          engine = waitingEngines[guid];
    8387          waitingEngines.Remove(guid);
     88          runningEngines[guid] = engine;
     89          runningEngineDate[guid] = DateTime.Now;
    8490          return true;
    8591        }
     
    9096      lock(bigLock) {
    9197        // clear old results
    92         List<Guid> expiredResults = FindExpiredResults(DateTime.Now.AddMinutes(-10.0));
     98        List<Guid> expiredResults = FindExpiredResults(DateTime.Now.AddMinutes(-RESULT_EXPIRY_TIME_MIN));
    9399        foreach(Guid expiredGuid in expiredResults) {
    94100          results.Remove(expiredGuid);
     
    97103        }
    98104        // add the new result
     105        runningEngines.Remove(guid);
     106        runningEngineDate.Remove(guid);
    99107        results[guid] = result;
    100108        resultDate[guid] = DateTime.Now;
     
    111119      }
    112120      return expiredResults;
     121    }
     122    private List<Guid> FindExpiredJobs(DateTime expirationDate) {
     123      List<Guid> expiredJobs = new List<Guid>();
     124      foreach(Guid guid in runningEngines.Keys) {
     125        if(runningEngineDate[guid] < expirationDate) {
     126          expiredJobs.Add(guid);
     127        }
     128      }
     129      return expiredJobs;
    113130    }
    114131
     
    139156          // result not yet available, if there is also no wait-handle for that result then we will never have a result and can return null
    140157          if(!waitHandles.ContainsKey(guid)) return null;
    141 
    142158          // otherwise we have a wait-handle and can wait for the result
    143159          ManualResetEvent waitHandle = waitHandles[guid];
     
    150166            return result;
    151167          } else {
    152             // no result yet return without result
     168            // no result yet, check for which jobs we waited too long and requeue those jobs
     169            List<Guid> expiredJobs = FindExpiredJobs(DateTime.Now.AddMinutes(-RUNNING_JOB_EXPIRY_TIME_MIN));
     170            foreach(Guid expiredGuid in expiredJobs) {
     171              engineList.Insert(0, expiredGuid);
     172              waitingEngines[expiredGuid] = runningEngines[expiredGuid];
     173              runningEngines.Remove(expiredGuid);
     174              runningEngineDate.Remove(expiredGuid);
     175            }
    153176            return null;
    154177          }
     
    158181
    159182    internal void AbortEngine(Guid guid) {
    160       lock(bigLock) {
    161         if(waitingEngines.ContainsKey(guid)) {
    162           byte[] engine = waitingEngines[guid];
    163           waitingEngines.Remove(guid);
    164           engineList.Remove(guid);
    165           waitHandles[guid].Set();
    166           results.Add(guid, engine);
    167         }
    168       }
     183      throw new NotImplementedException();
    169184    }
    170185
Note: See TracChangeset for help on using the changeset viewer.