Free cookie consent management tool by TermsFeed Policy Generator

Changeset 9109


Ignore:
Timestamp:
01/04/13 16:29:03 (11 years ago)
Author:
ascheibe
Message:

#1712 merged changes from trunk into branch and improved scheduler performance

Location:
branches/HiveTaskScheduler/HeuristicLab.Services.Hive/3.3
Files:
1 added
6 edited

Legend:

Unmodified
Added
Removed
  • branches/HiveTaskScheduler/HeuristicLab.Services.Hive/3.3/HeuristicLab.Services.Hive-3.3.csproj

    r8687 r9109  
    141141    <Compile Include="Interfaces\IHiveDao.cs" />
    142142    <Compile Include="Interfaces\ITaskScheduler.cs" />
     143    <Compile Include="Scheduler\JobInfoForScheduler.cs" />
    143144    <Compile Include="Scheduler\RoundRobinTaskScheduler.cs" />
    144145    <Compile Include="Settings.cs" />
  • branches/HiveTaskScheduler/HeuristicLab.Services.Hive/3.3/HiveDao.cs

    r8707 r9109  
    4949    }
    5050
     51    public IEnumerable<DT.LightweightTask> GetLightweightTasks(Expression<Func<Task, bool>> predicate) {
     52      List<DT.LightweightTask> tasks = new List<DT.LightweightTask>();
     53
     54      using (var db = CreateContext()) {
     55        var tasksQuery = db.Tasks.Where(predicate).Select(task => new { task.TaskId, task.ExecutionTimeMs, task.ParentTaskId, task.StateLogs, task.State, task.Command });
     56        var taskDatasQuery = db.Tasks.Where(predicate).Where(task => task.JobData != null).Select(task => new { task.TaskId, task.JobData.LastUpdate });
     57
     58        foreach (var task in tasksQuery) {
     59          DT.LightweightTask t = new DT.LightweightTask();
     60          t.Id = task.TaskId;
     61          t.ExecutionTime = TimeSpan.FromMilliseconds(task.ExecutionTimeMs);
     62          t.ParentTaskId = task.ParentTaskId;
     63          t.StateLog = task.StateLogs == null ? new List<DT.StateLog>() : task.StateLogs.Select(x => DataTransfer.Convert.ToDto(x)).OrderBy(x => x.DateTime).ToList();
     64          t.State = DataTransfer.Convert.ToDto(task.State);
     65          t.Command = DataTransfer.Convert.ToDto(task.Command);
     66          t.LastTaskDataUpdate = taskDatasQuery.Where(x => x.TaskId == task.TaskId).Count() > 0 ? taskDatasQuery.Select(x => x.LastUpdate).First() : DateTime.MinValue;
     67          tasks.Add(t);
     68        }
     69      }
     70      return tasks;
     71    }
     72
    5173    public Guid AddTask(DT.Task dto) {
    5274      using (var db = CreateContext()) {
     
    255277    }
    256278
     279    public IEnumerable<JobInfoForScheduler> GetJobInfoForScheduler(Expression<Func<Job, bool>> predicate) {
     280      using (var db = CreateContext()) {
     281        return db.Jobs.Where(predicate).Select(x => new JobInfoForScheduler() { Id = x.JobId, DateCreated = x.DateCreated, OwnerUserId = x.OwnerUserId }).ToArray();
     282      }
     283    }
     284
    257285    public Guid AddJob(DT.Job dto) {
    258286      using (var db = CreateContext()) {
    259287        var entity = DT.Convert.ToEntity(dto);
    260288        db.Jobs.InsertOnSubmit(entity);
    261         if (!db.Jobs.Any(x => x.OwnerUserId == dto.OwnerUserId))
     289        if (!db.UserPriorities.Any(x => x.UserId == dto.OwnerUserId))
    262290          EnqueueUserPriority(new DT.UserPriority { Id = dto.OwnerUserId, DateEnqueued = dto.DateCreated });
    263291        db.SubmitChanges();
     
    592620    public IEnumerable<DT.Resource> GetChildResources(Guid resourceId) {
    593621      using (var db = CreateContext()) {
    594         var childs = new List<DT.Resource>();
    595         foreach (var child in db.Resources.Where(x => x.ParentResourceId == resourceId)) {
    596           childs.Add(DT.Convert.ToDto(child));
    597           childs.AddRange(GetChildResources(child.ResourceId));
    598         }
    599         return childs;
    600       }
     622        return CollectChildResources(resourceId, db);
     623      }
     624    }
     625
     626    public IEnumerable<DT.Resource> CollectChildResources(Guid resourceId, HiveDataContext db) {
     627      var childs = new List<DT.Resource>();
     628      foreach (var child in db.Resources.Where(x => x.ParentResourceId == resourceId)) {
     629        childs.Add(DT.Convert.ToDto(child));
     630        childs.AddRange(CollectChildResources(child.ResourceId, db));
     631      }
     632      return childs;
    601633    }
    602634
     
    779811        if (entity != null) db.Statistics.DeleteOnSubmit(entity);
    780812        db.SubmitChanges();
     813      }
     814    }
     815
     816    public Dictionary<Guid, int> GetWaitingTasksByUser() {
     817      using (var db = CreateContext()) {
     818        var waitingTasksByUser = from task in db.Tasks
     819                                 where task.State == TaskState.Waiting
     820                                 group task by task.Job.OwnerUserId into g
     821                                 select new { UserId = g.Key, UsedCores = g.Count() };
     822        return waitingTasksByUser.ToDictionary(x => x.UserId, x => x.UsedCores);
     823      }
     824    }
     825
     826    public Dictionary<Guid, int> GetWaitingTasksByUserForResources(List<Guid> resourceIds) {
     827      using (var db = CreateContext()) {
     828        var waitingTasksByUser = from task in db.Tasks
     829                                 where task.State == TaskState.Waiting && task.AssignedResources.Any(x => resourceIds.Contains(x.ResourceId))
     830                                 group task by task.Job.OwnerUserId into g
     831                                 select new { UserId = g.Key, UsedCores = g.Count() };
     832        return waitingTasksByUser.ToDictionary(x => x.UserId, x => x.UsedCores);
     833      }
     834    }
     835
     836    public Dictionary<Guid, int> GetCalculatingTasksByUser() {
     837      using (var db = CreateContext()) {
     838        var calculatingTasksByUser = from task in db.Tasks
     839                                     where task.State == TaskState.Calculating
     840                                     group task by task.Job.OwnerUserId into g
     841                                     select new { UserId = g.Key, UsedCores = g.Count() };
     842        return calculatingTasksByUser.ToDictionary(x => x.UserId, x => x.UsedCores);
     843      }
     844    }
     845
     846    public Dictionary<Guid, int> GetCalculatingTasksByUserForResources(List<Guid> resourceIds) {
     847      using (var db = CreateContext()) {
     848        var calculatingTasksByUser = from task in db.Tasks
     849                                     where task.State == TaskState.Calculating && task.AssignedResources.Any(x => resourceIds.Contains(x.ResourceId))
     850                                     group task by task.Job.OwnerUserId into g
     851                                     select new { UserId = g.Key, UsedCores = g.Count() };
     852        return calculatingTasksByUser.ToDictionary(x => x.UserId, x => x.UsedCores);
    781853      }
    782854    }
  • branches/HiveTaskScheduler/HeuristicLab.Services.Hive/3.3/HiveService.cs

    r8687 r9109  
    128128
    129129      return trans.UseTransaction(() => {
    130         return dao.GetTasks(x => x.JobId == jobId).Select(x => new LightweightTask(x)).ToArray();
     130        return dao.GetLightweightTasks(task => task.JobId == jobId).ToArray();
    131131      }, false, false);
    132132    }
  • branches/HiveTaskScheduler/HeuristicLab.Services.Hive/3.3/Interfaces/IHiveDao.cs

    r8707 r9109  
    3131    DT.Task GetTask(Guid id);
    3232    IEnumerable<DT.Task> GetTasks(Expression<Func<Task, bool>> predicate);
     33    IEnumerable<DT.LightweightTask> GetLightweightTasks(Expression<Func<Task, bool>> predicate);
    3334    Guid AddTask(DT.Task dto);
    3435    void UpdateTask(DT.Task dto);
     
    5859    DT.Job GetJob(Guid id);
    5960    IEnumerable<DT.Job> GetJobs(Expression<Func<Job, bool>> predicate);
     61    IEnumerable<JobInfoForScheduler> GetJobInfoForScheduler(Expression<Func<Job, bool>> predicate);
    6062    Guid AddJob(DT.Job dto);
    6163    void UpdateJob(DT.Job dto);
     
    145147
    146148    #region Statistics Methods
     149    Dictionary<Guid, int> GetWaitingTasksByUser();
     150    Dictionary<Guid, int> GetWaitingTasksByUserForResources(List<Guid> resourceIds);
     151    Dictionary<Guid, int> GetCalculatingTasksByUser();
     152    Dictionary<Guid, int> GetCalculatingTasksByUserForResources(List<Guid> resourceIds);
    147153    DT.Statistics GetStatistic(Guid id);
    148154    IEnumerable<DT.Statistics> GetStatistics(Expression<Func<Statistics, bool>> predicate);
  • branches/HiveTaskScheduler/HeuristicLab.Services.Hive/3.3/Manager/HeartbeatManager.cs

    r8997 r9109  
    8787            DA.LogFactory.GetLogger(this.GetType().Namespace).Log("HeartbeatManager: The mutex used for scheduling has been abandoned.");
    8888          }
     89          catch (Exception ex) {
     90            DA.LogFactory.GetLogger(this.GetType().Namespace).Log("HeartbeatManager threw an exception in ProcessHeartbeat: " + ex.ToString());
     91          }
    8992          finally {
    9093            if (mutexAquired) mutex.ReleaseMutex();
  • branches/HiveTaskScheduler/HeuristicLab.Services.Hive/3.3/Scheduler/RoundRobinTaskScheduler.cs

    r8998 r9109  
    3636      var userPriorities = dao.GetUserPriorities(x => true).OrderBy(x => x.DateEnqueued).ToArray();
    3737
    38       var jobs = new List<Job>();
     38      var jobs = new List<JobInfoForScheduler>();
    3939      foreach (var userPriority in userPriorities) {
    40         jobs.AddRange(dao.GetJobs(x => x.OwnerUserId == userPriority.Id));
     40        jobs.AddRange(dao.GetJobInfoForScheduler(x => x.OwnerUserId == userPriority.Id));
    4141      }
    4242
     
    4444        task => task.JobId,
    4545        job => job.Id,
    46         (task, job) => new { Task = task, Job = job })
     46        (task, job) => new { Task = task, JobInfo = job })
    4747        .OrderByDescending(x => x.Task.Priority)
    4848        .ToList();
     
    5555      for (int i = 0; i < count; i++) {
    5656        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
     57        var priorityEntries = taskJobRelations.Where(x => x.JobInfo.OwnerUserId == userPriorities[priorityIndex].Id).ToArray(); // search for tasks with desired user priority
    5858        while (!priorityEntries.Any() && ++priorityIndex < userPriorities.Length)
    59           priorityEntries = taskJobRelations.Where(x => x.Job.OwnerUserId == userPriorities[priorityIndex].Id).ToArray();
     59          priorityEntries = taskJobRelations.Where(x => x.JobInfo.OwnerUserId == userPriorities[priorityIndex].Id).ToArray();
    6060        if (priorityEntries.Any()) { // tasks with desired user priority found
    61           var priorityEntry = priorityEntries.OrderByDescending(x => x.Task.Priority).ThenBy(x => x.Job.DateCreated).First();
     61          var priorityEntry = priorityEntries.OrderByDescending(x => x.Task.Priority).ThenBy(x => x.JobInfo.DateCreated).First();
    6262          if (defaultEntry.Task.Priority <= priorityEntry.Task.Priority) {
    6363            taskJobRelations.Remove(priorityEntry);
Note: See TracChangeset for help on using the changeset viewer.