Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/19/15 18:06:19 (9 years ago)
Author:
dglaser
Message:

#2388: Updated Hive, DataAccess and WebApp

HeuristicLab.Services.Hive.DataAccess:

  • Updated database statistics schema

HeuristicLab.Services.Hive:

  • Fixed event flag in HiveJanitor Service
  • Improved UpdateTaskFactsTable in the HiveStatisticsGenerator

HeuristicLab.Services.WebApp:

  • Updated Statistics DataController to match the new statistics schema
Location:
branches/HiveStatistics/sources/HeuristicLab.Services.Hive/3.3
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/HiveStatistics/sources/HeuristicLab.Services.Hive/3.3/HiveJanitor.cs

    r12477 r12484  
    4949    public HiveJanitor() {
    5050      stop = false;
    51       cleanupWaitHandle = new AutoResetEvent(true);
    52       generateStatisticsWaitHandle = new AutoResetEvent(true);
     51      cleanupWaitHandle = new AutoResetEvent(false);
     52      generateStatisticsWaitHandle = new AutoResetEvent(false);
    5353    }
    5454
  • branches/HiveStatistics/sources/HeuristicLab.Services.Hive/3.3/HiveStatisticsGenerator.cs

    r12477 r12484  
    3838          UpdateDimUserTable(pm);
    3939          UpdateDimJobTable(pm);
    40           UpdateDimClients(pm);
     40          UpdateDimClientsTable(pm);
    4141          pm.SubmitChanges();
    4242        });
     
    4747            pm.SubmitChanges();
    4848            UpdateFactClientInfoTable(newTime, pm);
    49             UpdateTaskFacts(newTime, pm);
     49            UpdateTaskFactsTable(newTime, pm);
    5050            try {
    5151              pm.SubmitChanges();
     
    6767      var now = DateTime.Now;
    6868      var timeEntry = new DimTime {
    69         Time = new DateTime(now.Year, now.Month, now.Day, now.Hour, now.Minute, 0),
     69        Time = now,
     70        Minute = new DateTime(now.Year, now.Month, now.Day, now.Hour, now.Minute, 0),
    7071        Hour = new DateTime(now.Year, now.Month, now.Day, now.Hour, 0, 0),
    7172        Day = new DateTime(now.Year, now.Month, now.Day, 0, 0, 0),
     
    7374        Year = new DateTime(now.Year, 1, 1, 0, 0, 0)
    7475      };
    75       // using SaveOrAttach instead of save because the table can only be updated once every minute
    76       // (pk restriction) save would cause a duplicate key exception if the method is accidentally
    77       // called more than once every minute (e.g. restarting the service within a minute)
    78       return dimTimeDao.SaveOrAttach(timeEntry);
     76      return dimTimeDao.Save(timeEntry);
    7977    }
    8078
     
    118116    }
    119117
    120     private void UpdateDimClients(PersistenceManager pm) {
     118    private void UpdateDimClientsTable(PersistenceManager pm) {
    121119      var dimClientDao = pm.DimClientDao;
    122120      var slaveDao = pm.SlaveDao;
     
    208206    }
    209207
    210     private void UpdateTaskFacts(DimTime newTime, PersistenceManager pm) {
     208    private void UpdateTaskFactsTable(DimTime newTime, PersistenceManager pm) {
    211209      var factTaskDao = pm.FactTaskDao;
    212210      var taskDao = pm.TaskDao;
     
    217215      var notFinishedFactTasks = factTaskDao.GetNotFinishedTasks().Select(x => new {
    218216        x.TaskId,
    219         x.DimTimeStart,
    220217        x.LastClientId
    221218      });
     
    238235          MemoryRequired = task.MemoryNeeded,
    239236          State = task.State,
    240           StateLogs = stateLogs,
    241           DimTimeStart = lastFact != null ? lastFact.DimTimeStart : newTime,
     237          StateLogs = stateLogs.OrderBy(x => x.DateTime),
    242238          LastClientId = client != null
    243239                         ? client.Id : lastFact != null
    244240                         ? lastFact.LastClientId : (Guid?)null
    245241        };
    246 
    247       var endStates = new[] { TaskState.Finished, TaskState.Failed, TaskState.Aborted };
    248242      factTaskDao.Save(
    249243        from x in newTasks.ToList()
    250         let stateLogsLinkedList = new LinkedList<StateLog>(x.StateLogs.OrderBy(y => y.DateTime))
    251         let lastStateLog = stateLogsLinkedList.OrderByDescending(y => y.DateTime).FirstOrDefault(sl => sl.Exception != null)
     244        let taskData = CalculateFactTaskData(x.StateLogs)
    252245        select new FactTask {
    253246          TaskId = x.TaskId,
    254247          JobId = x.JobId,
    255           DimTimeStart = x.DimTimeStart,
    256           DimTimeEnd = endStates.Contains(x.State) ? newTime : null,
     248          StartTime = taskData.StartTime,
     249          EndTime = taskData.EndTime,
    257250          LastClientId = x.LastClientId,
    258251          Priority = x.Priority,
    259252          CoresRequired = x.CoresRequired,
    260253          MemoryRequired = x.MemoryRequired,
    261           NumCalculationRuns = stateLogsLinkedList.CountCalculationRuns(),
    262           NumRetries = stateLogsLinkedList.CountRetries(),
    263           TotalWaitingTime = stateLogsLinkedList.SumTotalTimeWhere(stateLog => stateLog.Value.State == TaskState.Waiting),
    264           TotalRuntime = stateLogsLinkedList.SumTotalTimeWhere(stateLog => stateLog.Value.State == TaskState.Calculating && stateLog.NextIs(y => y.State == TaskState.Transferring)),
    265           TotalTransferTime = stateLogsLinkedList.SumTotalTimeWhere(stateLog => stateLog.Value.State == TaskState.Transferring),
     254          NumCalculationRuns = taskData.CalculationRuns,
     255          NumRetries = taskData.Retries,
     256          WaitingTime = taskData.WaitingTime,
     257          CalculatingTime = taskData.CalculatingTime,
     258          TransferTime = taskData.TransferTime,
    266259          TaskState = x.State,
    267           Exception = lastStateLog == null ? string.Empty : lastStateLog.Exception
     260          Exception = taskData.Exception,
     261          InitialWaitingTime = taskData.InitialWaitingTime
    268262        });
    269263      factTaskDao.Delete(notFinishedFactTasks.Select(x => x.TaskId));
     
    280274      }
    281275    }
    282   }
    283 
    284   public static class StateLogLinkedListExtensions {
    285     public static int CountCalculationRuns(this LinkedList<StateLog> stateLogs) {
    286       return stateLogs.EnumerateNodes()
    287                       .Count(sl => sl.Value.State == TaskState.Calculating && sl.NextIs(nsl => nsl.State == TaskState.Transferring));
    288     }
    289 
    290     public static int CountRetries(this LinkedList<StateLog> stateLogs) {
    291       return stateLogs.EnumerateNodes()
    292                       .Count(sl => sl.Value.State == TaskState.Calculating && sl.Next != null && sl.NextIs(nsl => nsl.State != TaskState.Transferring));
    293     }
    294 
    295     public static double SumTotalTimeWhere(this LinkedList<StateLog> stateLogs, Predicate<LinkedListNode<StateLog>> predicate) {
    296       return stateLogs.EnumerateNodes()
    297                       .Where(stateLog => predicate(stateLog))
    298                       .Sum(stateLog => stateLog.Next != null ? (stateLog.Next.Value.DateTime - stateLog.Value.DateTime).TotalMinutes : 0.0);
    299     }
    300   }
    301 
    302   public static class LinkedListExtensions {
    303     public static IEnumerable<LinkedListNode<T>> EnumerateNodes<T>(this LinkedList<T> list) {
    304       var node = list.First;
    305       while (node != null) {
    306         yield return node;
    307         node = node.Next;
     276
     277    private class FactTaskData {
     278      public int CalculationRuns { get; set; }
     279      public int Retries { get; set; }
     280      public double CalculatingTime { get; set; }
     281      public double WaitingTime { get; set; }
     282      public double TransferTime { get; set; }
     283      public double InitialWaitingTime { get; set; }
     284      public string Exception { get; set; }
     285      public DateTime? StartTime { get; set; }
     286      public DateTime? EndTime { get; set; }
     287    }
     288
     289    private FactTaskData CalculateFactTaskData(IEnumerable<StateLog> stateLogs) {
     290      var factTaskData = new FactTaskData();
     291      var enumerator = stateLogs.GetEnumerator();
     292      if (enumerator.MoveNext()) {
     293        StateLog current = enumerator.Current, first = current, prev = null;
     294        while (current != null) {
     295          var next = enumerator.MoveNext() ? enumerator.Current : null;
     296          int timeSpanInSeconds;
     297          if (next != null) {
     298            timeSpanInSeconds = (int)(next.DateTime - current.DateTime).TotalSeconds;
     299          } else {
     300            timeSpanInSeconds = (int)(DateTime.Now - current.DateTime).TotalSeconds;
     301            factTaskData.Exception = current.Exception;
     302          }
     303          switch (current.State) {
     304            case TaskState.Calculating:
     305              factTaskData.CalculatingTime += timeSpanInSeconds;
     306              factTaskData.CalculationRuns++;
     307              if (factTaskData.CalculationRuns == 1) {
     308                factTaskData.StartTime = current.DateTime;
     309                factTaskData.InitialWaitingTime = (int)(current.DateTime - first.DateTime).TotalSeconds;
     310              }
     311              if (prev != null && prev.State != TaskState.Transferring) {
     312                factTaskData.Retries++;
     313              }
     314              break;
     315
     316            case TaskState.Waiting:
     317              factTaskData.WaitingTime += timeSpanInSeconds;
     318              break;
     319
     320            case TaskState.Transferring:
     321              factTaskData.TransferTime += timeSpanInSeconds;
     322              break;
     323
     324            case TaskState.Finished:
     325            case TaskState.Failed:
     326            case TaskState.Aborted:
     327              factTaskData.EndTime = current.DateTime;
     328              break;
     329          }
     330          prev = current;
     331          current = next;
     332        }
    308333      }
    309     }
    310 
    311     public static bool NextIs<T>(this LinkedListNode<T> node, Predicate<T> predicate) {
    312       return node.Next != null && predicate(node.Next.Value);
     334      return factTaskData;
    313335    }
    314336  }
Note: See TracChangeset for help on using the changeset viewer.