Changeset 12146
- Timestamp:
- 03/05/15 17:09:10 (10 years ago)
- Location:
- trunk/sources
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Services.Hive.Web/Hive-3.3/Status.aspx.cs
r12012 r12146 23 23 using System.Collections.Generic; 24 24 using System.Linq; 25 using System.Web;26 using System.Web.UI;27 25 using System.Web.UI.WebControls; 28 using HeuristicLab.Services.Hive.DataAccess;29 26 using HeuristicLab.Services.Hive; 30 using HeuristicLab.Services.Hive.DataTransfer;31 using System.Text;32 27 using System.Web.UI.DataVisualization.Charting; 33 28 using DA = HeuristicLab.Services.Hive.DataAccess; … … 37 32 protected void Page_Load(object sender, EventArgs e) { 38 33 var dao = ServiceLocator.Instance.HiveDao; 34 var optDao = ServiceLocator.Instance.OptimizedHiveDao; 39 35 var transactionManager = ServiceLocator.Instance.TransactionManager; 40 36 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>(); 43 39 int currentlyJobsWaiting = 0; 44 Dictionary<Guid, int> calculatingTasksByUser = new Dictionary<Guid, int>();40 Dictionary<Guid, int> calculatingTasksByUser = new Dictionary<Guid, int>(); 45 41 Dictionary<Guid, int> waitingTasksByUser = new Dictionary<Guid, int>(); 46 42 List<DT.Resource> groups = new List<DT.Resource>(); 47 43 48 44 transactionManager.UseTransaction(() => { 49 50 }, false, false); 45 groups = dao.GetResources(x => x.ResourceType == "GROUP").ToList(); 46 }, false, false); 51 47 52 48 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); 60 55 } 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 } 68 62 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(); 73 70 }, false, false); 74 71 … … 76 73 int currentlyAvailableCores = onlineSlaves.Where(s => s.Cores.HasValue && s.IsAllowedToCalculate).Sum(s => s.Cores.Value); 77 74 int currentlyUsedCores = overallCurrentlyAvailableCores - onlineSlaves.Where(s => s.FreeCores.HasValue).Sum(s => s.FreeCores.Value); 78 75 79 76 this.overallAvailableCoresLabel.Text = overallCurrentlyAvailableCores.ToString(); 80 77 this.availableCoresLabel.Text = currentlyAvailableCores.ToString(); … … 86 83 groupsLabel.Text += string.Join(", ", groups.Select(x => string.Format("<a href=\"?resource={0}\">{0}</a>", x.Name))); 87 84 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") + " %"; 90 87 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 } 99 95 }, false, false); 100 96 101 97 for (int i = 0; i < stats.Length; i++) { 102 98 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(); 104 100 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; 106 102 cpuUtilizationChart.Series[0].Points.Add(new DataPoint(s.TimeStamp.ToOADate(), averageCpuUtilization)); 107 103 … … 118 114 } 119 115 120 GenerateTasksByUserTable(waitingTasksByUser, waitingTasksByUserTable); 121 GenerateTasksByUserTable(calculatingTasksByUser, calculatingTasksByUserTable); 116 GenerateTasksByUserTable(waitingTasksByUser, waitingTasksByUserTable); 117 GenerateTasksByUserTable(calculatingTasksByUser, calculatingTasksByUserTable); 122 118 } 123 119 … … 134 130 table.Rows.Add(curRow); 135 131 } 136 if (tasksByUser. Count() > 0) {137 TableRow sumRow = new TableRow(); 132 if (tasksByUser.Any()) { 133 TableRow sumRow = new TableRow(); 138 134 TableCell sumCell = new TableCell(); 139 135 sumCell.BorderWidth = Unit.Pixel(3); … … 143 139 table.Rows.Add(sumRow); 144 140 } 145 } 141 } 146 142 } -
trunk/sources/HeuristicLab.Services.Hive/3.3/HiveDao.cs
r12012 r12146 869 869 } 870 870 871 public Dictionary<Guid, int> GetWaitingTasksByUser() {872 using (var db = CreateContext()) {873 var waitingTasksByUser = from task in db.Tasks874 where task.State == TaskState.Waiting875 group task by task.Job.OwnerUserId into g876 select new { UserId = g.Key, UsedCores = g.Count() };877 return waitingTasksByUser.ToDictionary(x => x.UserId, x => x.UsedCores);878 }879 }880 881 871 public Dictionary<Guid, int> GetWaitingTasksByUserForResources(List<Guid> resourceIds) { 882 872 using (var db = CreateContext()) { … … 886 876 select new { UserId = g.Key, UsedCores = g.Count() }; 887 877 return waitingTasksByUser.ToDictionary(x => x.UserId, x => x.UsedCores); 888 }889 }890 891 public Dictionary<Guid, int> GetCalculatingTasksByUser() {892 using (var db = CreateContext()) {893 var calculatingTasksByUser = from task in db.Tasks894 where task.State == TaskState.Calculating895 group task by task.Job.OwnerUserId into g896 select new { UserId = g.Key, UsedCores = g.Count() };897 return calculatingTasksByUser.ToDictionary(x => x.UserId, x => x.UsedCores);898 878 } 899 879 } -
trunk/sources/HeuristicLab.Services.Hive/3.3/Interfaces/IHiveDao.cs
r12012 r12146 150 150 151 151 #region Statistics Methods 152 Dictionary<Guid, int> GetWaitingTasksByUser();153 152 Dictionary<Guid, int> GetWaitingTasksByUserForResources(List<Guid> resourceIds); 154 Dictionary<Guid, int> GetCalculatingTasksByUser();155 153 Dictionary<Guid, int> GetCalculatingTasksByUserForResources(List<Guid> resourceIds); 156 154 DT.Statistics GetStatistic(Guid id); -
trunk/sources/HeuristicLab.Services.Hive/3.3/Interfaces/IOptimizedHiveDao.cs
r12012 r12146 65 65 IEnumerable<Guid> GetAssignedResourceIds(Guid jobId); 66 66 #endregion 67 68 #region Website Methods 69 70 IEnumerable<Guid> GetAllResourceIds(); 71 72 int GetNumberOfWaitingTasks(); 73 74 Dictionary<Guid, int> GetCalculatingTasksByUser(); 75 76 Dictionary<Guid, int> GetWaitingTasksByUser(); 77 78 #endregion 67 79 } 68 80 } -
trunk/sources/HeuristicLab.Services.Hive/3.3/OptimizedHiveDao.cs
r12012 r12146 245 245 ); 246 246 #endregion 247 248 249 #region Website Methods 250 private const string GetAllResourceIdsString = @"SELECT ResourceId FROM [Resource]"; 251 public IEnumerable<Guid> GetAllResourceIds() { 252 return Db.ExecuteQuery<Guid>(GetAllResourceIdsString); 253 } 254 255 private const string GetNumberOfWaitingTasksString = @"SELECT COUNT(TaskId) 256 FROM [Task] 257 WHERE TaskState LIKE 'Waiting'"; 258 public int GetNumberOfWaitingTasks() { 259 return Db.ExecuteQuery<int>(GetNumberOfWaitingTasksString).Single(); 260 } 261 262 private class UserTasks { 263 public Guid OwnerUserId; 264 public int Count; 265 } 266 267 private const string GetCalculatingTasksByUserString = @"SELECT Job.OwnerUserId, COUNT(Task.TaskId) as Count 268 FROM Task, Job 269 WHERE TaskState LIKE 'Calculating' AND Task.JobId = Job.JobId 270 GROUP BY Job.OwnerUserId"; 271 272 public Dictionary<Guid, int> GetCalculatingTasksByUser() { 273 var result = Db.ExecuteQuery<UserTasks>(GetCalculatingTasksByUserString); 274 Dictionary<Guid, int> lst = new Dictionary<Guid, int>(); 275 276 foreach (var userTask in result) { 277 lst.Add(userTask.OwnerUserId, userTask.Count); 278 } 279 return lst; 280 } 281 282 private const string GetWaitingTasksByUserString = @"SELECT Job.OwnerUserId, COUNT(Task.TaskId) as Count 283 FROM Task, Job 284 WHERE TaskState LIKE 'Waiting' AND Task.JobId = Job.JobId 285 GROUP BY Job.OwnerUserId"; 286 287 public Dictionary<Guid, int> GetWaitingTasksByUser() { 288 var result = Db.ExecuteQuery<UserTasks>(GetWaitingTasksByUserString); 289 Dictionary<Guid, int> lst = new Dictionary<Guid, int>(); 290 291 foreach (var userTask in result) { 292 lst.Add(userTask.OwnerUserId, userTask.Count); 293 } 294 return lst; 295 } 296 #endregion 247 297 } 248 298 }
Note: See TracChangeset
for help on using the changeset viewer.