Changeset 12767


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

#2429:

  • Improved FactClientInfo aggregation
  • Added input field to specify how many entries should be aggregated
Location:
branches/HiveStatistics/sources/HeuristicLab.Services.WebApp.Maintenance/3.3
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/HiveStatistics/sources/HeuristicLab.Services.WebApp.Maintenance/3.3/HeuristicLab.Services.WebApp.Maintenance-3.3.csproj

    r12761 r12767  
    4040    <Reference Include="Newtonsoft.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
    4141      <SpecificVersion>False</SpecificVersion>
    42       <HintPath>..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
     42      <HintPath>..\..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
    4343      <Private>False</Private>
    4444    </Reference>
    45     <Reference Include="System" />
    46     <Reference Include="System.Core" />
    47     <Reference Include="System.Net.Http" />
     45    <Reference Include="System">
     46      <Private>False</Private>
     47    </Reference>
     48    <Reference Include="System.Core">
     49      <Private>False</Private>
     50    </Reference>
     51    <Reference Include="System.Net.Http">
     52      <Private>False</Private>
     53    </Reference>
    4854    <Reference Include="System.Net.Http.Formatting, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
    4955      <SpecificVersion>False</SpecificVersion>
    50       <HintPath>..\packages\Microsoft.AspNet.WebApi.Client.5.2.3\lib\net45\System.Net.Http.Formatting.dll</HintPath>
     56      <HintPath>..\..\packages\Microsoft.AspNet.WebApi.Client.5.2.3\lib\net45\System.Net.Http.Formatting.dll</HintPath>
    5157      <Private>False</Private>
    5258    </Reference>
    5359    <Reference Include="System.Web.Http, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
    5460      <SpecificVersion>False</SpecificVersion>
    55       <HintPath>..\packages\Microsoft.AspNet.WebApi.Core.5.2.3\lib\net45\System.Web.Http.dll</HintPath>
     61      <HintPath>..\..\packages\Microsoft.AspNet.WebApi.Core.5.2.3\lib\net45\System.Web.Http.dll</HintPath>
    5662      <Private>False</Private>
    5763    </Reference>
    5864    <Reference Include="System.Web.Http.WebHost, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
    5965      <SpecificVersion>False</SpecificVersion>
    60       <HintPath>..\packages\Microsoft.AspNet.WebApi.WebHost.5.2.3\lib\net45\System.Web.Http.WebHost.dll</HintPath>
     66      <HintPath>..\..\packages\Microsoft.AspNet.WebApi.WebHost.5.2.3\lib\net45\System.Web.Http.WebHost.dll</HintPath>
    6167      <Private>False</Private>
    6268    </Reference>
    63     <Reference Include="System.Xml.Linq" />
    64     <Reference Include="System.Data.DataSetExtensions" />
    65     <Reference Include="Microsoft.CSharp" />
    66     <Reference Include="System.Data" />
    67     <Reference Include="System.Xml" />
     69    <Reference Include="System.Xml.Linq">
     70      <Private>False</Private>
     71    </Reference>
     72    <Reference Include="System.Data.DataSetExtensions">
     73      <Private>False</Private>
     74    </Reference>
     75    <Reference Include="Microsoft.CSharp">
     76      <Private>False</Private>
     77    </Reference>
     78    <Reference Include="System.Data">
     79      <Private>False</Private>
     80    </Reference>
     81    <Reference Include="System.Xml">
     82      <Private>False</Private>
     83    </Reference>
    6884  </ItemGroup>
    6985  <ItemGroup>
     
    7995    <Compile Include="WebApi\PluginController.cs" />
    8096    <Compile Include="WebApi\SpaceUsageController.cs" />
    81     <Compile Include="WebApi\CleanupController.cs" />
    8297  </ItemGroup>
    8398  <ItemGroup>
    8499    <None Include="app.config" />
    85100    <None Include="HeuristicLab.snk" />
    86     <None Include="packages.config" />
    87101    <Content Include="WebApp\factclientinfo\factclientinfoCtrl.js">
    88102      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
     
    92106    </Content>
    93107    <Content Include="WebApp\plugin\plugin.cshtml">
     108      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
     109    </Content>
     110    <None Include="packages.config" />
     111    <Content Include="Web.config">
    94112      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    95113    </Content>
  • 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    }
  • branches/HiveStatistics/sources/HeuristicLab.Services.WebApp.Maintenance/3.3/WebApp/factclientinfo/factclientinfo.cshtml

    r12761 r12767  
    5454                <div class="panel-body">
    5555                    <form class="form-inline">
    56                         <p>
    57                             Rows: {{factClientInfo.Rows}}<br/>
    58                             Clients: {{factClientInfo.Clients}}
    59                         </p>
     56                        <div class="form-group" style="margin-left: 5px; margin-right: 5px;">
     57                            <label>Rows:&nbsp;{{factClientInfo.Rows}}</label>
     58                        </div>
     59                        <div class="form-group" style="margin-left: 5px; margin-right: 5px;">
     60                            <label>Clients:&nbsp;{{factClientInfo.Clients}}</label>
     61                        </div>
     62                        <div class="form-group" style="margin-left: 5px; margin-right: 5px;">
     63                            <label for="entries">Entries:&nbsp;</label>
     64                            <input id="entries" type="number" class="form-control"
     65                                   ng-model="entries" min="2"/>
     66                        </div>
    6067                        <div class="form-group" style="margin-left: 5px; margin-right: 5px;">
    6168                            <button type="button" class="btn btn-default" ng-click="aggregate()">
Note: See TracChangeset for help on using the changeset viewer.