Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/05/15 17:09:10 (9 years ago)
Author:
ascheibe
Message:

#2353

  • improved performance of status page
  • fixed code formatting and usings
  • simplified some expressions
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Services.Hive.Web/Hive-3.3/Status.aspx.cs

    r12012 r12146  
    2323using System.Collections.Generic;
    2424using System.Linq;
    25 using System.Web;
    26 using System.Web.UI;
    2725using System.Web.UI.WebControls;
    28 using HeuristicLab.Services.Hive.DataAccess;
    2926using HeuristicLab.Services.Hive;
    30 using HeuristicLab.Services.Hive.DataTransfer;
    31 using System.Text;
    3227using System.Web.UI.DataVisualization.Charting;
    3328using DA = HeuristicLab.Services.Hive.DataAccess;
     
    3732  protected void Page_Load(object sender, EventArgs e) {
    3833    var dao = ServiceLocator.Instance.HiveDao;
     34    var optDao = ServiceLocator.Instance.OptimizedHiveDao;
    3935    var transactionManager = ServiceLocator.Instance.TransactionManager;
    4036    var resourceName = Request.QueryString["resource"];
    41     IEnumerable<Guid> resourceIds = new List<Guid>();
    42     IEnumerable<DT.Slave> onlineSlaves = new List<DT.Slave>();
     37    List<Guid> resourceIds = new List<Guid>();
     38    List<DT.Slave> onlineSlaves = new List<DT.Slave>();
    4339    int currentlyJobsWaiting = 0;
    44     Dictionary<Guid, int> calculatingTasksByUser = new Dictionary<Guid,int>();
     40    Dictionary<Guid, int> calculatingTasksByUser = new Dictionary<Guid, int>();
    4541    Dictionary<Guid, int> waitingTasksByUser = new Dictionary<Guid, int>();
    4642    List<DT.Resource> groups = new List<DT.Resource>();
    4743
    4844    transactionManager.UseTransaction(() => {
    49        groups = dao.GetResources(x => x.ResourceType == "GROUP").ToList();
    50     }, false, false);   
     45      groups = dao.GetResources(x => x.ResourceType == "GROUP").ToList();
     46    }, false, false);
    5147
    5248    if (!string.IsNullOrEmpty(resourceName)) {
    53         transactionManager.UseTransaction(() =>
    54         {
    55             var resId = dao.GetResources(x => x.Name == resourceName).Single().Id;
    56             resourceIds = dao.GetChildResources(resId).Select(x => x.Id).Union(new List<Guid> { resId });
    57             calculatingTasksByUser = dao.GetCalculatingTasksByUserForResources(resourceIds.ToList());
    58             waitingTasksByUser = dao.GetWaitingTasksByUserForResources(resourceIds.ToList());
    59         }, false, false);       
     49      transactionManager.UseTransaction(() => {
     50        var resId = dao.GetResources(x => x.Name == resourceName).Single().Id;
     51        resourceIds = dao.GetChildResources(resId).Select(x => x.Id).Union(new List<Guid> { resId }).ToList();
     52        calculatingTasksByUser = dao.GetCalculatingTasksByUserForResources(resourceIds);
     53        waitingTasksByUser = dao.GetWaitingTasksByUserForResources(resourceIds);
     54      }, false, false);
    6055    } else {
    61         transactionManager.UseTransaction(() =>
    62         {
    63              resourceIds = dao.GetResources(x => true).Select(y => y.Id);
    64              calculatingTasksByUser = dao.GetCalculatingTasksByUser();
    65              waitingTasksByUser = dao.GetWaitingTasksByUser();           
    66         }, false, false);
    67     }   
     56      transactionManager.UseTransaction(() => {
     57        resourceIds = optDao.GetAllResourceIds().ToList();
     58        calculatingTasksByUser = optDao.GetCalculatingTasksByUser();
     59        waitingTasksByUser = optDao.GetWaitingTasksByUser();
     60      }, false, false);
     61    }
    6862
    69     transactionManager.UseTransaction(() =>
    70     {                     
    71         onlineSlaves = dao.GetSlaves(x => (x.SlaveState == DA.SlaveState.Calculating || x.SlaveState == DA.SlaveState.Idle) && resourceIds.Contains(x.ResourceId));
    72         currentlyJobsWaiting = dao.GetLightweightTasks(x => x.State == DA.TaskState.Waiting).Count();           
     63    transactionManager.UseTransaction(() => {
     64      if (string.IsNullOrEmpty(resourceName)) {
     65        onlineSlaves = dao.GetSlaves(x => x.SlaveState == DA.SlaveState.Calculating || x.SlaveState == DA.SlaveState.Idle).ToList();
     66      } else {
     67        onlineSlaves = dao.GetSlaves(x => (x.SlaveState == DA.SlaveState.Calculating || x.SlaveState == DA.SlaveState.Idle) && resourceIds.Contains(x.ResourceId)).ToList();
     68      }
     69      currentlyJobsWaiting = optDao.GetNumberOfWaitingTasks();
    7370    }, false, false);
    7471
     
    7673    int currentlyAvailableCores = onlineSlaves.Where(s => s.Cores.HasValue && s.IsAllowedToCalculate).Sum(s => s.Cores.Value);
    7774    int currentlyUsedCores = overallCurrentlyAvailableCores - onlineSlaves.Where(s => s.FreeCores.HasValue).Sum(s => s.FreeCores.Value);
    78    
     75
    7976    this.overallAvailableCoresLabel.Text = overallCurrentlyAvailableCores.ToString();
    8077    this.availableCoresLabel.Text = currentlyAvailableCores.ToString();
     
    8683    groupsLabel.Text += string.Join(", ", groups.Select(x => string.Format("<a href=\"?resource={0}\">{0}</a>", x.Name)));
    8784
    88     overallCpuUtilizationLabel.Text = (onlineSlaves.Count() > 0 ? Math.Round(onlineSlaves.Average(s => s.CpuUtilization), 2).ToString() : "0.0") + " %";
    89     cpuUtilizationLabel.Text = (onlineSlaves.Count() > 0 && onlineSlaves.Where(x => x.IsAllowedToCalculate).Count() > 0 ? Math.Round(onlineSlaves.Where(x => x.IsAllowedToCalculate).Average(s => s.CpuUtilization), 2).ToString() : "0.0") + " %";
     85    overallCpuUtilizationLabel.Text = (onlineSlaves.Any() ? Math.Round(onlineSlaves.Average(s => s.CpuUtilization), 2).ToString() : "0.0") + " %";
     86    cpuUtilizationLabel.Text = (onlineSlaves.Any() && onlineSlaves.Any(x => x.IsAllowedToCalculate) ? Math.Round(onlineSlaves.Where(x => x.IsAllowedToCalculate).Average(s => s.CpuUtilization), 2).ToString() : "0.0") + " %";
    9087
    91     DT.Statistics[] stats = new DT.Statistics[0];   
    92     transactionManager.UseTransaction(() =>
    93     {   
    94         if (daysDropDownList.SelectedValue == "All") {
    95           stats = dao.GetStatistics(x => true).OrderBy(x => x.TimeStamp).ToArray();
    96         } else {
    97           stats = dao.GetStatistics(x => x.Timestamp >= DateTime.Now.Subtract(TimeSpan.FromDays(int.Parse(daysDropDownList.SelectedValue)))).OrderBy(x => x.TimeStamp).ToArray();
    98         }
     88    DT.Statistics[] stats = new DT.Statistics[0];
     89    transactionManager.UseTransaction(() => {
     90      if (daysDropDownList.SelectedValue == "All") {
     91        stats = dao.GetStatistics(x => true).OrderBy(x => x.TimeStamp).ToArray();
     92      } else {
     93        stats = dao.GetStatistics(x => x.Timestamp >= DateTime.Now.Subtract(TimeSpan.FromDays(int.Parse(daysDropDownList.SelectedValue)))).OrderBy(x => x.TimeStamp).ToArray();
     94      }
    9995    }, false, false);
    100    
     96
    10197    for (int i = 0; i < stats.Length; i++) {
    10298      var s = stats[i];
    103       var slaveStats = s.SlaveStatistics.Where(x => resourceIds.Contains(x.SlaveId));
     99      var slaveStats = s.SlaveStatistics.Where(x => resourceIds.Contains(x.SlaveId)).ToArray();
    104100
    105       var averageCpuUtilization = slaveStats.Count() > 0 ? slaveStats.Average(x => x.CpuUtilization) : 0.0;
     101      var averageCpuUtilization = slaveStats.Any() ? slaveStats.Average(x => x.CpuUtilization) : 0.0;
    106102      cpuUtilizationChart.Series[0].Points.Add(new DataPoint(s.TimeStamp.ToOADate(), averageCpuUtilization));
    107103
     
    118114    }
    119115
    120     GenerateTasksByUserTable(waitingTasksByUser, waitingTasksByUserTable); 
    121     GenerateTasksByUserTable(calculatingTasksByUser, calculatingTasksByUserTable); 
     116    GenerateTasksByUserTable(waitingTasksByUser, waitingTasksByUserTable);
     117    GenerateTasksByUserTable(calculatingTasksByUser, calculatingTasksByUserTable);
    122118  }
    123119
     
    134130      table.Rows.Add(curRow);
    135131    }
    136     if (tasksByUser.Count() > 0) {
    137       TableRow sumRow = new TableRow();       
     132    if (tasksByUser.Any()) {
     133      TableRow sumRow = new TableRow();
    138134      TableCell sumCell = new TableCell();
    139135      sumCell.BorderWidth = Unit.Pixel(3);
     
    143139      table.Rows.Add(sumRow);
    144140    }
    145   } 
     141  }
    146142}
Note: See TracChangeset for help on using the changeset viewer.