Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
01/07/13 22:00:04 (12 years ago)
Author:
ascheibe
Message:

#1712 reintegrated Hive Scheduler branch and made further performance improvements

Location:
trunk/sources/HeuristicLab.Services.Hive
Files:
2 added
2 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Services.Hive

  • trunk/sources/HeuristicLab.Services.Hive/3.3/Scheduler/RoundRobinTaskScheduler.cs

    r8998 r9123  
    3131    }
    3232
    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>();
    3535
    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();
    4949
    50       var scheduledTasks = new List<Task>();
     50      var scheduledTasks = new List<TaskInfoForScheduler>();
    5151      int priorityIndex = 0;
    5252
     
    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
    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        }
    6062        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();
    6264          if (defaultEntry.Task.Priority <= priorityEntry.Task.Priority) {
    6365            taskJobRelations.Remove(priorityEntry);
    6466            scheduledTasks.Add(priorityEntry.Task);
     67            UpdateUserPriority(userPriorities[priorityIndex]);
    6568            priorityIndex++;
    6669          } else { // there are other tasks with higher priorities
     
    7275          scheduledTasks.Add(defaultEntry.Task);
    7376        }
     77
     78        if (priorityIndex >= (userPriorities.Length - 1)) priorityIndex = 0;
    7479      }
    75 
    76       // requeue user priorities
    77       if (priorityIndex < userPriorities.Length)
    78         for (int i = 0; i < priorityIndex; i++) {
    79           userPriorities[i].DateEnqueued = DateTime.Now;
    80           dao.EnqueueUserPriority(userPriorities[i]);
    81         }
    8280
    8381      return scheduledTasks;
    8482    }
     83
     84    private void UpdateUserPriority(UserPriority up) {
     85      up.DateEnqueued = DateTime.Now;
     86      dao.EnqueueUserPriority(up);
     87    }
    8588  }
    8689}
Note: See TracChangeset for help on using the changeset viewer.