Changeset 9646 for branches/HiveStatistics/sources/HeuristicLab.Services.Hive/3.3/HiveStatisticsGenerator.cs
- Timestamp:
- 06/19/13 15:29:37 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HiveStatistics/sources/HeuristicLab.Services.Hive/3.3/HiveStatisticsGenerator.cs
r9578 r9646 1 1 using System; 2 2 using System.Collections.Generic; 3 using System.Data.Linq; 3 4 using System.Linq; 4 5 using System.Transactions; … … 8 9 namespace HeuristicLab.Services.Hive { 9 10 public class HiveStatisticsGenerator : IStatisticsGenerator { 10 11 11 private IUserManager userManager { get { return ServiceLocator.Instance.UserManager; } } 12 12 … … 22 22 if (newTime != null) { 23 23 UpdateFactTables(newTime, db); 24 db.SubmitChanges(); 24 try { 25 db.SubmitChanges(); 26 } 27 catch (DuplicateKeyException) { 28 // Propable change from summertime to wintertime, resulting in overlapping times 29 // On wintertime to summertime change, slave timeouts and a fact gap will occur 30 } 25 31 } 26 32 … … 31 37 private DimTime UpdateDimensionTables(HiveDataContext db) { 32 38 var newTime = UpdateTime(db); 33 // Update other tables out of sync with time dimension? 39 34 40 UpdateUsers(db); 35 41 UpdateJobs(db); … … 155 161 156 162 private void UpdateClientInfoFacts(DimTime newTime, HiveDataContext db) { 163 var time = newTime.Time; 164 157 165 var lastFacts = 158 166 from cf in db.FactClientInfos … … 178 186 var clientFacts = 179 187 from s in slaves.ToList() 188 let duration = s.LastFact != null ? (time - s.LastFact.Time).TotalMinutes : SmallestTimeSpan.TotalMinutes 180 189 select new FactClientInfo { 181 190 DimClient = s.Client, 182 191 DimTime = newTime, 183 192 UserId = s.Slave.OwnerUserId ?? Guid.Empty, 184 NumUsedCores = 185 s.Slave.Cores != null && s.Slave.FreeCores != null 186 ? s.Slave.Cores.Value - s.Slave.FreeCores.Value 187 : 0, 193 NumUsedCores = s.Slave.Cores != null && s.Slave.FreeCores != null 194 ? s.Slave.Cores.Value - s.Slave.FreeCores.Value : 0, 188 195 NumTotalCores = s.Slave.Cores ?? 0, 189 UsedMemory = 190 s.Slave.Memory != null && s.Slave.FreeMemory != null 191 ? s.Slave.Memory.Value - s.Slave.FreeMemory.Value 192 : 0, 196 UsedMemory = s.Slave.Memory != null && s.Slave.FreeMemory != null 197 ? s.Slave.Memory.Value - s.Slave.FreeMemory.Value : 0, 193 198 TotalMemory = s.Slave.Memory ?? 0, 194 199 CpuUtilization = s.Slave.CpuUtilization, 195 200 TrafficIn = 0, 196 201 TrafficOut = 0, 197 TotalTimeIdle = CalcNewTotalTime(s.LastFact, newTime.Time, 198 x => x.TotalTimeIdle, 199 () => s.Slave.SlaveState == SlaveState.Idle && s.Slave.IsAllowedToCalculate), 200 TotalTimeCalculating = CalcNewTotalTime(s.LastFact, newTime.Time, 201 x => x.TotalTimeCalculating, 202 () => s.Slave.SlaveState == SlaveState.Calculating), 202 TotalTimeIdle = s.Slave.SlaveState == SlaveState.Idle && s.Slave.IsAllowedToCalculate 203 ? duration : 0.0, 204 TotalTimeCalculating = s.Slave.SlaveState == SlaveState.Calculating 205 ? duration : 0.0, 203 206 TotalTimeTransferring = 0.0, 204 TotalTimeUnavailable = CalcNewTotalTime(s.LastFact, newTime.Time, 205 x => x.TotalTimeUnavailable, 206 () => s.Slave.SlaveState == SlaveState.Idle && !s.Slave.IsAllowedToCalculate), 207 TotalTimeOffline = CalcNewTotalTime(s.LastFact, newTime.Time, 208 x => x.TotalTimeOffline, 209 () => s.Slave.SlaveState == SlaveState.Offline) 207 TotalTimeUnavailable = s.Slave.SlaveState == SlaveState.Idle && !s.Slave.IsAllowedToCalculate 208 ? duration : 0.0, 209 TotalTimeOffline = s.Slave.SlaveState == SlaveState.Offline 210 ? duration : 0.0 210 211 }; 211 212 212 213 db.FactClientInfos.InsertAllOnSubmit(clientFacts); 213 }214 215 private double CalcNewTotalTime(FactClientInfo lastFact, DateTime newTime, Func<FactClientInfo, double> selector, Func<bool> condition) {216 if (lastFact == null) {217 return 0.0;218 }219 return condition()220 ? selector(lastFact) + (newTime - lastFact.Time).TotalMinutes221 : selector(lastFact);222 214 } 223 215 … … 262 254 TaskSize = t.LastFact == null ? t.TaskDataSize : t.LastFact.TaskSize, 263 255 ResultSize = t.Task.State == TaskState.Finished ? t.TaskDataSize : default(long?), 264 NumCalculationRuns = stateLogsLinkedList.EnumerateNodes() 265 .Count(sl => sl.Value.State == TaskState.Calculating && sl.NextIs(nsl => nsl.State == TaskState.Transferring)), 266 NumRetries = stateLogsLinkedList.EnumerateNodes() 267 .Count(sl => sl.Value.State == TaskState.Calculating && sl.Next != null && sl.NextIs(nsl => nsl.State != TaskState.Transferring)), 268 TotalWaitingTime = SumTotalTime(stateLogsLinkedList, stateLog => stateLog.Value.State == TaskState.Waiting), 269 TotalRuntime = SumTotalTime(stateLogsLinkedList, stateLog => stateLog.Value.State == TaskState.Calculating && stateLog.NextIs(x => x.State == TaskState.Transferring)), 270 TotalTransferTime = SumTotalTime(stateLogsLinkedList, stateLog => stateLog.Value.State == TaskState.Transferring), 256 NumCalculationRuns = stateLogsLinkedList.CountCalculationRuns(), 257 NumRetries = stateLogsLinkedList.CountRetries(), 258 TotalWaitingTime = stateLogsLinkedList.SumTotalTimeWhere(stateLog => stateLog.Value.State == TaskState.Waiting), 259 TotalRuntime = stateLogsLinkedList.SumTotalTimeWhere(stateLog => stateLog.Value.State == TaskState.Calculating && stateLog.NextIs(x => x.State == TaskState.Transferring)), 260 TotalTransferTime = stateLogsLinkedList.SumTotalTimeWhere(stateLog => stateLog.Value.State == TaskState.Transferring), 271 261 TaskState = t.Task.State 272 262 }; … … 275 265 db.FactTasks.InsertAllOnSubmit(newTaskFacts); 276 266 } 277 278 private double SumTotalTime(LinkedList<StateLog> stateLogs, Predicate<LinkedListNode<StateLog>> predicate) { 267 } 268 269 public static class StateLogLinkedListExtensions { 270 public static int CountCalculationRuns(this LinkedList<StateLog> stateLogs) { 279 271 return stateLogs.EnumerateNodes() 280 .Where(sl => predicate(sl)) 281 .Sum(stateLog => stateLog.Next != null ? (stateLog.Next.Value.DateTime - stateLog.Value.DateTime).TotalMinutes : 0); 272 .Count(sl => sl.Value.State == TaskState.Calculating && sl.NextIs(nsl => nsl.State == TaskState.Transferring)); 273 } 274 275 public static int CountRetries(this LinkedList<StateLog> stateLogs) { 276 return stateLogs.EnumerateNodes() 277 .Count(sl => sl.Value.State == TaskState.Calculating && sl.Next != null && sl.NextIs(nsl => nsl.State != TaskState.Transferring)); 278 } 279 280 public static double SumTotalTimeWhere(this LinkedList<StateLog> stateLogs, Predicate<LinkedListNode<StateLog>> predicate) { 281 return stateLogs.EnumerateNodes() 282 .Where(stateLog => predicate(stateLog)) 283 .Sum(stateLog => stateLog.Next != null ? (stateLog.Next.Value.DateTime - stateLog.Value.DateTime).TotalMinutes : 0.0); 282 284 } 283 285 } 284 286 285 public static class LinkedList NodeExtensions {287 public static class LinkedListExtensions { 286 288 public static IEnumerable<LinkedListNode<T>> EnumerateNodes<T>(this LinkedList<T> list) { 287 289 var node = list.First;
Note: See TracChangeset
for help on using the changeset viewer.