Changeset 9541
- Timestamp:
- 05/27/13 17:03:43 (11 years ago)
- Location:
- branches/HiveStatistics/sources
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HiveStatistics/sources/HeuristicLab.Services.Hive.DataAccess/3.3/HiveDataContext.dbml
r9538 r9541 277 277 <Column Name="ClientId" Type="System.Guid" DbType="UniqueIdentifier NOT NULL" IsPrimaryKey="true" CanBeNull="false" /> 278 278 <Column Name="Time" Type="System.DateTime" DbType="DateTime NOT NULL" IsPrimaryKey="true" CanBeNull="false" /> 279 <Column Name="UserId" Type="System.Guid" DbType="UniqueIdentifier N OT NULL" IsPrimaryKey="true" CanBeNull="false" />279 <Column Name="UserId" Type="System.Guid" DbType="UniqueIdentifier NULL" CanBeNull="true" /> 280 280 <Column Name="NumUsedCores" Type="System.Int32" DbType="Int NOT NULL" CanBeNull="false" /> 281 281 <Column Name="NumTotalCores" Type="System.Int32" DbType="Int NOT NULL" CanBeNull="false" /> -
branches/HiveStatistics/sources/HeuristicLab.Services.Hive.DataAccess/3.3/HiveDataContext.dbml.layout
r9538 r9541 121 121 </nestedChildShapes> 122 122 </classShape> 123 <associationConnector edgePoints="[(11.25 : 1. 87677124023437); (10.9375 : 1.87677124023437); (10.9375 : 0.6875); (2.75 : 0.6875); (2.75 : 1)]" fixedFrom="NotFixed" fixedTo="NotFixed">123 <associationConnector edgePoints="[(11.25 : 1.44547136382195); (11.0260416666667 : 1.44547136382195); (11.0260416666667 : 0.5625); (2.75 : 0.5625); (2.75 : 1)]" manuallyRouted="true" fixedFrom="Caller" fixedTo="Algorithm"> 124 124 <AssociationMoniker Name="/HiveDataContext/Resource/Resource_StateLog" /> 125 125 <nodes> … … 179 179 </nodes> 180 180 </associationConnector> 181 <associationConnector edgePoints="[( 7.96163946463664 : 4.30930826822917); (7.96163946463664 : 5.09699625651042); (8.875 : 5.09699625651042)]" fixedFrom="NotFixed" fixedTo="NotFixed">181 <associationConnector edgePoints="[(8.0192961430407 : 3.90397379557292); (8.0192961430407 : 5.04807657877604); (8.875 : 5.04807657877604)]" fixedFrom="Caller" fixedTo="Algorithm"> 182 182 <AssociationMoniker Name="/HiveDataContext/Task/Task_AssignedResource" /> 183 183 <nodes> … … 186 186 </nodes> 187 187 </associationConnector> 188 <associationConnector edgePoints="[(7. 16831973231832 : 4.30930826822917); (7.16831973231832 : 5.875)]" fixedFrom="NotFixed" fixedTo="NotFixed">188 <associationConnector edgePoints="[(7.20145120722822 : 3.90397379557292); (7.20145120722822 : 5.875)]" fixedFrom="Caller" fixedTo="Algorithm"> 189 189 <AssociationMoniker Name="/HiveDataContext/Task/Task_RequiredPlugin" /> 190 190 <nodes> … … 193 193 </nodes> 194 194 </associationConnector> 195 <associationConnector edgePoints="[(7.20923076923077 : 1); (7.20923076923077 : 0. 875); (7.80461538461539 : 0.875); (7.80461538461539 : 1)]" fixedFrom="NotFixed" fixedTo="NotFixed">195 <associationConnector edgePoints="[(7.20923076923077 : 1); (7.20923076923077 : 0.770833333333333); (7.80461538461539 : 0.770833333333333); (7.80461538461539 : 1)]" manuallyRouted="true" fixedFrom="Algorithm" fixedTo="Algorithm"> 196 196 <AssociationMoniker Name="/HiveDataContext/Task/Task_Task" /> 197 197 <nodes> … … 297 297 </nodes> 298 298 </associationConnector> 299 <associationConnector edgePoints="[(5.15625 : 10.0891951497396); (5.15625 : 14.3889184570313); (6.875 : 14.3889184570313)]" fixedFrom=" Algorithm" fixedTo="Algorithm">299 <associationConnector edgePoints="[(5.15625 : 10.0891951497396); (5.15625 : 14.3889184570313); (6.875 : 14.3889184570313)]" fixedFrom="NotFixed" fixedTo="NotFixed"> 300 300 <AssociationMoniker Name="/HiveDataContext/DimTime/DimTime_FactTask" /> 301 301 <nodes> … … 304 304 </nodes> 305 305 </associationConnector> 306 <associationConnector edgePoints="[(5.4218775 : 10.0891951497396); (5.4218775 : 13.3576659570313); (6.71675495975 : 13.3576659570313); (6.71675495975 : 13.359301744963); (6.875 : 13.359301744963)]" manuallyRouted="true" fixedFrom=" Algorithm" fixedTo="Caller">306 <associationConnector edgePoints="[(5.4218775 : 10.0891951497396); (5.4218775 : 13.3576659570313); (6.71675495975 : 13.3576659570313); (6.71675495975 : 13.359301744963); (6.875 : 13.359301744963)]" manuallyRouted="true" fixedFrom="NotFixed" fixedTo="NotFixed"> 307 307 <AssociationMoniker Name="/HiveDataContext/DimTime/DimTime_FactTask1" /> 308 308 <nodes> … … 318 318 </nodes> 319 319 </associationConnector> 320 <associationConnector edgePoints="[(4.125 : 10.0891951497396); (4.125 : 11)]" fixedFrom=" Algorithm" fixedTo="Algorithm">320 <associationConnector edgePoints="[(4.125 : 10.0891951497396); (4.125 : 11)]" fixedFrom="NotFixed" fixedTo="NotFixed"> 321 321 <AssociationMoniker Name="/HiveDataContext/DimTime/DimTime_FactClientInfo" /> 322 322 <nodes> -
branches/HiveStatistics/sources/HeuristicLab.Services.Hive.DataAccess/3.3/HiveDataContext.designer.cs
r9538 r9541 5929 5929 private System.DateTime _Time; 5930 5930 5931 private System. Guid_UserId;5931 private System.Nullable<System.Guid> _UserId; 5932 5932 5933 5933 private int _NumUsedCores; … … 5969 5969 partial void OnTimeChanging(System.DateTime value); 5970 5970 partial void OnTimeChanged(); 5971 partial void OnUserIdChanging(System. Guidvalue);5971 partial void OnUserIdChanging(System.Nullable<System.Guid> value); 5972 5972 partial void OnUserIdChanged(); 5973 5973 partial void OnNumUsedCoresChanging(int value); … … 6053 6053 } 6054 6054 6055 [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_UserId", DbType="UniqueIdentifier N OT NULL", IsPrimaryKey=true)]6056 public System. GuidUserId6055 [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_UserId", DbType="UniqueIdentifier NULL")] 6056 public System.Nullable<System.Guid> UserId 6057 6057 { 6058 6058 get … … 6412 6412 else 6413 6413 { 6414 this._UserId = default( System.Guid);6414 this._UserId = default(Nullable<System.Guid>); 6415 6415 } 6416 6416 this.SendPropertyChanged("DimUser"); -
branches/HiveStatistics/sources/HeuristicLab.Services.Hive.DataAccess/3.3/SQL Scripts/Initialize Hive Database.sql
r9538 r9541 233 233 [ClientId] UNIQUEIDENTIFIER NOT NULL, 234 234 [Time] DATETIME NOT NULL, 235 [UserId] UNIQUEIDENTIFIER N OT NULL,235 [UserId] UNIQUEIDENTIFIER NULL, 236 236 [NumUsedCores] INT NOT NULL, 237 237 [NumTotalCores] INT NOT NULL, … … 246 246 [TotalTimeOffline] FLOAT (53) NOT NULL, 247 247 [TotalTimeUnavailable] FLOAT (53) NOT NULL, 248 CONSTRAINT [PK_FactClientInfo] PRIMARY KEY CLUSTERED ([ClientId] ASC, [Time] ASC , [UserId] ASC),248 CONSTRAINT [PK_FactClientInfo] PRIMARY KEY CLUSTERED ([ClientId] ASC, [Time] ASC), 249 249 CONSTRAINT [FK_FactClientInfo_DimTime] FOREIGN KEY ([Time]) REFERENCES [statistics].[DimTime] ([Time]), 250 250 CONSTRAINT [FK_FactClientInfo_DimClient] FOREIGN KEY ([ClientId]) REFERENCES [statistics].[DimClient] ([Id]), -
branches/HiveStatistics/sources/HeuristicLab.Services.Hive/3.3/HiveStatisticsGenerator.cs
r9538 r9541 6 6 namespace HeuristicLab.Services.Hive { 7 7 public class HiveStatisticsGenerator : IStatisticsGenerator { 8 private static readonly TimeSpan Smalles TimeSpan = new TimeSpan(0, 5, 0);8 private static readonly TimeSpan SmallestTimeSpan = new TimeSpan(0, 5, 0); 9 9 10 10 public void GenerateStatistics() { 11 11 using (var db = new HiveDataContext(Settings.Default.HeuristicLab_Hive_LinqConnectionString)) 12 12 using (var transaction = new TransactionScope()) { 13 14 13 var newTime = UpdateDimensionTables(db); 14 db.SubmitChanges(); 15 15 16 if (newTime != null) { 16 UpdateDataTables(newTime, db); 17 UpdateFactTables(newTime, db); 18 db.SubmitChanges(); 17 19 } 18 20 19 db.SubmitChanges();20 21 transaction.Complete(); 21 22 } … … 41 42 var now = DateTime.Now; 42 43 DimTime newTime = null; 43 if (lastUpdate == default(DateTime) || lastUpdate + Smalles TimeSpan < now) {44 if (lastUpdate == default(DateTime) || lastUpdate + SmallestTimeSpan < now) { 44 45 newTime = new DimTime { 45 Time = new DateTime(now.Year, now.Month, now.Day, now.Hour, now.Minute - now.Minute % Smalles TimeSpan.Minutes, 0),46 Time = new DateTime(now.Year, now.Month, now.Day, now.Hour, now.Minute - now.Minute % SmallestTimeSpan.Minutes, 0), 46 47 Hour = new DateTime(now.Year, now.Month, now.Day, now.Hour, 0, 0), 47 48 Day = new DateTime(now.Year, now.Month, now.Day, 0, 0, 0), … … 131 132 } 132 133 133 private void UpdateDataTables(DimTime newTime, HiveDataContext db) { 134 134 private void UpdateFactTables(DimTime newTime, HiveDataContext db) { 135 UpdateClientInfoFacts(newTime, db); 136 //UpdateTaskFacts(newTime, db); 137 } 138 139 private void UpdateClientInfoFacts(DimTime newTime, HiveDataContext db) { 140 var lastFacts = 141 from cf in db.FactClientInfos 142 group cf by cf.ClientId 143 into grpFacts 144 select grpFacts.OrderByDescending(x => x.Time).First(); 145 146 var slaves = 147 from s in db.Resources.OfType<Slave>() 148 join c in db.DimClients on s.ResourceId equals c.ResourceId 149 join lcf in lastFacts on c.Id equals lcf.ClientId into joinCf 150 from cf in joinCf.DefaultIfEmpty() 151 select new { 152 Slave = s, 153 Client = c, 154 LastFact = cf 155 }; 156 157 var clientFacts = 158 from s in slaves.ToList() 159 select new FactClientInfo { 160 DimClient = s.Client, 161 DimTime = newTime, 162 UserId = s.Slave.OwnerUserId, 163 NumUsedCores = 164 s.Slave.Cores != null && s.Slave.FreeCores != null 165 ? s.Slave.Cores.Value - s.Slave.FreeCores.Value 166 : 0, 167 NumTotalCores = s.Slave.Cores ?? 0, 168 UsedMemory = 169 s.Slave.Memory != null && s.Slave.FreeMemory != null 170 ? s.Slave.Memory.Value - s.Slave.FreeMemory.Value 171 : 0, 172 TotalMemory = s.Slave.Memory ?? 0, 173 CpuUtilization = s.Slave.CpuUtilization, 174 TrafficIn = 0, 175 TrafficOut = 0, 176 TotalTimeIdle = CalcNewTotalTime(s.LastFact, newTime.Time, 177 x => x.TotalTimeIdle, 178 () => s.Slave.SlaveState == SlaveState.Idle && s.Slave.IsAllowedToCalculate), 179 TotalTimeCalculating = CalcNewTotalTime(s.LastFact, newTime.Time, 180 x => x.TotalTimeCalculating, 181 () => s.Slave.SlaveState == SlaveState.Calculating), 182 TotalTimeTransferring = 0.0, 183 TotalTimeUnavailable = CalcNewTotalTime(s.LastFact, newTime.Time, 184 x => x.TotalTimeUnavailable, 185 () => s.Slave.SlaveState == SlaveState.Idle && !s.Slave.IsAllowedToCalculate), 186 TotalTimeOffline = CalcNewTotalTime(s.LastFact, newTime.Time, 187 x => x.TotalTimeOffline, 188 () => s.Slave.SlaveState == SlaveState.Offline) 189 }; 190 191 db.FactClientInfos.InsertAllOnSubmit(clientFacts); 192 } 193 194 private double CalcNewTotalTime(FactClientInfo lastFact, DateTime newTime, Func<FactClientInfo, double> selector, Func<bool> condition) { 195 if (lastFact == null) { 196 return 0.0; 197 } 198 return condition() 199 ? selector(lastFact) + (newTime - lastFact.Time).TotalMinutes 200 : selector(lastFact); 135 201 } 136 202 }
Note: See TracChangeset
for help on using the changeset viewer.