Changeset 8707 for branches/HiveTaskScheduler
- Timestamp:
- 09/28/12 10:49:02 (12 years ago)
- Location:
- branches/HiveTaskScheduler
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HiveTaskScheduler/HeuristicLab.Services.Hive.DataAccess/3.3/HiveDataContext.dbml
r8687 r8707 206 206 <Type Name="UserPriority"> 207 207 <Column Name="UserId" Type="System.Guid" DbType="UniqueIdentifier NOT NULL" IsPrimaryKey="true" CanBeNull="false" /> 208 <Column Name="DateEnqueued" Type="System.DateTime" DbType="DateTime" CanBeNull="false" /> 208 209 </Type> 209 210 </Table> -
branches/HiveTaskScheduler/HeuristicLab.Services.Hive.DataAccess/3.3/HiveDataContext.dbml.layout
r8687 r8707 241 241 </nodes> 242 242 </associationConnector> 243 <classShape Id="f9e8867f-fd15-4a72-8ca4-4f02cd3f141f" absoluteBounds="4.125, 5.5, 2, 1. 0016910807291666">243 <classShape Id="f9e8867f-fd15-4a72-8ca4-4f02cd3f141f" absoluteBounds="4.125, 5.5, 2, 1.1939925130208327"> 244 244 <DataClassMoniker Name="/HiveDataContext/UserPriority" /> 245 245 <nestedChildShapes> 246 <elementListCompartment Id="ee41f516-7d9c-4a1d-a1b8-bbe00a6ffea8" absoluteBounds="4.14, 5.96, 1.9700000000000002, 0. 44169108072916663" name="DataPropertiesCompartment" titleTextColor="Black" itemTextColor="Black" />246 <elementListCompartment Id="ee41f516-7d9c-4a1d-a1b8-bbe00a6ffea8" absoluteBounds="4.14, 5.96, 1.9700000000000002, 0.63399251302083326" name="DataPropertiesCompartment" titleTextColor="Black" itemTextColor="Black" /> 247 247 </nestedChildShapes> 248 248 </classShape> -
branches/HiveTaskScheduler/HeuristicLab.Services.Hive.DataAccess/3.3/HiveDataContext.designer.cs
r8687 r8707 3 3 // <auto-generated> 4 4 // This code was generated by a tool. 5 // Runtime Version:4.0.30319. 2695 // Runtime Version:4.0.30319.17929 6 6 // 7 7 // Changes to this file may cause incorrect behavior and will be lost if … … 4433 4433 private System.Guid _UserId; 4434 4434 4435 private System.DateTime _DateEnqueued; 4436 4435 4437 #region Extensibility Method Definitions 4436 4438 partial void OnLoaded(); … … 4439 4441 partial void OnUserIdChanging(System.Guid value); 4440 4442 partial void OnUserIdChanged(); 4443 partial void OnDateEnqueuedChanging(System.DateTime value); 4444 partial void OnDateEnqueuedChanged(); 4441 4445 #endregion 4442 4446 … … 4466 4470 } 4467 4471 4472 [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_DateEnqueued", DbType="DateTime")] 4473 public System.DateTime DateEnqueued 4474 { 4475 get 4476 { 4477 return this._DateEnqueued; 4478 } 4479 set 4480 { 4481 if ((this._DateEnqueued != value)) 4482 { 4483 this.OnDateEnqueuedChanging(value); 4484 this.SendPropertyChanging(); 4485 this._DateEnqueued = value; 4486 this.SendPropertyChanged("DateEnqueued"); 4487 this.OnDateEnqueuedChanged(); 4488 } 4489 } 4490 } 4491 4468 4492 public event PropertyChangingEventHandler PropertyChanging; 4469 4493 -
branches/HiveTaskScheduler/HeuristicLab.Services.Hive.DataAccess/3.3/SQL Scripts/Initialize Hive Database.sql
r8687 r8707 123 123 CREATE TABLE [UserPriority]( 124 124 [UserId] UniqueIdentifier NOT NULL, 125 [DateEnqueued] DateTime NOT NULL, 125 126 CONSTRAINT [PK_UserPriority] PRIMARY KEY ([UserId]) 126 127 ) -
branches/HiveTaskScheduler/HeuristicLab.Services.Hive/3.3/Convert.cs
r8687 r8707 531 531 public static DT.UserPriority ToDto(DB.UserPriority source) { 532 532 if (source == null) return null; 533 return new DT.UserPriority() { UserId = source.UserId };533 return new DT.UserPriority() { Id = source.UserId, DateEnqueued = source.DateEnqueued }; 534 534 } 535 535 public static DB.UserPriority ToEntity(DT.UserPriority source) { … … 540 540 public static void ToEntity(DT.UserPriority source, DB.UserPriority target) { 541 541 if ((source != null) && (target != null)) { 542 target.UserId = source.UserId; 542 target.UserId = source.Id; 543 target.DateEnqueued = source.DateEnqueued; 543 544 } 544 545 } -
branches/HiveTaskScheduler/HeuristicLab.Services.Hive/3.3/DataTransfer/UserPriority.cs
r8687 r8707 28 28 public class UserPriority : HiveItem { 29 29 [DataMember] 30 public Guid UserId { get; set; }30 public DateTime DateEnqueued { get; set; } 31 31 } 32 32 } -
branches/HiveTaskScheduler/HeuristicLab.Services.Hive/3.3/HiveDao.cs
r8687 r8707 259 259 var entity = DT.Convert.ToEntity(dto); 260 260 db.Jobs.InsertOnSubmit(entity); 261 if (!db.Jobs.Any(x => x.OwnerUserId == dto.OwnerUserId)) 262 EnqueueUserPriority(new DT.UserPriority { Id = dto.OwnerUserId, DateEnqueued = dto.DateCreated }); 261 263 db.SubmitChanges(); 262 264 return entity.JobId; … … 863 865 } 864 866 } 867 868 public void EnqueueUserPriority(DT.UserPriority dto) { 869 using (var db = CreateContext()) { 870 var entity = db.UserPriorities.FirstOrDefault(x => x.UserId == dto.Id); 871 if (entity == null) db.UserPriorities.InsertOnSubmit(DT.Convert.ToEntity(dto)); 872 else DT.Convert.ToEntity(dto, entity); 873 db.SubmitChanges(); 874 } 875 } 865 876 #endregion 866 877 -
branches/HiveTaskScheduler/HeuristicLab.Services.Hive/3.3/Interfaces/IHiveDao.cs
r8687 r8707 154 154 #region UserPriority Methods 155 155 IEnumerable<DT.UserPriority> GetUserPriorities(Expression<Func<UserPriority, bool>> predicate); 156 void EnqueueUserPriority(DT.UserPriority userPriority); 156 157 #endregion 157 158 } -
branches/HiveTaskScheduler/HeuristicLab.Services.Hive/3.3/Manager/HeartbeatManager.cs
r8687 r8707 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; } … … 63 66 // assign new task 64 67 if (heartbeat.AssignJob && slave.IsAllowedToCalculate && heartbeat.FreeCores > 0) { 65 var availableJobs = taskScheduler.Schedule(dao.GetWaitingTasks(slave)); 66 if (availableJobs.Any()) { 67 var job = availableJobs.First(); 68 if (AssignJob(slave, job)) 69 actions.Add(new MessageContainer(MessageContainer.MessageType.CalculateTask, job.Id)); 68 bool mutexAquired = false; 69 var mutex = new Mutex(false, MutexName); 70 try { 71 mutexAquired = mutex.WaitOne(Properties.Settings.Default.SchedulingPatience); 72 if (!mutexAquired) 73 DA.LogFactory.GetLogger(this.GetType().Namespace).Log("HeartbeatManager: The mutex used for scheduling could not be aquired."); 74 else { 75 var availableJobs = taskScheduler.Schedule(dao.GetWaitingTasks(slave)); 76 if (availableJobs.Any()) { 77 var job = availableJobs.First(); 78 if (AssignJob(slave, job)) 79 actions.Add(new MessageContainer(MessageContainer.MessageType.CalculateTask, job.Id)); 80 } 81 } 82 } 83 catch (AbandonedMutexException) { 84 DA.LogFactory.GetLogger(this.GetType().Namespace).Log("HeartbeatManager: The mutex used for scheduling has been abandoned."); 85 } 86 finally { 87 if (mutexAquired) mutex.ReleaseMutex(); 70 88 } 71 89 } -
branches/HiveTaskScheduler/HeuristicLab.Services.Hive/3.3/Properties/Settings.Designer.cs
r7857 r8707 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 … … 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 } -
branches/HiveTaskScheduler/HeuristicLab.Services.Hive/3.3/Properties/Settings.settings
r7857 r8707 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> -
branches/HiveTaskScheduler/HeuristicLab.Services.Hive/3.3/Scheduler/RoundRobinTaskScheduler.cs
r8687 r8707 20 20 #endregion 21 21 22 using System; 22 23 using System.Collections.Generic; 23 24 using System.Linq; … … 31 32 32 33 public IEnumerable<Task> Schedule(IEnumerable<Task> tasks, int count = 1) { 33 var userPriorities = dao.GetUserPriorities(x => true).ToArray(); 34 if (!tasks.Any()) return Enumerable.Empty<Task>(); 35 36 var userPriorities = dao.GetUserPriorities(x => true).OrderBy(x => x.DateEnqueued).ToArray(); 34 37 35 38 var jobs = new List<Job>(); 36 39 foreach (var userPriority in userPriorities) { 37 40 var closureUserPriority = userPriority; 38 jobs.AddRange(dao.GetJobs(x => x.OwnerUserId == closureUserPriority. UserId));41 jobs.AddRange(dao.GetJobs(x => x.OwnerUserId == closureUserPriority.Id)); 39 42 } 40 43 … … 43 46 job => job.Id, 44 47 (task, job) => new { Task = task, Job = job }) 45 .ToDictionary(k => k, v => false); 48 .OrderByDescending(x => x.Task.Priority) 49 .ToList(); 46 50 47 51 var scheduledTasks = new List<Task>(); 48 52 int priorityIndex = 0; 53 49 54 if (count == 0 || count > taskJobRelations.Count) count = taskJobRelations.Count; 55 50 56 for (int i = 0; i < count; i++) { 51 var defaultEntry = taskJobRelations.First( x => !x.Value); // search first task which is not included yet52 var priorityEntries = taskJobRelations.Where(x => !x.Value && x.Key.Job.OwnerUserId == userPriorities[priorityIndex].UserId).ToArray(); // search for tasks with desired user priority53 while (!priorityEntries.Any() && priorityIndex < priorityEntries.Length)54 priorityEntries = taskJobRelations.Where(x => !x.Value && x.Key.Job.OwnerUserId == userPriorities[++priorityIndex].UserId).ToArray();57 var defaultEntry = taskJobRelations.First(); // search first task which is not included yet 58 var priorityEntries = taskJobRelations.Where(x => x.Job.OwnerUserId == userPriorities[priorityIndex].Id).ToArray(); // search for tasks with desired user priority 59 while (!priorityEntries.Any() && ++priorityIndex < userPriorities.Length) 60 priorityEntries = taskJobRelations.Where(x => x.Job.OwnerUserId == userPriorities[priorityIndex].Id).ToArray(); 55 61 if (priorityEntries.Any()) { // tasks with desired user priority found 56 var priorityEntry = priorityEntries.OrderByDescending(x => x. Key.Task.Priority).ThenBy(x => x.Key.Task.DateCreated).First();57 if (defaultEntry. Key.Task.Priority <= priorityEntry.Key.Task.Priority) {58 taskJobRelations [priorityEntry.Key] = true;59 scheduledTasks.Add(priorityEntry. Key.Task);62 var priorityEntry = priorityEntries.OrderByDescending(x => x.Task.Priority).ThenBy(x => x.Job.DateCreated).First(); 63 if (defaultEntry.Task.Priority <= priorityEntry.Task.Priority) { 64 taskJobRelations.Remove(priorityEntry); 65 scheduledTasks.Add(priorityEntry.Task); 60 66 priorityIndex++; 61 } else { // there are other tasks with higher priorit y62 taskJobRelations [defaultEntry.Key] = true;63 scheduledTasks.Add(defaultEntry. Key.Task);67 } else { // there are other tasks with higher priorities 68 taskJobRelations.Remove(defaultEntry); 69 scheduledTasks.Add(defaultEntry.Task); 64 70 } 65 71 } else { 66 taskJobRelations [defaultEntry.Key] = true;67 scheduledTasks.Add(defaultEntry. Key.Task);72 taskJobRelations.Remove(defaultEntry); 73 scheduledTasks.Add(defaultEntry.Task); 68 74 } 69 75 } 70 76 71 // dequeue and enqueue priorities [0, priorityIndex), i.e. {4,3,6,2,5,1} and priorityIndex = 3 -> {2,5,1,4,3,6} 72 // i don't know how to solve this yet ... (race conditions, locking?) 77 // requeue user priorities 78 if (priorityIndex < userPriorities.Length) 79 for (int i = 0; i < priorityIndex; i++) { 80 userPriorities[i].DateEnqueued = DateTime.Now; 81 dao.EnqueueUserPriority(userPriorities[i]); 82 } 73 83 74 84 return scheduledTasks; -
branches/HiveTaskScheduler/HeuristicLab.Services.Hive/3.3/app.config
r7857 r8707 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.