Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/16/15 12:31:59 (9 years ago)
Author:
dglaser
Message:

#2429:

  • Improved FactClientInfo aggregation
  • Added input field to specify how many entries should be aggregated
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HiveStatistics/sources/HeuristicLab.Services.WebApp.Maintenance/3.3/WebApi/FactClientInfoController.cs

    r12761 r12767  
    6565      var factClientInfoDao = pm.FactClientInfoDao;
    6666      var clientInfos = pm.UseTransaction(() => factClientInfoDao.GetByClientId(clientId).OrderBy(x => x.Time).ToList());
    67       FactClientInfo lastClientInfo = null, sumClientInfo = new FactClientInfo();
    68       int counter = 0;
    69       var aggregatedClientInfos = new List<FactClientInfo>();
    70       foreach (var clientInfo in clientInfos) {
    71         if (lastClientInfo != null) {
    72           if (lastClientInfo.SlaveState != clientInfo.SlaveState ||
    73               lastClientInfo.IsAllowedToCalculate != clientInfo.IsAllowedToCalculate) {
    74             // update into 'lastClientInfo'
    75             if (aggregatedClientInfos.Any()) {
    76               counter = aggregatedClientInfos.Count();
    77               pm.UseTransaction(() => {
    78                 factClientInfoDao.Delete(aggregatedClientInfos);
    79                 lastClientInfo.NumUsedCores = sumClientInfo.NumUsedCores / counter;
    80                 lastClientInfo.NumTotalCores = sumClientInfo.NumTotalCores / counter;
    81                 lastClientInfo.UsedMemory = sumClientInfo.UsedMemory / counter;
    82                 lastClientInfo.TotalMemory = sumClientInfo.TotalMemory / counter;
    83                 lastClientInfo.CpuUtilization = sumClientInfo.CpuUtilization / counter;
    84                 lastClientInfo.IdleTime = sumClientInfo.IdleTime;
    85                 lastClientInfo.OfflineTime = sumClientInfo.OfflineTime;
    86                 lastClientInfo.UnavailableTime = sumClientInfo.UnavailableTime;
    87                 pm.SubmitChanges();
    88               });
    89             }
    90             aggregatedClientInfos.Clear();
    91             counter = 0;
    92             sumClientInfo = new FactClientInfo();
    93           } else {
    94             // sum up
    95             sumClientInfo.NumUsedCores += clientInfo.NumUsedCores;
    96             sumClientInfo.NumTotalCores += clientInfo.NumTotalCores;
    97             sumClientInfo.UsedMemory += clientInfo.UsedMemory;
    98             sumClientInfo.TotalMemory += clientInfo.TotalMemory;
    99             sumClientInfo.CpuUtilization += clientInfo.CpuUtilization;
    100             sumClientInfo.IdleTime += clientInfo.IdleTime;
    101             sumClientInfo.OfflineTime += clientInfo.OfflineTime;
    102             sumClientInfo.UnavailableTime += clientInfo.UnavailableTime;
    103             counter++;
    104             if (counter >= entries) {
    105               pm.UseTransaction(() => {
    106                 factClientInfoDao.Delete(aggregatedClientInfos);
    107                 clientInfo.NumUsedCores = sumClientInfo.NumUsedCores / counter;
    108                 clientInfo.NumTotalCores = sumClientInfo.NumTotalCores / counter;
    109                 clientInfo.UsedMemory = sumClientInfo.UsedMemory / counter;
    110                 clientInfo.TotalMemory = sumClientInfo.TotalMemory / counter;
    111                 clientInfo.CpuUtilization = sumClientInfo.CpuUtilization / counter;
    112                 clientInfo.IdleTime = sumClientInfo.IdleTime;
    113                 clientInfo.OfflineTime = sumClientInfo.OfflineTime;
    114                 clientInfo.UnavailableTime = sumClientInfo.UnavailableTime;
    115                 pm.SubmitChanges();
    116               });
    117               aggregatedClientInfos.Clear();
    118               counter = 0;
    119               sumClientInfo = new FactClientInfo();
    120             } else {
    121               aggregatedClientInfos.Add(clientInfo);
    122             }
    123           }
     67      var e = clientInfos.GetEnumerator();
     68      if (!e.MoveNext()) return;
     69      do {
     70        var infosToAggregate = new List<FactClientInfo> { e.Current };
     71        var prev = e.Current;
     72        while (infosToAggregate.Count() != entries && e.MoveNext()) {
     73          var cur = e.Current;
     74          if (prev.IsAllowedToCalculate != cur.IsAllowedToCalculate || prev.SlaveState != cur.SlaveState)
     75            break;
     76          infosToAggregate.Add(cur);
     77          prev = cur;
    12478        }
    125         lastClientInfo = clientInfo;
     79        if (infosToAggregate.Count() == entries) {
     80          AggregateClientInfos(pm, infosToAggregate);
     81        }
     82      } while (e.MoveNext());
     83    }
     84
     85    private void AggregateClientInfos(IPersistenceManager pm, List<FactClientInfo> clientInfos) {
     86      var factClientInfoDao = pm.FactClientInfoDao;
     87      var last = clientInfos.Last();
     88      var infos = clientInfos.GroupBy(x => x.ClientId).Select(x => new {
     89        NumUsedCores = (int)x.Average(y => y.NumUsedCores),
     90        NumTotalCores = (int)x.Average(y => y.NumTotalCores),
     91        UsedMemory = (int)x.Average(y => y.UsedMemory),
     92        TotalMemory = (int)x.Average(y => y.TotalMemory),
     93        CpuUtilization = Math.Round(x.Average(y => y.CpuUtilization), 2),
     94        IdleTime = x.Sum(y => y.IdleTime),
     95        OfflineTime = x.Sum(y => y.OfflineTime),
     96        UnavailableTime = x.Sum(y => y.UnavailableTime)
     97      }).SingleOrDefault();
     98      if (infos != null) {
     99        pm.UseTransaction(() => {
     100          last.NumUsedCores = infos.NumUsedCores;
     101          last.NumTotalCores = infos.NumTotalCores;
     102          last.UsedMemory = infos.UsedMemory;
     103          last.TotalMemory = infos.TotalMemory;
     104          last.CpuUtilization = infos.CpuUtilization;
     105          last.IdleTime = infos.IdleTime;
     106          last.OfflineTime = infos.OfflineTime;
     107          last.UnavailableTime = infos.UnavailableTime;
     108          clientInfos.Remove(last);
     109          factClientInfoDao.Delete(clientInfos);
     110          pm.SubmitChanges();
     111        });
    126112      }
    127113    }
Note: See TracChangeset for help on using the changeset viewer.