Free cookie consent management tool by TermsFeed Policy Generator

Changeset 9561


Ignore:
Timestamp:
05/31/13 15:46:38 (11 years ago)
Author:
pfleck
Message:

#2063:
Simplified and optimized query for task fact statistics.

File:
1 edited

Legend:

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

    r9560 r9561  
    223223    private void UpdateTaskFacts(DimTime newTime, HiveDataContext db) {
    224224      var lastFacts =
    225         from f in db.FactTasks
    226         group f by f.TaskId into grpFacts
    227         select grpFacts.OrderByDescending(x => x.EndTime).First();
    228 
    229       var tasksWithLastFact =
    230         from t in db.Tasks
    231         join lf in lastFacts on t.TaskId equals lf.TaskId into tLfJoin
    232         from lWithLf in tLfJoin.DefaultIfEmpty()
    233         where !t.IsParentTask
    234         select new { Task = t, TaskDataSize = t.JobData.DataSize, LastFact = tLfJoin.FirstOrDefault() };
    235 
    236       var tasksWithNewStateLogs =
    237         from sl in db.StateLogs
    238         join twlf in tasksWithLastFact on sl.TaskId equals twlf.Task.TaskId
    239         where (twlf.LastFact == null || sl.DateTime > twlf.LastFact.EndTime) && sl.DateTime < newTime.Time
    240         group sl by twlf.Task into factGroup
    241         select new {
    242           Task = factGroup.Key,
    243           StateLogs = factGroup.OrderBy(x => x.DateTime),
    244           LastSlave = factGroup.OrderByDescending(x => x.DateTime).First(x => x.SlaveId != null).SlaveId
    245         };
    246 
    247       var tasksWithLastFactsAndStateLogs =
    248         from twsl in tasksWithNewStateLogs
    249         join twlf in tasksWithLastFact on twsl.Task equals twlf.Task
    250         select new { twlf.Task, twlf.TaskDataSize, twlf.LastFact, twsl.StateLogs, twsl.LastSlave };
    251 
    252       var clients =
    253         from cl in db.DimClients
    254         //where cl.ExpirationTime == null
    255         select cl;
    256 
    257       var tasksWithLastFactsAndStateLogsAndLastResource =
    258         from twlfasl in tasksWithLastFactsAndStateLogs
    259         join cl in clients on twlfasl.LastSlave equals cl.ResourceId into clJoinGrp
    260         from cl in clJoinGrp.DefaultIfEmpty()
    261         select new { twlfasl.Task, twlfasl.TaskDataSize, twlfasl.LastFact, twlfasl.StateLogs, LastClient = cl };
     225        from fact in db.FactTasks
     226        group fact by fact.TaskId into factsPerTask
     227        select factsPerTask.OrderByDescending(x => x.EndTime).First();
     228
     229      var lastFactAndStateLogsAndLastClientPerTask =
     230        from task in db.Tasks.Where(task => !task.IsParentTask)
     231        join lastFact in lastFacts on task.TaskId equals lastFact.TaskId into lastFactsPerTask
     232        from lastFact in lastFactsPerTask.DefaultIfEmpty()
     233        let newStateLogs = task.StateLogs.Where(stateLog => (lastFact == null || stateLog.DateTime > lastFact.EndTime) && stateLog.DateTime < newTime.Time)
     234        let lastSlaveId = newStateLogs.OrderByDescending(stateLog => stateLog.DateTime).First(stateLog => stateLog.SlaveId != null).SlaveId
     235        join client in db.DimClients.Where(client => client.ExpirationTime == null) on lastSlaveId equals client.ResourceId into clientPerTask
     236        from client in clientPerTask.DefaultIfEmpty()
     237        select new {
     238          Task = task,
     239          TaskDataSize = task.JobData.DataSize,
     240          LastFact = lastFact,
     241          StateLogs = newStateLogs.OrderBy(stateLog => stateLog.DateTime),
     242          LastClientId = client != null ? client.Id : default(Guid?)
     243        };
    262244
    263245      var newTaskFacts =
    264         from t in tasksWithLastFactsAndStateLogsAndLastResource.ToList()
     246        from t in lastFactAndStateLogsAndLastClientPerTask.ToList()
    265247        select new FactTask {
    266248          TaskId = t.Task.TaskId,
     
    268250          DimTimeStart = t.LastFact != null ? t.LastFact.DimTimeStart : newTime,
    269251          DimTimeEnd = newTime,
    270           LastClientId = t.LastClient != null ? t.LastClient.Id : (t.LastFact != null ? t.LastFact.LastClientId : Guid.Empty),
     252          LastClientId = t.LastClientId ?? (t.LastFact != null ? t.LastFact.LastClientId : Guid.Empty),
    271253          Priority = t.Task.Priority,
    272254          CoresRequired = t.Task.CoresNeeded,
Note: See TracChangeset for help on using the changeset viewer.