Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Services.Hive.Web/Hive-3.3/Status.aspx.cs @ 6993

Last change on this file since 6993 was 6993, checked in by ascheibe, 12 years ago

#1672

  • removed unused files
  • changed the plugin cache path of the Slave HL App so that HL doesn't discover Hive assemblies
  • cleaned up config files
  • incremented version number of installers to 3.3.6
  • removed Execution time on Hive from Status page because it can't be calculated without the user statistics
File size: 5.7 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2011 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.Collections.Generic;
24using System.Linq;
25using System.Web;
26using System.Web.UI;
27using System.Web.UI.WebControls;
28using HeuristicLab.Services.Hive.DataAccess;
29using HeuristicLab.Services.Hive;
30using HeuristicLab.Services.Hive.DataTransfer;
31using System.Text;
32using System.Web.UI.DataVisualization.Charting;
33using DA = HeuristicLab.Services.Hive.DataAccess;
34
35public partial class Status : System.Web.UI.Page {
36  protected void Page_Load(object sender, EventArgs e) {
37    var dao = ServiceLocator.Instance.HiveDao;
38    var resourceName = Request.QueryString["resource"];
39    IEnumerable<Guid> resourceIds;
40    if (!string.IsNullOrEmpty(resourceName)) {
41      var resId = dao.GetResources(x => x.Name == resourceName).Single().Id;
42      resourceIds = dao.GetChildResources(resId).Select(x => x.Id).Union(new List<Guid> { resId });
43      speedupChartHours.Visible = false;
44      speedupChartMinutes.Visible = false;
45    } else {
46      resourceIds = dao.GetResources(x => true).Select(y => y.Id);
47      speedupChartHours.Visible = true;
48      speedupChartMinutes.Visible = true;
49    }
50                                 
51    var onlineSlaves = dao.GetSlaves(x => (x.SlaveState == DA.SlaveState.Calculating || x.SlaveState == DA.SlaveState.Idle) && resourceIds.Contains(x.ResourceId));
52
53    int currentlyAvailableCores = onlineSlaves.Where(s => s.Cores.HasValue).Sum(s => s.Cores.Value);
54    int currentlyUsedCores = currentlyAvailableCores - onlineSlaves.Where(s => s.FreeCores.HasValue).Sum(s => s.FreeCores.Value);
55    int currentlyJobsWaiting = ServiceLocator.Instance.HiveDao.GetTasks(x => x.State == DA.TaskState.Waiting).Count();
56
57    this.availableCoresLabel.Text = currentlyAvailableCores.ToString();
58    this.usedCoresLabel.Text = currentlyUsedCores.ToString();
59    this.waitingJobsLabel.Text = currentlyJobsWaiting.ToString();
60
61    slavesLabel.Text = string.Join(", ", onlineSlaves.Select(x => string.Format("<a href=\"?resource={0}\">{0}</a> ({1} %)", x.Name, Math.Round(x.CpuUtilization, 2))));
62
63    cpuUtilizationLabel.Text = (onlineSlaves.Count() > 0 ? Math.Round(onlineSlaves.Average(s => s.CpuUtilization), 2).ToString() : "0.0") + " %";
64
65    HeuristicLab.Services.Hive.DataTransfer.Statistics[] stats;
66    if (daysDropDownList.SelectedValue == "All") {
67      stats = dao.GetStatistics(x => true).OrderBy(x => x.TimeStamp).ToArray();
68    } else {
69      stats = dao.GetStatistics(x => x.Timestamp >= DateTime.Now.Subtract(TimeSpan.FromDays(int.Parse(daysDropDownList.SelectedValue)))).OrderBy(x => x.TimeStamp).ToArray();
70    }
71   
72    for (int i = 0; i < stats.Length; i++) {
73      var s = stats[i];
74      var slaveStats = s.SlaveStatistics.Where(x => resourceIds.Contains(x.SlaveId));
75
76      var averageCpuUtilization = slaveStats.Count() > 0 ? slaveStats.Average(x => x.CpuUtilization) : 0.0;
77      cpuUtilizationChart.Series[0].Points.Add(new DataPoint(s.TimeStamp.ToOADate(), averageCpuUtilization));
78
79      var cores = slaveStats.Sum(x => x.Cores);
80
81      var usedCores = cores - slaveStats.Sum(x => x.FreeCores);
82      coresChart.Series[0].Points.AddXY(s.TimeStamp.ToOADate(), cores);
83      coresChart.Series[1].Points.AddXY(s.TimeStamp.ToOADate(), usedCores);
84
85      var memory = slaveStats.Sum(x => x.Memory);
86      var usedMemory = memory - slaveStats.Sum(x => x.FreeMemory);
87      memoryChart.Series[0].Points.AddXY(s.TimeStamp.ToOADate(), memory / 1024.0);
88      memoryChart.Series[1].Points.AddXY(s.TimeStamp.ToOADate(), usedMemory / 1024.0);
89
90      if (i > 0) {
91        var execTime = new TimeSpan(s.UserStatistics.Sum(x => x.ExecutionTime.Ticks));
92        var execTimePrev = new TimeSpan(stats[i - 1].UserStatistics.Sum(x => x.ExecutionTime.Ticks));
93        var execTimeDifference = execTimePrev - execTime;
94
95        var timeDifference = stats[i - 1].TimeStamp - s.TimeStamp; // the difference between statistic entries is not alway exactly 1 minute
96        var speedup = execTimeDifference.TotalMinutes / timeDifference.TotalMinutes;
97        speedupChartMinutes.Series[0].Points.AddXY(s.TimeStamp.ToOADate(), speedup);
98        speedupChartMinutes.Series[1].Points.AddXY(s.TimeStamp.ToOADate(), cores);
99      }
100      if (i - 60 >= 0) {
101        var execTime = new TimeSpan(s.UserStatistics.Sum(x => x.ExecutionTime.Ticks));
102        var execTimePrev = new TimeSpan(stats[i - 60].UserStatistics.Sum(x => x.ExecutionTime.Ticks));
103        var execTimeDifference = execTimePrev - execTime;
104
105        var timeDifference = stats[i - 60].TimeStamp - s.TimeStamp; // the difference between statistic entries is not alway exactly 1 minute
106        var speedup = execTimeDifference.TotalMinutes / timeDifference.TotalMinutes;
107        speedupChartHours.Series[0].Points.AddXY(s.TimeStamp.ToOADate(), speedup);
108        speedupChartHours.Series[1].Points.AddXY(s.TimeStamp.ToOADate(), cores);
109      }
110    }
111  }
112
113  protected void daysDropDownList_SelectedIndexChanged(object sender, EventArgs e) {
114
115  }
116}
Note: See TracBrowser for help on using the repository browser.