- Timestamp:
- 01/07/13 22:00:04 (12 years ago)
- Location:
- trunk/sources
- Files:
-
- 2 added
- 19 edited
- 3 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Services.Hive
-
Property
svn:mergeinfo
set to
/branches/HiveTaskScheduler/HeuristicLab.Services.Hive merged eligible
-
Property
svn:mergeinfo
set to
-
trunk/sources/HeuristicLab.Services.Hive.DataAccess
-
Property
svn:mergeinfo
set to
/branches/HiveTaskScheduler/HeuristicLab.Services.Hive.DataAccess merged eligible
-
Property
svn:mergeinfo
set to
-
trunk/sources/HeuristicLab.Services.Hive.DataAccess/3.3/HiveDataContext.dbml
r8957 r9123 42 42 <Association Name="Resource_Downtime" Member="Downtimes" Storage="_UptimeCalendars" ThisKey="ResourceId" OtherKey="ResourceId" Type="Downtime" /> 43 43 <Association Name="Resource_StateLog" Member="StateLogs" ThisKey="ResourceId" OtherKey="SlaveId" Type="StateLog" /> 44 <Association Name="Resource_ SlavePermission" Member="ResourcePermissions" ThisKey="ResourceId" OtherKey="ResourceId" Type="ResourcePermission" />44 <Association Name="Resource_ResourcePermission" Member="ResourcePermissions" ThisKey="ResourceId" OtherKey="ResourceId" Type="ResourcePermission" /> 45 45 <Association Name="Resource_Resource" Member="ParentResource" ThisKey="ParentResourceId" OtherKey="ResourceId" Type="Resource" IsForeignKey="true" /> 46 46 <Type Name="Slave" InheritanceCode="Slave" IsInheritanceDefault="true"> … … 201 201 <Column Name="GrantedUserId" Type="System.Guid" DbType="UniqueIdentifier NOT NULL" IsPrimaryKey="true" CanBeNull="false" /> 202 202 <Column Name="GrantedByUserId" Type="System.Guid" DbType="UniqueIdentifier NOT NULL" CanBeNull="false" /> 203 <Association Name="Resource_SlavePermission" Member="Resource" ThisKey="ResourceId" OtherKey="ResourceId" Type="Resource" IsForeignKey="true" /> 203 <Association Name="Resource_ResourcePermission" Member="Resource" ThisKey="ResourceId" OtherKey="ResourceId" Type="Resource" IsForeignKey="true" /> 204 </Type> 205 </Table> 206 <Table Name="" Member="UserPriorities"> 207 <Type Name="UserPriority"> 208 <Column Name="UserId" Type="System.Guid" DbType="UniqueIdentifier NOT NULL" IsPrimaryKey="true" CanBeNull="false" /> 209 <Column Name="DateEnqueued" Type="System.DateTime" DbType="DateTime NOT NULL" CanBeNull="false" /> 204 210 </Type> 205 211 </Table> -
trunk/sources/HeuristicLab.Services.Hive.DataAccess/3.3/HiveDataContext.dbml.layout
r7916 r9123 33 33 </nestedChildShapes> 34 34 </classShape> 35 <classShape Id="8d5712f7-7a1a-4a89-bd4d-fd60200d3306" absoluteBounds="13.5, 2.5, 2, 2. 1554996744791666">35 <classShape Id="8d5712f7-7a1a-4a89-bd4d-fd60200d3306" absoluteBounds="13.5, 2.5, 2, 2.3478011067708326"> 36 36 <DataClassMoniker Name="/HiveDataContext/Downtime" /> 37 37 <nestedChildShapes> 38 <elementListCompartment Id="7d8f121b-35bb-4753-a25f-3fac1562e68e" absoluteBounds="13.515, 2.9600000000000009, 1.9700000000000002, 1. 5954996744791665" name="DataPropertiesCompartment" titleTextColor="Black" itemTextColor="Black" />38 <elementListCompartment Id="7d8f121b-35bb-4753-a25f-3fac1562e68e" absoluteBounds="13.515, 2.9600000000000009, 1.9700000000000002, 1.7878011067708333" name="DataPropertiesCompartment" titleTextColor="Black" itemTextColor="Black" /> 39 39 </nestedChildShapes> 40 40 </classShape> … … 57 57 </nestedChildShapes> 58 58 </classShape> 59 <inheritanceConnector edgePoints="[(11.25 : 1.98159912109375); (10.875 : 1.98159912109375)]" fixedFrom=" Algorithm" fixedTo="Algorithm" TargetRelationshipDomainClassId="7a7fe09e-e9ef-4b01-9ff3-bde95e827b62">59 <inheritanceConnector edgePoints="[(11.25 : 1.98159912109375); (10.875 : 1.98159912109375)]" fixedFrom="NotFixed" fixedTo="NotFixed" TargetRelationshipDomainClassId="7a7fe09e-e9ef-4b01-9ff3-bde95e827b62"> 60 60 <nodes> 61 61 <classShapeMoniker Id="706a4581-6daf-4e71-ae2a-87d50b27a051" /> … … 63 63 </nodes> 64 64 </inheritanceConnector> 65 <inheritanceConnector edgePoints="[(13.25 : 1.40469482421875); (13.5 : 1.40469482421875)]" fixedFrom=" Algorithm" fixedTo="Algorithm" TargetRelationshipDomainClassId="7a7fe09e-e9ef-4b01-9ff3-bde95e827b62">65 <inheritanceConnector edgePoints="[(13.25 : 1.40469482421875); (13.5 : 1.40469482421875)]" fixedFrom="NotFixed" fixedTo="NotFixed" TargetRelationshipDomainClassId="7a7fe09e-e9ef-4b01-9ff3-bde95e827b62"> 66 66 <nodes> 67 67 <classShapeMoniker Id="706a4581-6daf-4e71-ae2a-87d50b27a051" /> … … 121 121 </nestedChildShapes> 122 122 </classShape> 123 <associationConnector edgePoints="[(11.25 : 1. 45954756054688); (10.9375 : 1.45954756054688); (10.9375 : 0.6875); (2.75 : 0.6875); (2.75 : 1)]" fixedFrom="Algorithm" fixedTo="Algorithm">123 <associationConnector edgePoints="[(11.25 : 1.98159912109375); (10.9375 : 1.98159912109375); (10.9375 : 0.6875); (2.75 : 0.6875); (2.75 : 1)]" fixedFrom="NotFixed" fixedTo="NotFixed"> 124 124 <AssociationMoniker Name="/HiveDataContext/Resource/Resource_StateLog" /> 125 125 <nodes> … … 172 172 </nodes> 173 173 </associationConnector> 174 <associationConnector edgePoints="[(13.25 : 2.73159912109375); (13.5 : 2.73159912109375)]" fixedFrom=" Algorithm" fixedTo="Algorithm">174 <associationConnector edgePoints="[(13.25 : 2.73159912109375); (13.5 : 2.73159912109375)]" fixedFrom="NotFixed" fixedTo="NotFixed"> 175 175 <AssociationMoniker Name="/HiveDataContext/Resource/Resource_Downtime" /> 176 176 <nodes> … … 234 234 </nestedChildShapes> 235 235 </classShape> 236 <associationConnector edgePoints="[(12.5942481820367 : 2.9631982421875); (12.5942481820367 : 3.875)]" fixedFrom=" Algorithm" fixedTo="Algorithm">237 <AssociationMoniker Name="/HiveDataContext/Resource/Resource_ SlavePermission" />236 <associationConnector edgePoints="[(12.5942481820367 : 2.9631982421875); (12.5942481820367 : 3.875)]" fixedFrom="NotFixed" fixedTo="NotFixed"> 237 <AssociationMoniker Name="/HiveDataContext/Resource/Resource_ResourcePermission" /> 238 238 <nodes> 239 239 <classShapeMoniker Id="706a4581-6daf-4e71-ae2a-87d50b27a051" /> … … 241 241 </nodes> 242 242 </associationConnector> 243 <classShape Id="f9e8867f-fd15-4a72-8ca4-4f02cd3f141f" absoluteBounds="4.125, 5.5, 2, 1.1939925130208327"> 244 <DataClassMoniker Name="/HiveDataContext/UserPriority" /> 245 <nestedChildShapes> 246 <elementListCompartment Id="ee41f516-7d9c-4a1d-a1b8-bbe00a6ffea8" absoluteBounds="4.14, 5.96, 1.9700000000000002, 0.63399251302083326" name="DataPropertiesCompartment" titleTextColor="Black" itemTextColor="Black" /> 247 </nestedChildShapes> 248 </classShape> 243 249 </nestedChildShapes> 244 250 </ordesignerObjectsDiagram> -
trunk/sources/HeuristicLab.Services.Hive.DataAccess/3.3/HiveDataContext.designer.cs
r8957 r9123 82 82 partial void UpdateResourcePermission(ResourcePermission instance); 83 83 partial void DeleteResourcePermission(ResourcePermission instance); 84 partial void InsertUserPriority(UserPriority instance); 85 partial void UpdateUserPriority(UserPriority instance); 86 partial void DeleteUserPriority(UserPriority instance); 84 87 #endregion 85 88 … … 247 250 { 248 251 return this.GetTable<ResourcePermission>(); 252 } 253 } 254 255 public System.Data.Linq.Table<UserPriority> UserPriorities 256 { 257 get 258 { 259 return this.GetTable<UserPriority>(); 249 260 } 250 261 } … … 1087 1098 } 1088 1099 1089 [global::System.Data.Linq.Mapping.AssociationAttribute(Name="Resource_ SlavePermission", Storage="_ResourcePermissions", ThisKey="ResourceId", OtherKey="ResourceId")]1100 [global::System.Data.Linq.Mapping.AssociationAttribute(Name="Resource_ResourcePermission", Storage="_ResourcePermissions", ThisKey="ResourceId", OtherKey="ResourceId")] 1090 1101 public EntitySet<ResourcePermission> ResourcePermissions 1091 1102 { … … 4383 4394 } 4384 4395 4385 [global::System.Data.Linq.Mapping.AssociationAttribute(Name="Resource_ SlavePermission", Storage="_Resource", ThisKey="ResourceId", OtherKey="ResourceId", IsForeignKey=true)]4396 [global::System.Data.Linq.Mapping.AssociationAttribute(Name="Resource_ResourcePermission", Storage="_Resource", ThisKey="ResourceId", OtherKey="ResourceId", IsForeignKey=true)] 4386 4397 public Resource Resource 4387 4398 { … … 4437 4448 } 4438 4449 } 4450 4451 [global::System.Data.Linq.Mapping.TableAttribute(Name="")] 4452 public partial class UserPriority : INotifyPropertyChanging, INotifyPropertyChanged 4453 { 4454 4455 private static PropertyChangingEventArgs emptyChangingEventArgs = new PropertyChangingEventArgs(String.Empty); 4456 4457 private System.Guid _UserId; 4458 4459 private System.DateTime _DateEnqueued; 4460 4461 #region Extensibility Method Definitions 4462 partial void OnLoaded(); 4463 partial void OnValidate(System.Data.Linq.ChangeAction action); 4464 partial void OnCreated(); 4465 partial void OnUserIdChanging(System.Guid value); 4466 partial void OnUserIdChanged(); 4467 partial void OnDateEnqueuedChanging(System.DateTime value); 4468 partial void OnDateEnqueuedChanged(); 4469 #endregion 4470 4471 public UserPriority() 4472 { 4473 OnCreated(); 4474 } 4475 4476 [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_UserId", DbType="UniqueIdentifier NOT NULL", IsPrimaryKey=true)] 4477 public System.Guid UserId 4478 { 4479 get 4480 { 4481 return this._UserId; 4482 } 4483 set 4484 { 4485 if ((this._UserId != value)) 4486 { 4487 this.OnUserIdChanging(value); 4488 this.SendPropertyChanging(); 4489 this._UserId = value; 4490 this.SendPropertyChanged("UserId"); 4491 this.OnUserIdChanged(); 4492 } 4493 } 4494 } 4495 4496 [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_DateEnqueued", DbType="DateTime NOT NULL")] 4497 public System.DateTime DateEnqueued 4498 { 4499 get 4500 { 4501 return this._DateEnqueued; 4502 } 4503 set 4504 { 4505 if ((this._DateEnqueued != value)) 4506 { 4507 this.OnDateEnqueuedChanging(value); 4508 this.SendPropertyChanging(); 4509 this._DateEnqueued = value; 4510 this.SendPropertyChanged("DateEnqueued"); 4511 this.OnDateEnqueuedChanged(); 4512 } 4513 } 4514 } 4515 4516 public event PropertyChangingEventHandler PropertyChanging; 4517 4518 public event PropertyChangedEventHandler PropertyChanged; 4519 4520 protected virtual void SendPropertyChanging() 4521 { 4522 if ((this.PropertyChanging != null)) 4523 { 4524 this.PropertyChanging(this, emptyChangingEventArgs); 4525 } 4526 } 4527 4528 protected virtual void SendPropertyChanged(String propertyName) 4529 { 4530 if ((this.PropertyChanged != null)) 4531 { 4532 this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); 4533 } 4534 } 4535 } 4439 4536 } 4440 4537 #pragma warning restore 1591 -
trunk/sources/HeuristicLab.Services.Hive.DataAccess/3.3/SQL Scripts/Initialize Hive Database.sql
r8957 r9123 122 122 CONSTRAINT [PK_Lifecycle] PRIMARY KEY ([LifecycleId]) 123 123 ) 124 CREATE TABLE [UserPriority]( 125 [UserId] UniqueIdentifier NOT NULL, 126 [DateEnqueued] DateTime NOT NULL, 127 CONSTRAINT [PK_UserPriority] PRIMARY KEY ([UserId]) 128 ) 124 129 CREATE TABLE [DeletedJobStatistics]( 125 130 [UserId] UniqueIdentifier NOT NULL, -
trunk/sources/HeuristicLab.Services.Hive/3.3/Convert.cs
r8957 r9123 527 527 } 528 528 #endregion 529 530 #region UserPriority 531 public static DT.UserPriority ToDto(DB.UserPriority source) { 532 if (source == null) return null; 533 return new DT.UserPriority() { Id = source.UserId, DateEnqueued = source.DateEnqueued }; 534 } 535 public static DB.UserPriority ToEntity(DT.UserPriority source) { 536 if (source == null) return null; 537 var entity = new DB.UserPriority(); ToEntity(source, entity); 538 return entity; 539 } 540 public static void ToEntity(DT.UserPriority source, DB.UserPriority target) { 541 if ((source != null) && (target != null)) { 542 target.UserId = source.Id; 543 target.DateEnqueued = source.DateEnqueued; 544 } 545 } 546 #endregion 529 547 } 530 548 } -
trunk/sources/HeuristicLab.Services.Hive/3.3/HeuristicLab.Services.Hive-3.3.csproj
r8600 r9123 114 114 <Compile Include="Convert.cs" /> 115 115 <Compile Include="DataTransfer\Command.cs" /> 116 <Compile Include="DataTransfer\UserPriority.cs" /> 116 117 <Compile Include="DataTransfer\ResourcePermission.cs" /> 117 118 <Compile Include="DataTransfer\Downtime.cs" /> … … 139 140 <Compile Include="HiveJanitor.cs" /> 140 141 <Compile Include="Interfaces\IHiveDao.cs" /> 142 <Compile Include="Interfaces\ITaskScheduler.cs" /> 143 <Compile Include="Scheduler\TaskInfoForScheduler.cs" /> 144 <Compile Include="Scheduler\JobInfoForScheduler.cs" /> 145 <Compile Include="Scheduler\RoundRobinTaskScheduler.cs" /> 141 146 <Compile Include="Settings.cs" /> 142 147 <None Include="app.config" /> … … 196 201 </PropertyGroup> 197 202 <PropertyGroup> 198 <PreBuildEvent Condition=" '$(OS)' == 'Windows_NT' ">set Path=%25Path%25;$(ProjectDir);$(SolutionDir)203 <PreBuildEvent Condition=" '$(OS)' == 'Windows_NT' ">set Path=%25Path%25;$(ProjectDir);$(SolutionDir) 199 204 set ProjectDir=$(ProjectDir) 200 205 set SolutionDir=$(SolutionDir) … … 202 207 203 208 call PreBuildEvent.cmd</PreBuildEvent> 204 <PreBuildEvent Condition=" '$(OS)' != 'Windows_NT' ">209 <PreBuildEvent Condition=" '$(OS)' != 'Windows_NT' "> 205 210 export ProjectDir=$(ProjectDir) 206 211 export SolutionDir=$(SolutionDir) -
trunk/sources/HeuristicLab.Services.Hive/3.3/HiveDao.cs
r9035 r9123 84 84 } 85 85 86 public void UpdateTask (DT.Task dto) {86 public void UpdateTaskAndPlugins(DT.Task dto) { 87 87 using (var db = CreateContext()) { 88 88 var entity = db.Tasks.FirstOrDefault(x => x.TaskId == dto.Id); … … 94 94 } 95 95 } 96 db.SubmitChanges(); 97 } 98 } 99 100 public void UpdateTask(DT.Task dto) { 101 using (var db = CreateContext()) { 102 var entity = db.Tasks.FirstOrDefault(x => x.TaskId == dto.Id); 103 if (entity == null) db.Tasks.InsertOnSubmit(DT.Convert.ToEntity(dto)); 104 else DT.Convert.ToEntity(dto, entity); 96 105 db.SubmitChanges(); 97 106 } … … 134 143 } 135 144 136 public IEnumerable< DT.Task> GetWaitingTasks(DT.Slave slave, int count) {145 public IEnumerable<TaskInfoForScheduler> GetWaitingTasks(DT.Slave slave) { 137 146 using (var db = CreateContext()) { 138 147 var resourceIds = GetParentResources(slave.Id).Select(r => r.Id); … … 147 156 && ar.Task.CoresNeeded <= slave.FreeCores 148 157 && ar.Task.MemoryNeeded <= slave.FreeMemory 149 orderby ar.Task.Priority descending, db.Random() // take random task to avoid the race condition that occurs when this method is called concurrently (the same task would be returned) 150 select DT.Convert.ToDto(ar.Task); 151 var waitingTasks = (count == 0 ? query : query.Take(count)).ToArray(); 158 select new TaskInfoForScheduler() { TaskId = ar.Task.TaskId, JobId = ar.Task.JobId, Priority = ar.Task.Priority }; 159 var waitingTasks = query.ToArray(); 152 160 return waitingTasks; 153 161 } … … 277 285 } 278 286 287 public IEnumerable<JobInfoForScheduler> GetJobInfoForScheduler(Expression<Func<Job, bool>> predicate) { 288 using (var db = CreateContext()) { 289 return db.Jobs.Where(predicate).Select(x => new JobInfoForScheduler() { Id = x.JobId, DateCreated = x.DateCreated, OwnerUserId = x.OwnerUserId }).ToArray(); 290 } 291 } 292 279 293 public Guid AddJob(DT.Job dto) { 280 294 using (var db = CreateContext()) { 281 295 var entity = DT.Convert.ToEntity(dto); 282 296 db.Jobs.InsertOnSubmit(entity); 297 if (!db.UserPriorities.Any(x => x.UserId == dto.OwnerUserId)) 298 EnqueueUserPriority(new DT.UserPriority { Id = dto.OwnerUserId, DateEnqueued = dto.DateCreated }); 283 299 db.SubmitChanges(); 284 300 return entity.JobId; … … 923 939 #endregion 924 940 941 #region UserPriority Methods 942 public IEnumerable<DT.UserPriority> GetUserPriorities(Expression<Func<UserPriority, bool>> predicate) { 943 using (var db = CreateContext()) { 944 return db.UserPriorities.Where(predicate).Select(x => DT.Convert.ToDto(x)).ToArray(); 945 } 946 } 947 948 public void EnqueueUserPriority(DT.UserPriority dto) { 949 using (var db = CreateContext()) { 950 var entity = db.UserPriorities.FirstOrDefault(x => x.UserId == dto.Id); 951 if (entity == null) db.UserPriorities.InsertOnSubmit(DT.Convert.ToEntity(dto)); 952 else DT.Convert.ToEntity(dto, entity); 953 db.SubmitChanges(); 954 } 955 } 956 #endregion 957 925 958 #region Helpers 926 959 private void CollectChildTasks(HiveDataContext db, Guid parentTaskId, List<Task> collection) { -
trunk/sources/HeuristicLab.Services.Hive/3.3/HiveService.cs
r9035 r9123 142 142 author.AuthorizeForTask(taskDto.Id, Permission.Full); 143 143 trans.UseTransaction(() => { 144 dao.UpdateTask (taskDto);144 dao.UpdateTaskAndPlugins(taskDto); 145 145 }); 146 146 } … … 152 152 //trans.UseTransaction(() => { // cneumuel: try without transaction 153 153 taskData.LastUpdate = DateTime.Now; 154 dao.UpdateTask (task);154 dao.UpdateTaskAndPlugins(task); 155 155 dao.UpdateTaskData(taskData); 156 156 //}, false, true); … … 194 194 } 195 195 196 dao.UpdateTask (task);196 dao.UpdateTaskAndPlugins(task); 197 197 return task; 198 198 }); … … 499 499 #endregion 500 500 501 #region Resource Methods 502 public IEnumerable<Resource> GetChildResources(Guid resourceId) { 503 return dao.GetChildResources(resourceId); 504 } 505 #endregion 506 501 507 #region Slave Methods 502 508 public int GetNewHeartbeatInterval(Guid slaveId) { … … 671 677 #endregion 672 678 679 #region UserPriority Methods 680 public IEnumerable<UserPriority> GetUserPriorities() { 681 return trans.UseTransaction(() => dao.GetUserPriorities(x => true)); 682 } 683 #endregion 684 673 685 #region Helper Methods 674 686 private IEnumerable<Task> GetChildTasks(Guid? parentTaskId, bool recursive, bool includeParent) { … … 687 699 } 688 700 #endregion 701 702 #region Statistics Methods 703 public IEnumerable<Statistics> GetStatistics() { 704 return dao.GetStatistics(x => true); 705 } 706 public IEnumerable<Statistics> GetStatisticsForTimePeriod(DateTime from, DateTime to) { 707 return dao.GetStatistics(x => x.Timestamp >= from && x.Timestamp <= to); 708 } 709 #endregion 689 710 } 690 711 } -
trunk/sources/HeuristicLab.Services.Hive/3.3/Interfaces/IHiveDao.cs
r9035 r9123 33 33 IEnumerable<DT.LightweightTask> GetLightweightTasks(Expression<Func<Task, bool>> predicate); 34 34 Guid AddTask(DT.Task dto); 35 void UpdateTaskAndPlugins(DT.Task dto); 35 36 void UpdateTask(DT.Task dto); 36 37 void DeleteTask(Guid id); 37 IEnumerable< DT.Task> GetWaitingTasks(DT.Slave slave, int count);38 IEnumerable<TaskInfoForScheduler> GetWaitingTasks(DT.Slave slave); 38 39 IEnumerable<DT.Task> GetParentTasks(IEnumerable<Guid> resourceIds, int count, bool finished); 39 40 DT.Task UpdateTaskState(Guid taskId, TaskState taskState, Guid? slaveId, Guid? userId, string exception); … … 59 60 DT.Job GetJob(Guid id); 60 61 IEnumerable<DT.Job> GetJobs(Expression<Func<Job, bool>> predicate); 62 IEnumerable<JobInfoForScheduler> GetJobInfoForScheduler(Expression<Func<Job, bool>> predicate); 61 63 Guid AddJob(DT.Job dto); 62 64 void UpdateJob(DT.Job dto); … … 156 158 List<DT.UserStatistics> GetUserStatistics(); 157 159 #endregion 160 161 #region UserPriority Methods 162 IEnumerable<DT.UserPriority> GetUserPriorities(Expression<Func<UserPriority, bool>> predicate); 163 void EnqueueUserPriority(DT.UserPriority userPriority); 164 #endregion 158 165 } 159 166 } -
trunk/sources/HeuristicLab.Services.Hive/3.3/Interfaces/IServiceLocator.cs
r8051 r9123 31 31 Access.IUserManager UserManager { get; } 32 32 HeartbeatManager HeartbeatManager { get; } 33 ITaskScheduler TaskScheduler { get; } 33 34 } 34 35 } -
trunk/sources/HeuristicLab.Services.Hive/3.3/Interfaces/ITaskScheduler.cs
r9106 r9123 25 25 namespace HeuristicLab.Services.Hive { 26 26 public interface ITaskScheduler { 27 IEnumerable<Task > Schedule(IEnumerable<Task> tasks, int count = 1);27 IEnumerable<TaskInfoForScheduler> Schedule(IEnumerable<TaskInfoForScheduler> tasks, int count = 1); 28 28 } 29 29 } -
trunk/sources/HeuristicLab.Services.Hive/3.3/Manager/HeartbeatManager.cs
r8957 r9123 23 23 using System.Collections.Generic; 24 24 using System.Linq; 25 using System.Threading; 25 26 using HeuristicLab.Services.Hive.DataTransfer; 26 27 using DA = HeuristicLab.Services.Hive.DataAccess; … … 28 29 namespace HeuristicLab.Services.Hive { 29 30 public class HeartbeatManager { 31 private const string MutexName = "HiveTaskSchedulingMutex"; 32 30 33 private IHiveDao dao { 31 34 get { return ServiceLocator.Instance.HiveDao; } 32 35 } 33 private I AuthorizationManager auth{34 get { return ServiceLocator.Instance. AuthorizationManager; }36 private ITaskScheduler taskScheduler { 37 get { return ServiceLocator.Instance.TaskScheduler; } 35 38 } 36 39 … … 66 69 // assign new task 67 70 if (heartbeat.AssignJob && slave.IsAllowedToCalculate && heartbeat.FreeCores > 0) { 68 var availableJobs = dao.GetWaitingTasks(slave, 1); 69 if (availableJobs.Count() > 0) { 70 var job = availableJobs.First(); 71 if (AssignJob(slave, job)) 72 actions.Add(new MessageContainer(MessageContainer.MessageType.CalculateTask, job.Id)); 71 bool mutexAquired = false; 72 var mutex = new Mutex(false, MutexName); 73 try { 74 mutexAquired = mutex.WaitOne(Properties.Settings.Default.SchedulingPatience); 75 if (!mutexAquired) 76 DA.LogFactory.GetLogger(this.GetType().Namespace).Log("HeartbeatManager: The mutex used for scheduling could not be aquired."); 77 else { 78 var availableTasks = taskScheduler.Schedule(dao.GetWaitingTasks(slave)); 79 if (availableTasks.Any()) { 80 var task = availableTasks.First(); 81 AssignJob(slave, task.TaskId); 82 actions.Add(new MessageContainer(MessageContainer.MessageType.CalculateTask, task.TaskId)); 83 } 84 } 85 } 86 catch (AbandonedMutexException) { 87 DA.LogFactory.GetLogger(this.GetType().Namespace).Log("HeartbeatManager: The mutex used for scheduling has been abandoned."); 88 } 89 catch (Exception ex) { 90 DA.LogFactory.GetLogger(this.GetType().Namespace).Log("HeartbeatManager threw an exception in ProcessHeartbeat: " + ex.ToString()); 91 } 92 finally { 93 if (mutexAquired) mutex.ReleaseMutex(); 73 94 } 74 95 } … … 77 98 } 78 99 79 // returns true if assignment was successful 80 private bool AssignJob(Slave slave, Task task) { 81 // load task again and check if it is still available (this is an attempt to reduce the race condition which causes multiple heartbeats to get the same task assigned) 82 if (dao.GetTask(task.Id).State != TaskState.Waiting) return false; 83 84 task = dao.UpdateTaskState(task.Id, DataAccess.TaskState.Transferring, slave.Id, null, null); 100 private void AssignJob(Slave slave, Guid taskId) { 101 var task = dao.UpdateTaskState(taskId, DataAccess.TaskState.Transferring, slave.Id, null, null); 85 102 86 103 // from now on the task has some time to send the next heartbeat (ApplicationConstants.TransferringJobHeartbeatTimeout) 87 104 task.LastHeartbeat = DateTime.Now; 88 105 dao.UpdateTask(task); 89 return true;90 106 } 91 107 -
trunk/sources/HeuristicLab.Services.Hive/3.3/Properties/Settings.Designer.cs
r7857 r9123 2 2 // <auto-generated> 3 3 // This code was generated by a tool. 4 // Runtime Version:4.0.30319. 2694 // Runtime Version:4.0.30319.17929 5 5 // 6 6 // Changes to this file may cause incorrect behavior and will be lost if … … 13 13 14 14 [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 15 [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "1 0.0.0.0")]15 [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] 16 16 public sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { 17 17 … … 77 77 } 78 78 } 79 80 [global::System.Configuration.ApplicationScopedSettingAttribute()] 81 [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 82 [global::System.Configuration.DefaultSettingValueAttribute("00:00:20")] 83 public global::System.TimeSpan SchedulingPatience { 84 get { 85 return ((global::System.TimeSpan)(this["SchedulingPatience"])); 86 } 87 } 79 88 } 80 89 } -
trunk/sources/HeuristicLab.Services.Hive/3.3/Properties/Settings.settings
r7857 r9123 21 21 <Value Profile="(Default)">3.00:00:00</Value> 22 22 </Setting> 23 <Setting Name="SchedulingPatience" Type="System.TimeSpan" Scope="Application"> 24 <Value Profile="(Default)">00:00:20</Value> 25 </Setting> 23 26 </Settings> 24 27 </SettingsFile> -
trunk/sources/HeuristicLab.Services.Hive/3.3/Scheduler/RoundRobinTaskScheduler.cs
r8998 r9123 31 31 } 32 32 33 public IEnumerable<Task > Schedule(IEnumerable<Task> tasks, int count = 1) {34 if (!tasks.Any()) return Enumerable.Empty<Task >();33 public IEnumerable<TaskInfoForScheduler> Schedule(IEnumerable<TaskInfoForScheduler> tasks, int count = 1) { 34 if (!tasks.Any()) return Enumerable.Empty<TaskInfoForScheduler>(); 35 35 36 36 var userPriorities = dao.GetUserPriorities(x => true).OrderBy(x => x.DateEnqueued).ToArray(); 37 37 38 var jobs = new List<Job >();38 var jobs = new List<JobInfoForScheduler>(); 39 39 foreach (var userPriority in userPriorities) { 40 jobs.AddRange(dao.GetJob s(x => x.OwnerUserId == userPriority.Id));40 jobs.AddRange(dao.GetJobInfoForScheduler(x => x.OwnerUserId == userPriority.Id)); 41 41 } 42 42 … … 44 44 task => task.JobId, 45 45 job => job.Id, 46 (task, job) => new { Task = task, Job = job })46 (task, job) => new { Task = task, JobInfo = job }) 47 47 .OrderByDescending(x => x.Task.Priority) 48 48 .ToList(); 49 49 50 var scheduledTasks = new List<Task >();50 var scheduledTasks = new List<TaskInfoForScheduler>(); 51 51 int priorityIndex = 0; 52 52 … … 55 55 for (int i = 0; i < count; i++) { 56 56 var defaultEntry = taskJobRelations.First(); // search first task which is not included yet 57 var priorityEntries = taskJobRelations.Where(x => x.Job.OwnerUserId == userPriorities[priorityIndex].Id).ToArray(); // search for tasks with desired user priority 58 while (!priorityEntries.Any() && ++priorityIndex < userPriorities.Length) 59 priorityEntries = taskJobRelations.Where(x => x.Job.OwnerUserId == userPriorities[priorityIndex].Id).ToArray(); 57 var priorityEntries = taskJobRelations.Where(x => x.JobInfo.OwnerUserId == userPriorities[priorityIndex].Id).ToArray(); // search for tasks with desired user priority 58 while (!priorityEntries.Any() && priorityIndex < userPriorities.Length - 1) { 59 priorityIndex++; 60 priorityEntries = taskJobRelations.Where(x => x.JobInfo.OwnerUserId == userPriorities[priorityIndex].Id).ToArray(); 61 } 60 62 if (priorityEntries.Any()) { // tasks with desired user priority found 61 var priorityEntry = priorityEntries.OrderByDescending(x => x.Task.Priority).ThenBy(x => x.Job .DateCreated).First();63 var priorityEntry = priorityEntries.OrderByDescending(x => x.Task.Priority).ThenBy(x => x.JobInfo.DateCreated).First(); 62 64 if (defaultEntry.Task.Priority <= priorityEntry.Task.Priority) { 63 65 taskJobRelations.Remove(priorityEntry); 64 66 scheduledTasks.Add(priorityEntry.Task); 67 UpdateUserPriority(userPriorities[priorityIndex]); 65 68 priorityIndex++; 66 69 } else { // there are other tasks with higher priorities … … 72 75 scheduledTasks.Add(defaultEntry.Task); 73 76 } 77 78 if (priorityIndex >= (userPriorities.Length - 1)) priorityIndex = 0; 74 79 } 75 76 // requeue user priorities77 if (priorityIndex < userPriorities.Length)78 for (int i = 0; i < priorityIndex; i++) {79 userPriorities[i].DateEnqueued = DateTime.Now;80 dao.EnqueueUserPriority(userPriorities[i]);81 }82 80 83 81 return scheduledTasks; 84 82 } 83 84 private void UpdateUserPriority(UserPriority up) { 85 up.DateEnqueued = DateTime.Now; 86 dao.EnqueueUserPriority(up); 87 } 85 88 } 86 89 } -
trunk/sources/HeuristicLab.Services.Hive/3.3/ServiceContracts/IHiveService.cs
r8071 r9123 168 168 #endregion 169 169 170 #region Resource Methods 171 [OperationContract] 172 IEnumerable<Resource> GetChildResources(Guid resourceId); 173 #endregion 174 170 175 #region Slave Methods 171 176 [OperationContract] … … 238 243 [OperationContract] 239 244 Guid GetUserIdByUsername(string username); 245 #endregion 246 247 #region UserPriorities Methods 248 [OperationContract] 249 IEnumerable<UserPriority> GetUserPriorities(); 250 #endregion 251 252 #region Statistics Methods 253 [OperationContract] 254 IEnumerable<Statistics> GetStatistics(); 255 [OperationContract] 256 IEnumerable<Statistics> GetStatisticsForTimePeriod(DateTime from, DateTime to); 240 257 #endregion 241 258 } -
trunk/sources/HeuristicLab.Services.Hive/3.3/ServiceLocator.cs
r8051 r9123 89 89 } 90 90 } 91 92 private ITaskScheduler taskScheduler; 93 public ITaskScheduler TaskScheduler { 94 get { 95 if (taskScheduler == null) taskScheduler = new RoundRobinTaskScheduler(); 96 return taskScheduler; 97 } 98 } 91 99 } 92 100 } -
trunk/sources/HeuristicLab.Services.Hive/3.3/app.config
r7857 r9123 26 26 <value>3.00:00:00</value> 27 27 </setting> 28 <setting name="SchedulingPatience" serializeAs="String"> 29 <value>00:00:20</value> 30 </setting> 28 31 </HeuristicLab.Services.Hive.Properties.Settings> 29 32 </applicationSettings>
Note: See TracChangeset
for help on using the changeset viewer.