Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/HeuristicLab.Services.Hive/3.3/Scheduler/RoundRobinTaskScheduler.cs @ 17764

Last change on this file since 17764 was 17574, checked in by jkarder, 5 years ago

#3062: overhauled statistics generation and cleanup

  • switched to a single thread for database cleanup and statistics generation (executed sequentially)
  • switched to preemptive deletion of items that are in status DeletionPending (for jobs: statelogs, taskdata, tasks)
  • added code that aborts tasks whose jobs have already been marked for deletion
  • added method UseTransactionAndSubmit in addition to UseTransaction in PersistenceManager
  • updated DAO methods and introduced more bare metal sql
  • introduced DAO methods for batch deletion
  • fixed usage of enum values in DAO sql queries
  • deleted unnecessary triggers tr_JobDeleteCascade and tr_TaskDeleteCascade in Prepare Hive Database.sql
  • changed scheduling for less interference with janitor and other heartbeats
    • increased scheduling patience from 20 to 70 seconds (to wait longer to get the mutex for scheduling)
    • changed signature of ITaskScheduler.Schedule
    • added base class for TaskSchedulers and moved assignment of tasks to slaves into it
    • changed RoundRobinTaskScheduler to use bare metal sql
  • made MessageContainer a storable type (leftover)
  • updated HiveJanitorServiceInstaller.nsi
File size: 2.5 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.Collections.Generic;
24using System.Linq;
25using DA = HeuristicLab.Services.Hive.DataAccess;
26
27namespace HeuristicLab.Services.Hive {
28  public class RoundRobinTaskScheduler : TaskScheduler {
29    private class TaskPriorityResult {
30      public Guid TaskId { get; set; }
31      public Guid OwnerUserId { get; set; }
32    }
33
34    protected override IReadOnlyList<Guid> ScheduleInternal(DA.Slave slave, int count) {
35      var pm = PersistenceManager;
36
37      var result = pm.DataContext.ExecuteQuery<TaskPriorityResult>(
38        GetHighestPriorityWaitingTasksQuery, slave.ResourceId, count, slave.FreeCores, slave.FreeMemory).ToList();
39
40      foreach (var row in result) {
41        pm.DataContext.ExecuteCommand("UPDATE UserPriority SET DateEnqueued = SYSDATETIME() WHERE UserId = {0}", row.OwnerUserId);
42      }
43
44      return result.Select(x => x.TaskId).ToArray();
45    }
46
47    #region Query Strings
48    private string GetHighestPriorityWaitingTasksQuery = @"
49WITH rbranch AS(
50  SELECT ResourceId, ParentResourceId
51  FROM [Resource]
52  WHERE ResourceId = {0}
53  UNION ALL
54  SELECT r.ResourceId, r.ParentResourceId
55  FROM [Resource] r
56  JOIN rbranch rb ON rb.ParentResourceId = r.ResourceId
57)
58SELECT TOP ({1}) t.TaskId, j.OwnerUserId
59FROM Task t
60  JOIN Job j on t.JobId = j.JobId
61  JOIN AssignedJobResource ajr on j.JobId = ajr.JobId
62  JOIN rbranch on ajr.ResourceId = rbranch.ResourceId
63  JOIN UserPriority u on j.OwnerUserId = u.UserId
64WHERE NOT (t.IsParentTask = 1 AND t.FinishWhenChildJobsFinished = 1)
65AND t.TaskState = 'Waiting'
66AND t.CoresNeeded <= {2}
67AND t.MemoryNeeded <= {3}
68AND j.JobState = 'Online'
69ORDER BY t.Priority DESC, u.DateEnqueued ASC, j.DateCreated ASC";
70    #endregion
71  }
72}
Note: See TracBrowser for help on using the repository browser.