Free cookie consent management tool by TermsFeed Policy Generator

Changeset 2145


Ignore:
Timestamp:
07/07/09 12:49:24 (15 years ago)
Author:
gkronber
Message:

Fixed #694 (GridExecuter throws exceptions while no job can be started).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.CEDMA.Server/3.3/GridExecuter.cs

    r2128 r2145  
    5353    }
    5454
     55    private TimeSpan WaitForNewJobsInterval {
     56      get { return TimeSpan.FromSeconds(3); }
     57    }
     58
    5559    public GridExecuter(IDispatcher dispatcher, IStore store, IGridServer server)
    5660      : base(dispatcher, store) {
     
    8387            }
    8488          }
    85           WaitHandle[] whArr = asyncResults.Keys.ToArray();
    86           int readyHandleIndex = WaitAny(whArr, WaitForFinishedJobsTimeout);
    87           if (readyHandleIndex != WaitHandle.WaitTimeout) {
    88             WaitHandle readyHandle = whArr[readyHandleIndex];
    89             IAlgorithm finishedAlgorithm = null;
    90             AsyncGridResult finishedResult = null;
    91             lock (activeAlgorithms) {
    92               finishedResult = asyncResults[readyHandle];
    93               finishedAlgorithm = activeAlgorithms[finishedResult];
    94               activeAlgorithms.Remove(finishedResult);
    95               asyncResults.Remove(readyHandle);
     89          if (asyncResults.Count > 0) {
     90            WaitHandle[] whArr = asyncResults.Keys.ToArray();
     91            int readyHandleIndex = WaitAny(whArr, WaitForFinishedJobsTimeout);
     92            if (readyHandleIndex != WaitHandle.WaitTimeout) {
     93              WaitHandle readyHandle = whArr[readyHandleIndex];
     94              IAlgorithm finishedAlgorithm = null;
     95              AsyncGridResult finishedResult = null;
     96              lock (activeAlgorithms) {
     97                finishedResult = asyncResults[readyHandle];
     98                finishedAlgorithm = activeAlgorithms[finishedResult];
     99                activeAlgorithms.Remove(finishedResult);
     100                asyncResults.Remove(readyHandle);
     101              }
     102              OnChanged();
     103              try {
     104                IEngine finishedEngine = jobManager.EndExecuteEngine(finishedResult);
     105                SetResults(finishedEngine.GlobalScope, finishedAlgorithm.Engine.GlobalScope);
     106                StoreResults(finishedAlgorithm);
     107              }
     108              catch (Exception badEx) {
     109                HeuristicLab.Tracing.Logger.Error("CEDMA Executer: Exception in job execution thread. " + badEx.Message);
     110              }
    96111            }
    97             OnChanged();
    98             try {
    99               IEngine finishedEngine = jobManager.EndExecuteEngine(finishedResult);
    100               SetResults(finishedEngine.GlobalScope, finishedAlgorithm.Engine.GlobalScope);
    101               StoreResults(finishedAlgorithm);
    102             }
    103             catch (Exception badEx) {
    104               HeuristicLab.Tracing.Logger.Error("CEDMA Executer: Exception in job execution thread. " + badEx.Message);
    105             }
     112          } else {
     113            Thread.Sleep(WaitForNewJobsInterval);
    106114          }
    107115        }
     116
    108117        catch (Exception ex) {
    109118          HeuristicLab.Tracing.Logger.Warn("CEDMA Executer: Exception in job-management thread. " + ex.Message);
     
    112121    }
    113122
    114         // wait until any job is finished
     123    // wait until any job is finished
    115124    private int WaitAny(WaitHandle[] wh, TimeSpan WaitForFinishedJobsTimeout) {
    116125      if (wh.Length <= 64) {
Note: See TracChangeset for help on using the changeset viewer.