src/Pure/Tools/build_schedule.scala
author Fabian Huch <huch@in.tum.de>
Thu, 23 Nov 2023 20:53:58 +0100
changeset 79028 6bada416ba55
parent 79027 d08fb157e300
child 79029 49e8b031e0cb
permissions -rw-r--r--
clarified timing data operations: proper estimation (instead of known points);
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
78845
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
     1
/*  Title:      Pure/Tools/build_schedule.scala
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
     2
    Author:     Fabian Huch, TU Muenchen
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
     3
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
     4
Build schedule generated by Heuristic methods, allowing for more efficient builds.
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
     5
 */
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
     6
package isabelle
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
     7
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
     8
78846
966aa081929f tuned imports;
wenzelm
parents: 78845
diff changeset
     9
import Host.Node_Info
78845
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
    10
import scala.annotation.tailrec
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
    11
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
    12
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
    13
object Build_Schedule {
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
    14
  val engine_name = "build_schedule"
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
    15
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
    16
  object Config {
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
    17
    def from_job(job: Build_Process.Job): Config = Config(job.name, job.node_info)
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
    18
  }
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
    19
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
    20
  case class Config(job_name: String, node_info: Node_Info) {
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
    21
    def job_of(start_time: Time): Build_Process.Job =
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
    22
      Build_Process.Job(job_name, "", "", node_info, Date(start_time), None)
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
    23
  }
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
    24
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
    25
  /* organized historic timing information (extracted from build logs) */
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
    26
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
    27
  case class Timing_Entry(job_name: String, hostname: String, threads: Int, elapsed: Time)
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
    28
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
    29
  class Timing_Data private(data: List[Timing_Entry], val host_infos: Host_Infos) {
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
    30
    require(data.nonEmpty)
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
    31
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
    32
    def is_empty = data.isEmpty
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
    33
    def size = data.length
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
    34
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
    35
    private lazy val by_job =
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
    36
      data.groupBy(_.job_name).view.mapValues(new Timing_Data(_, host_infos)).toMap
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
    37
    private lazy val by_threads =
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
    38
      data.groupBy(_.threads).view.mapValues(new Timing_Data(_, host_infos)).toMap
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
    39
    private lazy val by_hostname =
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
    40
      data.groupBy(_.hostname).view.mapValues(new Timing_Data(_, host_infos)).toMap
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
    41
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
    42
    def mean_time: Time = Timing_Data.mean_time(data.map(_.elapsed))
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
    43
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
    44
    private def best_entry: Timing_Entry = data.minBy(_.elapsed.ms)
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
    45
79025
f78ee2d48bf5 handle inflection point in interpolation with monotone prefix;
Fabian Huch <huch@in.tum.de>
parents: 79024
diff changeset
    46
    private def inflection_point(last_mono: Int, next: Int): Int =
f78ee2d48bf5 handle inflection point in interpolation with monotone prefix;
Fabian Huch <huch@in.tum.de>
parents: 79024
diff changeset
    47
      last_mono + ((next - last_mono) / 2)
f78ee2d48bf5 handle inflection point in interpolation with monotone prefix;
Fabian Huch <huch@in.tum.de>
parents: 79024
diff changeset
    48
79028
6bada416ba55 clarified timing data operations: proper estimation (instead of known points);
Fabian Huch <huch@in.tum.de>
parents: 79027
diff changeset
    49
    def best_threads(job_name: String, max_threads: Int): Int = {
6bada416ba55 clarified timing data operations: proper estimation (instead of known points);
Fabian Huch <huch@in.tum.de>
parents: 79027
diff changeset
    50
      val worse_threads =
6bada416ba55 clarified timing data operations: proper estimation (instead of known points);
Fabian Huch <huch@in.tum.de>
parents: 79027
diff changeset
    51
        by_job.get(job_name).toList.flatMap(_.by_hostname).flatMap {
6bada416ba55 clarified timing data operations: proper estimation (instead of known points);
Fabian Huch <huch@in.tum.de>
parents: 79027
diff changeset
    52
          case (hostname, data) =>
6bada416ba55 clarified timing data operations: proper estimation (instead of known points);
Fabian Huch <huch@in.tum.de>
parents: 79027
diff changeset
    53
            val best_threads = data.best_entry.threads
6bada416ba55 clarified timing data operations: proper estimation (instead of known points);
Fabian Huch <huch@in.tum.de>
parents: 79027
diff changeset
    54
            data.by_threads.keys.toList.sorted.find(_ > best_threads).map(
6bada416ba55 clarified timing data operations: proper estimation (instead of known points);
Fabian Huch <huch@in.tum.de>
parents: 79027
diff changeset
    55
              inflection_point(best_threads, _))
6bada416ba55 clarified timing data operations: proper estimation (instead of known points);
Fabian Huch <huch@in.tum.de>
parents: 79027
diff changeset
    56
        }
6bada416ba55 clarified timing data operations: proper estimation (instead of known points);
Fabian Huch <huch@in.tum.de>
parents: 79027
diff changeset
    57
      (max_threads :: worse_threads).min
6bada416ba55 clarified timing data operations: proper estimation (instead of known points);
Fabian Huch <huch@in.tum.de>
parents: 79027
diff changeset
    58
    }
78845
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
    59
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
    60
    private def hostname_factor(from: String, to: String): Double =
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
    61
      host_infos.host_factor(host_infos.the_host(from), host_infos.the_host(to))
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
    62
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
    63
    def approximate_threads(threads: Int): Option[Time] = {
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
    64
      val approximations =
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
    65
        by_job.values.filter(_.size > 1).map { data =>
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
    66
          val (ref_hostname, x0) =
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
    67
            data.by_hostname.toList.flatMap((hostname, data) =>
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
    68
              data.by_threads.keys.map(hostname -> _)).minBy((_, n) => Math.abs(n - threads))
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
    69
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
    70
          def unify_hosts(data: Timing_Data): List[Time] =
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
    71
            data.by_hostname.toList.map((hostname, data) =>
78888
95bbf9a576b3 prefer Time.scale(), following Isabelle/ML;
wenzelm
parents: 78884
diff changeset
    72
              data.mean_time.scale(hostname_factor(hostname, ref_hostname)))
78845
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
    73
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
    74
          val entries =
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
    75
            data.by_threads.toList.map((threads, data) =>
79022
e4fc535d4d2f proper piecewise linear build time interpolation;
Fabian Huch <huch@in.tum.de>
parents: 79021
diff changeset
    76
              threads -> Timing_Data.median_time(unify_hosts(data))).sortBy(_._1)
78845
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
    77
79024
d989e00c3ff5 proper computation of sorted prefix;
Fabian Huch <huch@in.tum.de>
parents: 79023
diff changeset
    78
          def sorted_prefix[A](xs: List[A], f: A => Long): List[A] =
d989e00c3ff5 proper computation of sorted prefix;
Fabian Huch <huch@in.tum.de>
parents: 79023
diff changeset
    79
            xs match {
d989e00c3ff5 proper computation of sorted prefix;
Fabian Huch <huch@in.tum.de>
parents: 79023
diff changeset
    80
              case x1 :: x2 :: xs =>
d989e00c3ff5 proper computation of sorted prefix;
Fabian Huch <huch@in.tum.de>
parents: 79023
diff changeset
    81
                if (f(x1) <= f(x2)) x1 :: sorted_prefix(x2 :: xs, f) else x1 :: Nil
d989e00c3ff5 proper computation of sorted prefix;
Fabian Huch <huch@in.tum.de>
parents: 79023
diff changeset
    82
              case xs => xs
d989e00c3ff5 proper computation of sorted prefix;
Fabian Huch <huch@in.tum.de>
parents: 79023
diff changeset
    83
            }
79025
f78ee2d48bf5 handle inflection point in interpolation with monotone prefix;
Fabian Huch <huch@in.tum.de>
parents: 79024
diff changeset
    84
f78ee2d48bf5 handle inflection point in interpolation with monotone prefix;
Fabian Huch <huch@in.tum.de>
parents: 79024
diff changeset
    85
          def linear(p0: (Int, Time), p1: (Int, Time)): Time = {
f78ee2d48bf5 handle inflection point in interpolation with monotone prefix;
Fabian Huch <huch@in.tum.de>
parents: 79024
diff changeset
    86
            val a = (p1._2 - p0._2).scale(1.0 / (p1._1 - p0._1))
f78ee2d48bf5 handle inflection point in interpolation with monotone prefix;
Fabian Huch <huch@in.tum.de>
parents: 79024
diff changeset
    87
            val b = p0._2 - a.scale(p0._1)
f78ee2d48bf5 handle inflection point in interpolation with monotone prefix;
Fabian Huch <huch@in.tum.de>
parents: 79024
diff changeset
    88
            Time.ms((a.scale(threads) + b).ms max 0)
f78ee2d48bf5 handle inflection point in interpolation with monotone prefix;
Fabian Huch <huch@in.tum.de>
parents: 79024
diff changeset
    89
          }
f78ee2d48bf5 handle inflection point in interpolation with monotone prefix;
Fabian Huch <huch@in.tum.de>
parents: 79024
diff changeset
    90
79024
d989e00c3ff5 proper computation of sorted prefix;
Fabian Huch <huch@in.tum.de>
parents: 79023
diff changeset
    91
          val monotone_prefix = sorted_prefix(entries, e => -e._2.ms)
79023
abc27a824419 better build time interpolation: model with Amdahl's law where applicable;
Fabian Huch <huch@in.tum.de>
parents: 79022
diff changeset
    92
79025
f78ee2d48bf5 handle inflection point in interpolation with monotone prefix;
Fabian Huch <huch@in.tum.de>
parents: 79024
diff changeset
    93
          val is_mono = entries == monotone_prefix
f78ee2d48bf5 handle inflection point in interpolation with monotone prefix;
Fabian Huch <huch@in.tum.de>
parents: 79024
diff changeset
    94
          val in_prefix = monotone_prefix.length > 1 && threads <= monotone_prefix.last._1
f78ee2d48bf5 handle inflection point in interpolation with monotone prefix;
Fabian Huch <huch@in.tum.de>
parents: 79024
diff changeset
    95
          val in_inflection = !is_mono && threads < entries.drop(monotone_prefix.length).head._1
f78ee2d48bf5 handle inflection point in interpolation with monotone prefix;
Fabian Huch <huch@in.tum.de>
parents: 79024
diff changeset
    96
          if (is_mono || in_prefix || in_inflection) {
79023
abc27a824419 better build time interpolation: model with Amdahl's law where applicable;
Fabian Huch <huch@in.tum.de>
parents: 79022
diff changeset
    97
            // Model with Amdahl's law
abc27a824419 better build time interpolation: model with Amdahl's law where applicable;
Fabian Huch <huch@in.tum.de>
parents: 79022
diff changeset
    98
            val t_p =
abc27a824419 better build time interpolation: model with Amdahl's law where applicable;
Fabian Huch <huch@in.tum.de>
parents: 79022
diff changeset
    99
              Timing_Data.median_time(for {
abc27a824419 better build time interpolation: model with Amdahl's law where applicable;
Fabian Huch <huch@in.tum.de>
parents: 79022
diff changeset
   100
                (n, t0) <- monotone_prefix
abc27a824419 better build time interpolation: model with Amdahl's law where applicable;
Fabian Huch <huch@in.tum.de>
parents: 79022
diff changeset
   101
                (m, t1) <- monotone_prefix
abc27a824419 better build time interpolation: model with Amdahl's law where applicable;
Fabian Huch <huch@in.tum.de>
parents: 79022
diff changeset
   102
                if m != n
abc27a824419 better build time interpolation: model with Amdahl's law where applicable;
Fabian Huch <huch@in.tum.de>
parents: 79022
diff changeset
   103
              } yield (t0 - t1).scale(n.toDouble * m / (m - n)))
abc27a824419 better build time interpolation: model with Amdahl's law where applicable;
Fabian Huch <huch@in.tum.de>
parents: 79022
diff changeset
   104
            val t_c =
abc27a824419 better build time interpolation: model with Amdahl's law where applicable;
Fabian Huch <huch@in.tum.de>
parents: 79022
diff changeset
   105
              Timing_Data.median_time(for ((n, t) <- monotone_prefix) yield t - t_p.scale(1.0 / n))
78845
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   106
79025
f78ee2d48bf5 handle inflection point in interpolation with monotone prefix;
Fabian Huch <huch@in.tum.de>
parents: 79024
diff changeset
   107
            def model(threads: Int): Time = t_c + t_p.scale(1.0 / threads)
f78ee2d48bf5 handle inflection point in interpolation with monotone prefix;
Fabian Huch <huch@in.tum.de>
parents: 79024
diff changeset
   108
f78ee2d48bf5 handle inflection point in interpolation with monotone prefix;
Fabian Huch <huch@in.tum.de>
parents: 79024
diff changeset
   109
            if (is_mono || in_prefix) model(threads)
f78ee2d48bf5 handle inflection point in interpolation with monotone prefix;
Fabian Huch <huch@in.tum.de>
parents: 79024
diff changeset
   110
            else {
f78ee2d48bf5 handle inflection point in interpolation with monotone prefix;
Fabian Huch <huch@in.tum.de>
parents: 79024
diff changeset
   111
              val post_inflection = entries.drop(monotone_prefix.length).head
f78ee2d48bf5 handle inflection point in interpolation with monotone prefix;
Fabian Huch <huch@in.tum.de>
parents: 79024
diff changeset
   112
              val inflection_threads = inflection_point(monotone_prefix.last._1, post_inflection._1)
f78ee2d48bf5 handle inflection point in interpolation with monotone prefix;
Fabian Huch <huch@in.tum.de>
parents: 79024
diff changeset
   113
f78ee2d48bf5 handle inflection point in interpolation with monotone prefix;
Fabian Huch <huch@in.tum.de>
parents: 79024
diff changeset
   114
              if (threads <= inflection_threads) model(threads)
f78ee2d48bf5 handle inflection point in interpolation with monotone prefix;
Fabian Huch <huch@in.tum.de>
parents: 79024
diff changeset
   115
              else linear((inflection_threads, model(inflection_threads)), post_inflection)
f78ee2d48bf5 handle inflection point in interpolation with monotone prefix;
Fabian Huch <huch@in.tum.de>
parents: 79024
diff changeset
   116
            }
79023
abc27a824419 better build time interpolation: model with Amdahl's law where applicable;
Fabian Huch <huch@in.tum.de>
parents: 79022
diff changeset
   117
          } else {
abc27a824419 better build time interpolation: model with Amdahl's law where applicable;
Fabian Huch <huch@in.tum.de>
parents: 79022
diff changeset
   118
            // Piecewise linear
79025
f78ee2d48bf5 handle inflection point in interpolation with monotone prefix;
Fabian Huch <huch@in.tum.de>
parents: 79024
diff changeset
   119
            val (p0, p1) =
79023
abc27a824419 better build time interpolation: model with Amdahl's law where applicable;
Fabian Huch <huch@in.tum.de>
parents: 79022
diff changeset
   120
              if (entries.head._1 <= threads && threads <= entries.last._1) {
abc27a824419 better build time interpolation: model with Amdahl's law where applicable;
Fabian Huch <huch@in.tum.de>
parents: 79022
diff changeset
   121
                val split = entries.partition(_._1 <= threads)
abc27a824419 better build time interpolation: model with Amdahl's law where applicable;
Fabian Huch <huch@in.tum.de>
parents: 79022
diff changeset
   122
                (split._1.last, split._2.head)
abc27a824419 better build time interpolation: model with Amdahl's law where applicable;
Fabian Huch <huch@in.tum.de>
parents: 79022
diff changeset
   123
              } else {
abc27a824419 better build time interpolation: model with Amdahl's law where applicable;
Fabian Huch <huch@in.tum.de>
parents: 79022
diff changeset
   124
                val piece = if (threads < entries.head._1) entries.take(2) else entries.takeRight(2)
abc27a824419 better build time interpolation: model with Amdahl's law where applicable;
Fabian Huch <huch@in.tum.de>
parents: 79022
diff changeset
   125
                (piece.head, piece.last)
abc27a824419 better build time interpolation: model with Amdahl's law where applicable;
Fabian Huch <huch@in.tum.de>
parents: 79022
diff changeset
   126
              }
abc27a824419 better build time interpolation: model with Amdahl's law where applicable;
Fabian Huch <huch@in.tum.de>
parents: 79022
diff changeset
   127
79025
f78ee2d48bf5 handle inflection point in interpolation with monotone prefix;
Fabian Huch <huch@in.tum.de>
parents: 79024
diff changeset
   128
            linear(p0, p1)
79023
abc27a824419 better build time interpolation: model with Amdahl's law where applicable;
Fabian Huch <huch@in.tum.de>
parents: 79022
diff changeset
   129
          }
78845
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   130
        }
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   131
      if (approximations.isEmpty) None else Some(Timing_Data.mean_time(approximations))
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   132
    }
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   133
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   134
    def threads_factor(divided: Int, divisor: Int): Double =
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   135
      (approximate_threads(divided), approximate_threads(divisor)) match {
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   136
        case (Some(dividend), Some(divisor)) => dividend.ms.toDouble / divisor.ms
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   137
        case _ => divided.toDouble / divisor
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   138
      }
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   139
79026
6585acdd6505 clarified time estimation: does not use config;
Fabian Huch <huch@in.tum.de>
parents: 79025
diff changeset
   140
    def estimate(job_name: String, hostname: String, threads: Int): Time =
6585acdd6505 clarified time estimation: does not use config;
Fabian Huch <huch@in.tum.de>
parents: 79025
diff changeset
   141
      by_job.get(job_name) match {
78845
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   142
        case None => mean_time
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   143
        case Some(data) =>
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   144
          data.by_threads.get(threads) match {
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   145
            case None => // interpolate threads
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   146
              data.by_hostname.get(hostname).flatMap(
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   147
                _.approximate_threads(threads)).getOrElse {
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   148
                  // per machine, try to approximate config for threads
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   149
                  val approximated =
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   150
                    data.by_hostname.toList.flatMap((hostname1, data) =>
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   151
                      data.approximate_threads(threads).map(time =>
78888
95bbf9a576b3 prefer Time.scale(), following Isabelle/ML;
wenzelm
parents: 78884
diff changeset
   152
                        time.scale(hostname_factor(hostname1, hostname))))
78845
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   153
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   154
                  if (approximated.nonEmpty) Timing_Data.mean_time(approximated)
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   155
                  else {
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   156
                    // no machine where config can be approximated
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   157
                    data.approximate_threads(threads).getOrElse {
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   158
                      // only single data point, use global curve to approximate
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   159
                      val global_factor = threads_factor(data.by_threads.keys.head, threads)
78888
95bbf9a576b3 prefer Time.scale(), following Isabelle/ML;
wenzelm
parents: 78884
diff changeset
   160
                      data.by_threads.values.head.mean_time.scale(global_factor)
78845
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   161
                    }
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   162
                  }
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   163
                }
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   164
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   165
            case Some(data) => // time for job/thread exists, interpolate machine
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   166
              data.by_hostname.get(hostname).map(_.mean_time).getOrElse {
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   167
                Timing_Data.median_time(
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   168
                  data.by_hostname.toList.map((hostname1, data) =>
78888
95bbf9a576b3 prefer Time.scale(), following Isabelle/ML;
wenzelm
parents: 78884
diff changeset
   169
                    data.mean_time.scale(hostname_factor(hostname1, hostname))))
78845
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   170
              }
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   171
          }
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   172
      }
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   173
  }
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   174
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   175
  object Timing_Data {
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   176
    def median_time(obs: List[Time]): Time = obs.sortBy(_.ms).drop(obs.length / 2).head
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   177
    def mean_time(obs: Iterable[Time]): Time = Time.ms(obs.map(_.ms).sum / obs.size)
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   178
78934
5553a86a1091 proper dummy timing entries;
Fabian Huch <huch@in.tum.de>
parents: 78933
diff changeset
   179
    private def dummy_entries(host: Host, host_factor: Double) =
78845
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   180
      List(
78934
5553a86a1091 proper dummy timing entries;
Fabian Huch <huch@in.tum.de>
parents: 78933
diff changeset
   181
        Timing_Entry("dummy", host.info.hostname, 1, Time.minutes(5).scale(host_factor)),
5553a86a1091 proper dummy timing entries;
Fabian Huch <huch@in.tum.de>
parents: 78933
diff changeset
   182
        Timing_Entry("dummy", host.info.hostname, 8, Time.minutes(1).scale(host_factor)))
78845
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   183
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   184
    def make(
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   185
      host_infos: Host_Infos,
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   186
      build_history: List[(Build_Log.Meta_Info, Build_Log.Build_Info)],
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   187
    ): Timing_Data = {
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   188
      val hosts = host_infos.hosts
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   189
      val measurements =
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   190
        for {
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   191
          (meta_info, build_info) <- build_history
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   192
          build_host <- meta_info.get(Build_Log.Prop.build_host).toList
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   193
          (job_name, session_info) <- build_info.sessions.toList
78933
4f940d7293ea use only finished sessions in timing data;
Fabian Huch <huch@in.tum.de>
parents: 78932
diff changeset
   194
          if build_info.finished_sessions.contains(job_name)
78845
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   195
          hostname = session_info.hostname.getOrElse(build_host)
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   196
          host <- hosts.find(_.info.hostname == build_host).toList
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   197
          threads = session_info.threads.getOrElse(host.info.num_cpus)
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   198
        } yield (job_name, hostname, threads) -> session_info.timing.elapsed
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   199
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   200
      val entries =
78934
5553a86a1091 proper dummy timing entries;
Fabian Huch <huch@in.tum.de>
parents: 78933
diff changeset
   201
        if (measurements.isEmpty) {
5553a86a1091 proper dummy timing entries;
Fabian Huch <huch@in.tum.de>
parents: 78933
diff changeset
   202
          val default_host = host_infos.hosts.sorted(host_infos.host_speeds).head
5553a86a1091 proper dummy timing entries;
Fabian Huch <huch@in.tum.de>
parents: 78933
diff changeset
   203
          host_infos.hosts.flatMap(host =>
5553a86a1091 proper dummy timing entries;
Fabian Huch <huch@in.tum.de>
parents: 78933
diff changeset
   204
            dummy_entries(host, host_infos.host_factor(default_host, host)))
5553a86a1091 proper dummy timing entries;
Fabian Huch <huch@in.tum.de>
parents: 78933
diff changeset
   205
        }
78845
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   206
        else
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   207
          measurements.groupMap(_._1)(_._2).toList.map {
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   208
            case ((job_name, hostname, threads), timings) =>
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   209
              Timing_Entry(job_name, hostname, threads, median_time(timings))
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   210
          }
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   211
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   212
      new Timing_Data(entries, host_infos)
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   213
    }
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   214
  }
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   215
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   216
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   217
  /* host information */
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   218
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   219
  case class Host(info: isabelle.Host.Info, build: Build_Cluster.Host)
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   220
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   221
  object Host_Infos {
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   222
    def dummy: Host_Infos =
78846
966aa081929f tuned imports;
wenzelm
parents: 78845
diff changeset
   223
      new Host_Infos(
966aa081929f tuned imports;
wenzelm
parents: 78845
diff changeset
   224
        List(Host(isabelle.Host.Info("dummy", Nil, 8, Some(1.0)), Build_Cluster.Host("dummy"))))
78845
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   225
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   226
    def apply(build_hosts: List[Build_Cluster.Host], db: SQL.Database): Host_Infos = {
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   227
      def get_host(build_host: Build_Cluster.Host): Host = {
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   228
        val info =
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   229
          isabelle.Host.read_info(db, build_host.name).getOrElse(
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   230
            error("No benchmark for " + quote(build_host.name)))
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   231
        Host(info, build_host)
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   232
      }
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   233
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   234
      new Host_Infos(build_hosts.map(get_host))
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   235
    }
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   236
  }
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   237
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   238
  class Host_Infos private(val hosts: List[Host]) {
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   239
    private val by_hostname = hosts.map(host => host.info.hostname -> host).toMap
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   240
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   241
    def host_factor(from: Host, to: Host): Double =
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   242
      from.info.benchmark_score.get / to.info.benchmark_score.get
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   243
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   244
    val host_speeds: Ordering[Host] =
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   245
      Ordering.fromLessThan((host1, host2) => host_factor(host1, host2) > 1)
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   246
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   247
    def the_host(hostname: String): Host =
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   248
      by_hostname.getOrElse(hostname, error("Unknown host " + quote(hostname)))
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   249
    def the_host(node_info: Node_Info): Host = the_host(node_info.hostname)
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   250
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   251
    def num_threads(node_info: Node_Info): Int =
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   252
      if (node_info.rel_cpus.nonEmpty) node_info.rel_cpus.length
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   253
      else the_host(node_info).info.num_cpus
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   254
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   255
    def available(state: Build_Process.State): Resources = {
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   256
      val allocated =
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   257
        state.running.values.map(_.node_info).groupMapReduce(the_host)(List(_))(_ ::: _)
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   258
      Resources(this, allocated)
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   259
    }
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   260
  }
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   261
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   262
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   263
  /* offline tracking of resource allocations */
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   264
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   265
  case class Resources(
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   266
    host_infos: Host_Infos,
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   267
    allocated_nodes: Map[Host, List[Node_Info]]
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   268
  ) {
78973
d91e131840a0 timing heuristic: parallelize more aggressively to utilize hosts fully;
Fabian Huch <huch@in.tum.de>
parents: 78972
diff changeset
   269
    def unused_nodes(threads: Int): List[Node_Info] = {
d91e131840a0 timing heuristic: parallelize more aggressively to utilize hosts fully;
Fabian Huch <huch@in.tum.de>
parents: 78972
diff changeset
   270
      val fully_allocated =
d91e131840a0 timing heuristic: parallelize more aggressively to utilize hosts fully;
Fabian Huch <huch@in.tum.de>
parents: 78972
diff changeset
   271
        host_infos.hosts.foldLeft(this) { case (resources, host) =>
d91e131840a0 timing heuristic: parallelize more aggressively to utilize hosts fully;
Fabian Huch <huch@in.tum.de>
parents: 78972
diff changeset
   272
          if (!resources.available(host, threads)) resources
d91e131840a0 timing heuristic: parallelize more aggressively to utilize hosts fully;
Fabian Huch <huch@in.tum.de>
parents: 78972
diff changeset
   273
          else resources.allocate(resources.next_node(host, threads))
d91e131840a0 timing heuristic: parallelize more aggressively to utilize hosts fully;
Fabian Huch <huch@in.tum.de>
parents: 78972
diff changeset
   274
        }
d91e131840a0 timing heuristic: parallelize more aggressively to utilize hosts fully;
Fabian Huch <huch@in.tum.de>
parents: 78972
diff changeset
   275
      val used_nodes = allocated_nodes.values.flatten.toSet
d91e131840a0 timing heuristic: parallelize more aggressively to utilize hosts fully;
Fabian Huch <huch@in.tum.de>
parents: 78972
diff changeset
   276
      fully_allocated.allocated_nodes.values.flatten.toList.filterNot(used_nodes.contains)
d91e131840a0 timing heuristic: parallelize more aggressively to utilize hosts fully;
Fabian Huch <huch@in.tum.de>
parents: 78972
diff changeset
   277
    }
78845
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   278
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   279
    def allocated(host: Host): List[Node_Info] = allocated_nodes.getOrElse(host, Nil)
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   280
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   281
    def allocate(node: Node_Info): Resources = {
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   282
      val host = host_infos.the_host(node)
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   283
      copy(allocated_nodes = allocated_nodes + (host -> (node :: allocated(host))))
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   284
    }
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   285
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   286
    def try_allocate_tasks(
78971
f930d24f1548 scheduled build: allocate cpus more aggressively, to avoid idle threads;
Fabian Huch <huch@in.tum.de>
parents: 78970
diff changeset
   287
      hosts: List[(Host, Int)],
f930d24f1548 scheduled build: allocate cpus more aggressively, to avoid idle threads;
Fabian Huch <huch@in.tum.de>
parents: 78970
diff changeset
   288
      tasks: List[(Build_Process.Task, Int, Int)],
78845
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   289
    ): (List[Config], Resources) =
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   290
      tasks match {
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   291
        case Nil => (Nil, this)
78971
f930d24f1548 scheduled build: allocate cpus more aggressively, to avoid idle threads;
Fabian Huch <huch@in.tum.de>
parents: 78970
diff changeset
   292
        case (task, min_threads, max_threads) :: tasks =>
78845
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   293
          val (config, resources) =
78971
f930d24f1548 scheduled build: allocate cpus more aggressively, to avoid idle threads;
Fabian Huch <huch@in.tum.de>
parents: 78970
diff changeset
   294
            hosts.find((host, _) => available(host, min_threads)) match {
f930d24f1548 scheduled build: allocate cpus more aggressively, to avoid idle threads;
Fabian Huch <huch@in.tum.de>
parents: 78970
diff changeset
   295
              case Some((host, host_max_threads)) =>
f930d24f1548 scheduled build: allocate cpus more aggressively, to avoid idle threads;
Fabian Huch <huch@in.tum.de>
parents: 78970
diff changeset
   296
                val free_threads = host.info.num_cpus - ((host.build.jobs - 1) * host_max_threads)
f930d24f1548 scheduled build: allocate cpus more aggressively, to avoid idle threads;
Fabian Huch <huch@in.tum.de>
parents: 78970
diff changeset
   297
                val node_info = next_node(host, (min_threads max free_threads) min max_threads)
78845
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   298
                (Some(Config(task.name, node_info)), allocate(node_info))
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   299
              case None => (None, this)
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   300
            }
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   301
          val (configs, resources1) = resources.try_allocate_tasks(hosts, tasks)
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   302
          (configs ++ config, resources1)
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   303
      }
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   304
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   305
    def next_node(host: Host, threads: Int): Node_Info = {
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   306
      val numa_node_num_cpus = host.info.num_cpus / (host.info.numa_nodes.length max 1)
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   307
      def explicit_cpus(node_info: Node_Info): List[Int] =
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   308
        if (node_info.rel_cpus.nonEmpty) node_info.rel_cpus else (0 until numa_node_num_cpus).toList
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   309
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   310
      val used_nodes = allocated(host).groupMapReduce(_.numa_node)(explicit_cpus)(_ ::: _)
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   311
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   312
      val available_nodes = host.info.numa_nodes
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   313
      val numa_node =
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   314
        if (!host.build.numa) None
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   315
        else available_nodes.sortBy(n => used_nodes.getOrElse(Some(n), Nil).length).headOption
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   316
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   317
      val used_cpus = used_nodes.getOrElse(numa_node, Nil).toSet
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   318
      val available_cpus = (0 until numa_node_num_cpus).filterNot(used_cpus.contains).toList
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   319
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   320
      val rel_cpus = if (available_cpus.length >= threads) available_cpus.take(threads) else Nil
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   321
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   322
      Node_Info(host.info.hostname, numa_node, rel_cpus)
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   323
    }
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   324
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   325
    def available(host: Host, threads: Int): Boolean = {
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   326
      val used = allocated(host)
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   327
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   328
      if (used.length >= host.build.jobs) false
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   329
      else {
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   330
        if (host.info.numa_nodes.length <= 1)
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   331
          used.map(host_infos.num_threads).sum + threads <= host.info.num_cpus
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   332
        else {
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   333
          def node_threads(n: Int): Int =
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   334
            used.filter(_.numa_node.contains(n)).map(host_infos.num_threads).sum
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   335
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   336
          host.info.numa_nodes.exists(
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   337
            node_threads(_) + threads <= host.info.num_cpus / host.info.numa_nodes.length)
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   338
        }
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   339
      }
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   340
    }
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   341
  }
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   342
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   343
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   344
  /* schedule generation */
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   345
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   346
  case class State(build_state: Build_Process.State, current_time: Time) {
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   347
    def start(config: Config): State =
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   348
      copy(build_state =
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   349
        build_state.copy(running = build_state.running +
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   350
          (config.job_name -> config.job_of(current_time))))
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   351
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   352
    def step(timing_data: Timing_Data): State = {
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   353
      val remaining =
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   354
        build_state.running.values.toList.map { job =>
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   355
          val elapsed = current_time - job.start_date.time
79026
6585acdd6505 clarified time estimation: does not use config;
Fabian Huch <huch@in.tum.de>
parents: 79025
diff changeset
   356
          val threads = timing_data.host_infos.num_threads(job.node_info)
6585acdd6505 clarified time estimation: does not use config;
Fabian Huch <huch@in.tum.de>
parents: 79025
diff changeset
   357
          val predicted = timing_data.estimate(job.name, job.node_info.hostname, threads)
78845
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   358
          val remaining = if (elapsed > predicted) Time.zero else predicted - elapsed
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   359
          job -> remaining
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   360
        }
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   361
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   362
      if (remaining.isEmpty) error("Schedule step without running sessions")
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   363
      else {
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   364
        val (job, elapsed) = remaining.minBy(_._2.ms)
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   365
        State(build_state.remove_running(job.name).remove_pending(job.name), current_time + elapsed)
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   366
      }
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   367
    }
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   368
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   369
    def finished: Boolean = build_state.pending.isEmpty && build_state.running.isEmpty
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   370
  }
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   371
78932
Fabian Huch <huch@in.tum.de>
parents: 78931
diff changeset
   372
  trait Scheduler {
78928
6c2c60b852e0 move timing data into scheduler for more efficient heuristics (e.g., with pre-calculated values);
Fabian Huch <huch@in.tum.de>
parents: 78888
diff changeset
   373
    def next(state: Build_Process.State): List[Config]
78931
26841d3c568c performance tuning for build schedule: explicit schedule generation, without mixing heuristics;
Fabian Huch <huch@in.tum.de>
parents: 78930
diff changeset
   374
    def build_duration(build_state: Build_Process.State): Time
26841d3c568c performance tuning for build schedule: explicit schedule generation, without mixing heuristics;
Fabian Huch <huch@in.tum.de>
parents: 78930
diff changeset
   375
  }
26841d3c568c performance tuning for build schedule: explicit schedule generation, without mixing heuristics;
Fabian Huch <huch@in.tum.de>
parents: 78930
diff changeset
   376
79027
d08fb157e300 use proper max threads (limited by available hardware) in heuristics;
Fabian Huch <huch@in.tum.de>
parents: 79026
diff changeset
   377
  abstract class Heuristic(timing_data: Timing_Data, max_threads_limit: Int) extends Scheduler {
79019
4df053d29215 introduced path heuristic abstraction;
Fabian Huch <huch@in.tum.de>
parents: 78976
diff changeset
   378
    val host_infos = timing_data.host_infos
79028
6bada416ba55 clarified timing data operations: proper estimation (instead of known points);
Fabian Huch <huch@in.tum.de>
parents: 79027
diff changeset
   379
    val ordered_hosts = host_infos.hosts.sorted(host_infos.host_speeds)
79027
d08fb157e300 use proper max threads (limited by available hardware) in heuristics;
Fabian Huch <huch@in.tum.de>
parents: 79026
diff changeset
   380
    val max_threads = host_infos.hosts.map(_.info.num_cpus).max min max_threads_limit
79019
4df053d29215 introduced path heuristic abstraction;
Fabian Huch <huch@in.tum.de>
parents: 78976
diff changeset
   381
79028
6bada416ba55 clarified timing data operations: proper estimation (instead of known points);
Fabian Huch <huch@in.tum.de>
parents: 79027
diff changeset
   382
    def best_time(job_name: String): Time = {
6bada416ba55 clarified timing data operations: proper estimation (instead of known points);
Fabian Huch <huch@in.tum.de>
parents: 79027
diff changeset
   383
      val host = ordered_hosts.last
6bada416ba55 clarified timing data operations: proper estimation (instead of known points);
Fabian Huch <huch@in.tum.de>
parents: 79027
diff changeset
   384
      val threads = timing_data.best_threads(job_name, max_threads) min host.info.num_cpus
6bada416ba55 clarified timing data operations: proper estimation (instead of known points);
Fabian Huch <huch@in.tum.de>
parents: 79027
diff changeset
   385
      timing_data.estimate(job_name, host.info.hostname, threads)
6bada416ba55 clarified timing data operations: proper estimation (instead of known points);
Fabian Huch <huch@in.tum.de>
parents: 79027
diff changeset
   386
    }
6bada416ba55 clarified timing data operations: proper estimation (instead of known points);
Fabian Huch <huch@in.tum.de>
parents: 79027
diff changeset
   387
78928
6c2c60b852e0 move timing data into scheduler for more efficient heuristics (e.g., with pre-calculated values);
Fabian Huch <huch@in.tum.de>
parents: 78888
diff changeset
   388
    def build_duration(build_state: Build_Process.State): Time = {
78845
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   389
      @tailrec
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   390
      def simulate(state: State): State =
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   391
        if (state.finished) state
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   392
        else {
78932
Fabian Huch <huch@in.tum.de>
parents: 78931
diff changeset
   393
          val state1 = next(state.build_state).foldLeft(state)(_.start(_)).step(timing_data)
78845
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   394
          simulate(state1)
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   395
        }
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   396
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   397
      val start = Time.now()
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   398
      simulate(State(build_state, start)).current_time - start
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   399
    }
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   400
  }
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   401
78931
26841d3c568c performance tuning for build schedule: explicit schedule generation, without mixing heuristics;
Fabian Huch <huch@in.tum.de>
parents: 78930
diff changeset
   402
  class Meta_Heuristic(heuristics: List[Heuristic]) extends Scheduler {
26841d3c568c performance tuning for build schedule: explicit schedule generation, without mixing heuristics;
Fabian Huch <huch@in.tum.de>
parents: 78930
diff changeset
   403
    require(heuristics.nonEmpty)
26841d3c568c performance tuning for build schedule: explicit schedule generation, without mixing heuristics;
Fabian Huch <huch@in.tum.de>
parents: 78930
diff changeset
   404
26841d3c568c performance tuning for build schedule: explicit schedule generation, without mixing heuristics;
Fabian Huch <huch@in.tum.de>
parents: 78930
diff changeset
   405
    def best_result(state: Build_Process.State): (Heuristic, Time) =
26841d3c568c performance tuning for build schedule: explicit schedule generation, without mixing heuristics;
Fabian Huch <huch@in.tum.de>
parents: 78930
diff changeset
   406
      heuristics.map(heuristic => heuristic -> heuristic.build_duration(state)).minBy(_._2.ms)
26841d3c568c performance tuning for build schedule: explicit schedule generation, without mixing heuristics;
Fabian Huch <huch@in.tum.de>
parents: 78930
diff changeset
   407
26841d3c568c performance tuning for build schedule: explicit schedule generation, without mixing heuristics;
Fabian Huch <huch@in.tum.de>
parents: 78930
diff changeset
   408
    def next(state: Build_Process.State): List[Config] = best_result(state)._1.next(state)
26841d3c568c performance tuning for build schedule: explicit schedule generation, without mixing heuristics;
Fabian Huch <huch@in.tum.de>
parents: 78930
diff changeset
   409
26841d3c568c performance tuning for build schedule: explicit schedule generation, without mixing heuristics;
Fabian Huch <huch@in.tum.de>
parents: 78930
diff changeset
   410
    def build_duration(state: Build_Process.State): Time = best_result(state)._2
26841d3c568c performance tuning for build schedule: explicit schedule generation, without mixing heuristics;
Fabian Huch <huch@in.tum.de>
parents: 78930
diff changeset
   411
  }
26841d3c568c performance tuning for build schedule: explicit schedule generation, without mixing heuristics;
Fabian Huch <huch@in.tum.de>
parents: 78930
diff changeset
   412
78845
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   413
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   414
  /* heuristics */
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   415
79027
d08fb157e300 use proper max threads (limited by available hardware) in heuristics;
Fabian Huch <huch@in.tum.de>
parents: 79026
diff changeset
   416
  abstract class Path_Heuristic(
d08fb157e300 use proper max threads (limited by available hardware) in heuristics;
Fabian Huch <huch@in.tum.de>
parents: 79026
diff changeset
   417
    timing_data: Timing_Data,
d08fb157e300 use proper max threads (limited by available hardware) in heuristics;
Fabian Huch <huch@in.tum.de>
parents: 79026
diff changeset
   418
    sessions_structure: Sessions.Structure,
d08fb157e300 use proper max threads (limited by available hardware) in heuristics;
Fabian Huch <huch@in.tum.de>
parents: 79026
diff changeset
   419
    max_threads_limit: Int
d08fb157e300 use proper max threads (limited by available hardware) in heuristics;
Fabian Huch <huch@in.tum.de>
parents: 79026
diff changeset
   420
  ) extends Heuristic(timing_data, max_threads_limit) {
78929
df323f23dfde performance tuning for timing heuristic: pre-calculate graph operations;
Fabian Huch <huch@in.tum.de>
parents: 78928
diff changeset
   421
    /* pre-computed properties for efficient heuristic */
df323f23dfde performance tuning for timing heuristic: pre-calculate graph operations;
Fabian Huch <huch@in.tum.de>
parents: 78928
diff changeset
   422
df323f23dfde performance tuning for timing heuristic: pre-calculate graph operations;
Fabian Huch <huch@in.tum.de>
parents: 78928
diff changeset
   423
    type Node = String
df323f23dfde performance tuning for timing heuristic: pre-calculate graph operations;
Fabian Huch <huch@in.tum.de>
parents: 78928
diff changeset
   424
df323f23dfde performance tuning for timing heuristic: pre-calculate graph operations;
Fabian Huch <huch@in.tum.de>
parents: 78928
diff changeset
   425
    val build_graph = sessions_structure.build_graph
df323f23dfde performance tuning for timing heuristic: pre-calculate graph operations;
Fabian Huch <huch@in.tum.de>
parents: 78928
diff changeset
   426
    val all_maximals = build_graph.maximals.toSet
df323f23dfde performance tuning for timing heuristic: pre-calculate graph operations;
Fabian Huch <huch@in.tum.de>
parents: 78928
diff changeset
   427
    val maximals_preds =
df323f23dfde performance tuning for timing heuristic: pre-calculate graph operations;
Fabian Huch <huch@in.tum.de>
parents: 78928
diff changeset
   428
      all_maximals.map(node => node -> build_graph.all_preds(List(node)).toSet).toMap
df323f23dfde performance tuning for timing heuristic: pre-calculate graph operations;
Fabian Huch <huch@in.tum.de>
parents: 78928
diff changeset
   429
79028
6bada416ba55 clarified timing data operations: proper estimation (instead of known points);
Fabian Huch <huch@in.tum.de>
parents: 79027
diff changeset
   430
    val best_times = build_graph.keys.map(node => node -> best_time(node)).toMap
78974
Fabian Huch <huch@in.tum.de>
parents: 78973
diff changeset
   431
    val remaining_time_ms = build_graph.node_height(best_times(_).ms)
78929
df323f23dfde performance tuning for timing heuristic: pre-calculate graph operations;
Fabian Huch <huch@in.tum.de>
parents: 78928
diff changeset
   432
78974
Fabian Huch <huch@in.tum.de>
parents: 78973
diff changeset
   433
    def elapsed_times(node: Node): Map[Node, Time] =
Fabian Huch <huch@in.tum.de>
parents: 78973
diff changeset
   434
      build_graph.reachable_length(best_times(_).ms, build_graph.imm_succs, List(node)).map(
Fabian Huch <huch@in.tum.de>
parents: 78973
diff changeset
   435
        (node, ms) => node -> Time.ms(ms))
78929
df323f23dfde performance tuning for timing heuristic: pre-calculate graph operations;
Fabian Huch <huch@in.tum.de>
parents: 78928
diff changeset
   436
78974
Fabian Huch <huch@in.tum.de>
parents: 78973
diff changeset
   437
    def path_times(node: Node): Map[Node, Time] = {
78929
df323f23dfde performance tuning for timing heuristic: pre-calculate graph operations;
Fabian Huch <huch@in.tum.de>
parents: 78928
diff changeset
   438
      val maximals = all_maximals.intersect(build_graph.all_succs(List(node)).toSet)
df323f23dfde performance tuning for timing heuristic: pre-calculate graph operations;
Fabian Huch <huch@in.tum.de>
parents: 78928
diff changeset
   439
      val elapsed_time = elapsed_times(node)
df323f23dfde performance tuning for timing heuristic: pre-calculate graph operations;
Fabian Huch <huch@in.tum.de>
parents: 78928
diff changeset
   440
df323f23dfde performance tuning for timing heuristic: pre-calculate graph operations;
Fabian Huch <huch@in.tum.de>
parents: 78928
diff changeset
   441
      maximals
df323f23dfde performance tuning for timing heuristic: pre-calculate graph operations;
Fabian Huch <huch@in.tum.de>
parents: 78928
diff changeset
   442
        .flatMap(node => maximals_preds(node).map(_ -> elapsed_time(node)))
df323f23dfde performance tuning for timing heuristic: pre-calculate graph operations;
Fabian Huch <huch@in.tum.de>
parents: 78928
diff changeset
   443
        .groupMapReduce(_._1)(_._2)(_ max _)
df323f23dfde performance tuning for timing heuristic: pre-calculate graph operations;
Fabian Huch <huch@in.tum.de>
parents: 78928
diff changeset
   444
    }
df323f23dfde performance tuning for timing heuristic: pre-calculate graph operations;
Fabian Huch <huch@in.tum.de>
parents: 78928
diff changeset
   445
78972
7a39f151e9a7 proper parallel paths for timing heuristic;
Fabian Huch <huch@in.tum.de>
parents: 78971
diff changeset
   446
    def parallel_paths(minimals: Set[Node], pred: Node => Boolean = _ => true): Int = {
7a39f151e9a7 proper parallel paths for timing heuristic;
Fabian Huch <huch@in.tum.de>
parents: 78971
diff changeset
   447
      def start(node: Node): (Node, Time) = node -> best_times(node)
7a39f151e9a7 proper parallel paths for timing heuristic;
Fabian Huch <huch@in.tum.de>
parents: 78971
diff changeset
   448
7a39f151e9a7 proper parallel paths for timing heuristic;
Fabian Huch <huch@in.tum.de>
parents: 78971
diff changeset
   449
      def pass_time(elapsed: Time)(node: Node, time: Time): (Node, Time) =
7a39f151e9a7 proper parallel paths for timing heuristic;
Fabian Huch <huch@in.tum.de>
parents: 78971
diff changeset
   450
        node -> (time - elapsed)
7a39f151e9a7 proper parallel paths for timing heuristic;
Fabian Huch <huch@in.tum.de>
parents: 78971
diff changeset
   451
7a39f151e9a7 proper parallel paths for timing heuristic;
Fabian Huch <huch@in.tum.de>
parents: 78971
diff changeset
   452
      def parallel_paths(running: Map[Node, Time]): (Int, Map[Node, Time]) =
7a39f151e9a7 proper parallel paths for timing heuristic;
Fabian Huch <huch@in.tum.de>
parents: 78971
diff changeset
   453
        if (running.isEmpty) (0, running)
7a39f151e9a7 proper parallel paths for timing heuristic;
Fabian Huch <huch@in.tum.de>
parents: 78971
diff changeset
   454
        else {
7a39f151e9a7 proper parallel paths for timing heuristic;
Fabian Huch <huch@in.tum.de>
parents: 78971
diff changeset
   455
          def get_next(node: Node): List[Node] =
7a39f151e9a7 proper parallel paths for timing heuristic;
Fabian Huch <huch@in.tum.de>
parents: 78971
diff changeset
   456
            build_graph.imm_succs(node).filter(pred).filter(
7a39f151e9a7 proper parallel paths for timing heuristic;
Fabian Huch <huch@in.tum.de>
parents: 78971
diff changeset
   457
              build_graph.imm_preds(_).intersect(running.keySet).isEmpty).toList
7a39f151e9a7 proper parallel paths for timing heuristic;
Fabian Huch <huch@in.tum.de>
parents: 78971
diff changeset
   458
7a39f151e9a7 proper parallel paths for timing heuristic;
Fabian Huch <huch@in.tum.de>
parents: 78971
diff changeset
   459
          val (next, elapsed) = running.minBy(_._2.ms)
7a39f151e9a7 proper parallel paths for timing heuristic;
Fabian Huch <huch@in.tum.de>
parents: 78971
diff changeset
   460
          val (remaining, finished) =
7a39f151e9a7 proper parallel paths for timing heuristic;
Fabian Huch <huch@in.tum.de>
parents: 78971
diff changeset
   461
            running.toList.map(pass_time(elapsed)).partition(_._2 > Time.zero)
7a39f151e9a7 proper parallel paths for timing heuristic;
Fabian Huch <huch@in.tum.de>
parents: 78971
diff changeset
   462
7a39f151e9a7 proper parallel paths for timing heuristic;
Fabian Huch <huch@in.tum.de>
parents: 78971
diff changeset
   463
          val running1 =
7a39f151e9a7 proper parallel paths for timing heuristic;
Fabian Huch <huch@in.tum.de>
parents: 78971
diff changeset
   464
            remaining.map(pass_time(elapsed)).toMap ++
7a39f151e9a7 proper parallel paths for timing heuristic;
Fabian Huch <huch@in.tum.de>
parents: 78971
diff changeset
   465
              finished.map(_._1).flatMap(get_next).map(start)
7a39f151e9a7 proper parallel paths for timing heuristic;
Fabian Huch <huch@in.tum.de>
parents: 78971
diff changeset
   466
          val (res, running2) = parallel_paths(running1)
7a39f151e9a7 proper parallel paths for timing heuristic;
Fabian Huch <huch@in.tum.de>
parents: 78971
diff changeset
   467
          (res max running1.size, running2)
7a39f151e9a7 proper parallel paths for timing heuristic;
Fabian Huch <huch@in.tum.de>
parents: 78971
diff changeset
   468
        }
7a39f151e9a7 proper parallel paths for timing heuristic;
Fabian Huch <huch@in.tum.de>
parents: 78971
diff changeset
   469
7a39f151e9a7 proper parallel paths for timing heuristic;
Fabian Huch <huch@in.tum.de>
parents: 78971
diff changeset
   470
      parallel_paths(minimals.map(start).toMap)._1
7a39f151e9a7 proper parallel paths for timing heuristic;
Fabian Huch <huch@in.tum.de>
parents: 78971
diff changeset
   471
    }
79019
4df053d29215 introduced path heuristic abstraction;
Fabian Huch <huch@in.tum.de>
parents: 78976
diff changeset
   472
  }
78929
df323f23dfde performance tuning for timing heuristic: pre-calculate graph operations;
Fabian Huch <huch@in.tum.de>
parents: 78928
diff changeset
   473
79019
4df053d29215 introduced path heuristic abstraction;
Fabian Huch <huch@in.tum.de>
parents: 78976
diff changeset
   474
  class Timing_Heuristic(
4df053d29215 introduced path heuristic abstraction;
Fabian Huch <huch@in.tum.de>
parents: 78976
diff changeset
   475
    threshold: Time,
4df053d29215 introduced path heuristic abstraction;
Fabian Huch <huch@in.tum.de>
parents: 78976
diff changeset
   476
    timing_data: Timing_Data,
4df053d29215 introduced path heuristic abstraction;
Fabian Huch <huch@in.tum.de>
parents: 78976
diff changeset
   477
    sessions_structure: Sessions.Structure,
79027
d08fb157e300 use proper max threads (limited by available hardware) in heuristics;
Fabian Huch <huch@in.tum.de>
parents: 79026
diff changeset
   478
    max_threads_limit: Int = 8
d08fb157e300 use proper max threads (limited by available hardware) in heuristics;
Fabian Huch <huch@in.tum.de>
parents: 79026
diff changeset
   479
  ) extends Path_Heuristic(timing_data, sessions_structure, max_threads_limit) {
79019
4df053d29215 introduced path heuristic abstraction;
Fabian Huch <huch@in.tum.de>
parents: 78976
diff changeset
   480
    val critical_path_nodes =
4df053d29215 introduced path heuristic abstraction;
Fabian Huch <huch@in.tum.de>
parents: 78976
diff changeset
   481
      build_graph.keys.map(node =>
4df053d29215 introduced path heuristic abstraction;
Fabian Huch <huch@in.tum.de>
parents: 78976
diff changeset
   482
        node -> path_times(node).filter((_, time) => time > threshold).keySet).toMap
78929
df323f23dfde performance tuning for timing heuristic: pre-calculate graph operations;
Fabian Huch <huch@in.tum.de>
parents: 78928
diff changeset
   483
78928
6c2c60b852e0 move timing data into scheduler for more efficient heuristics (e.g., with pre-calculated values);
Fabian Huch <huch@in.tum.de>
parents: 78888
diff changeset
   484
    def next(state: Build_Process.State): List[Config] = {
78845
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   485
      val resources = host_infos.available(state)
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   486
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   487
      def best_threads(task: Build_Process.Task): Int =
79028
6bada416ba55 clarified timing data operations: proper estimation (instead of known points);
Fabian Huch <huch@in.tum.de>
parents: 79027
diff changeset
   488
        timing_data.best_threads(task.name, max_threads)
78971
f930d24f1548 scheduled build: allocate cpus more aggressively, to avoid idle threads;
Fabian Huch <huch@in.tum.de>
parents: 78970
diff changeset
   489
79028
6bada416ba55 clarified timing data operations: proper estimation (instead of known points);
Fabian Huch <huch@in.tum.de>
parents: 79027
diff changeset
   490
      val rev_ordered_hosts = ordered_hosts.reverse.map(_ -> max_threads)
78845
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   491
79021
1c91e884035d properly incorporate running tasks into timing heuristic;
Fabian Huch <huch@in.tum.de>
parents: 79020
diff changeset
   492
      val resources0 = host_infos.available(state.copy(running = Map.empty))
1c91e884035d properly incorporate running tasks into timing heuristic;
Fabian Huch <huch@in.tum.de>
parents: 79020
diff changeset
   493
      val max_parallel = parallel_paths(state.ready.map(_.name).toSet)
1c91e884035d properly incorporate running tasks into timing heuristic;
Fabian Huch <huch@in.tum.de>
parents: 79020
diff changeset
   494
      val fully_parallelizable = max_parallel <= resources0.unused_nodes(max_threads).length
78973
d91e131840a0 timing heuristic: parallelize more aggressively to utilize hosts fully;
Fabian Huch <huch@in.tum.de>
parents: 78972
diff changeset
   495
d91e131840a0 timing heuristic: parallelize more aggressively to utilize hosts fully;
Fabian Huch <huch@in.tum.de>
parents: 78972
diff changeset
   496
      if (fully_parallelizable) {
79020
ef76705bf402 clarified ready vs. next ready;
Fabian Huch <huch@in.tum.de>
parents: 79019
diff changeset
   497
        val all_tasks = state.next_ready.map(task => (task, best_threads(task), best_threads(task)))
79028
6bada416ba55 clarified timing data operations: proper estimation (instead of known points);
Fabian Huch <huch@in.tum.de>
parents: 79027
diff changeset
   498
        resources.try_allocate_tasks(rev_ordered_hosts, all_tasks)._1
78971
f930d24f1548 scheduled build: allocate cpus more aggressively, to avoid idle threads;
Fabian Huch <huch@in.tum.de>
parents: 78970
diff changeset
   499
      }
78845
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   500
      else {
79021
1c91e884035d properly incorporate running tasks into timing heuristic;
Fabian Huch <huch@in.tum.de>
parents: 79020
diff changeset
   501
        val critical_nodes = state.ready.toSet.flatMap(task => critical_path_nodes(task.name))
78845
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   502
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   503
        val (critical, other) =
79020
ef76705bf402 clarified ready vs. next ready;
Fabian Huch <huch@in.tum.de>
parents: 79019
diff changeset
   504
          state.next_ready.sortBy(task => remaining_time_ms(task.name)).reverse.partition(task =>
78974
Fabian Huch <huch@in.tum.de>
parents: 78973
diff changeset
   505
            critical_nodes.contains(task.name))
78845
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   506
78971
f930d24f1548 scheduled build: allocate cpus more aggressively, to avoid idle threads;
Fabian Huch <huch@in.tum.de>
parents: 78970
diff changeset
   507
        val critical_tasks = critical.map(task => (task, best_threads(task), best_threads(task)))
f930d24f1548 scheduled build: allocate cpus more aggressively, to avoid idle threads;
Fabian Huch <huch@in.tum.de>
parents: 78970
diff changeset
   508
        val other_tasks = other.map(task => (task, 1, best_threads(task)))
f930d24f1548 scheduled build: allocate cpus more aggressively, to avoid idle threads;
Fabian Huch <huch@in.tum.de>
parents: 78970
diff changeset
   509
79021
1c91e884035d properly incorporate running tasks into timing heuristic;
Fabian Huch <huch@in.tum.de>
parents: 79020
diff changeset
   510
        val critical_minimals = critical_nodes.intersect(state.ready.map(_.name).toSet)
1c91e884035d properly incorporate running tasks into timing heuristic;
Fabian Huch <huch@in.tum.de>
parents: 79020
diff changeset
   511
        val max_critical_parallel = parallel_paths(critical_minimals, critical_nodes.contains)
79028
6bada416ba55 clarified timing data operations: proper estimation (instead of known points);
Fabian Huch <huch@in.tum.de>
parents: 79027
diff changeset
   512
        val (critical_hosts, other_hosts) = rev_ordered_hosts.splitAt(max_critical_parallel)
78845
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   513
78971
f930d24f1548 scheduled build: allocate cpus more aggressively, to avoid idle threads;
Fabian Huch <huch@in.tum.de>
parents: 78970
diff changeset
   514
        val (configs1, resources1) = resources.try_allocate_tasks(critical_hosts, critical_tasks)
f930d24f1548 scheduled build: allocate cpus more aggressively, to avoid idle threads;
Fabian Huch <huch@in.tum.de>
parents: 78970
diff changeset
   515
        val (configs2, _) = resources1.try_allocate_tasks(other_hosts, other_tasks)
78845
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   516
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   517
        configs1 ::: configs2
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   518
      }
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   519
    }
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   520
  }
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   521
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   522
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   523
  /* process for scheduled build */
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   524
78928
6c2c60b852e0 move timing data into scheduler for more efficient heuristics (e.g., with pre-calculated values);
Fabian Huch <huch@in.tum.de>
parents: 78888
diff changeset
   525
  abstract class Scheduled_Build_Process(
78845
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   526
    build_context: Build.Context,
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   527
    build_progress: Progress,
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   528
    server: SSH.Server,
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   529
  ) extends Build_Process(build_context, build_progress, server) {
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   530
    protected val start_date = Date.now()
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   531
78928
6c2c60b852e0 move timing data into scheduler for more efficient heuristics (e.g., with pre-calculated values);
Fabian Huch <huch@in.tum.de>
parents: 78888
diff changeset
   532
    def init_scheduler(timing_data: Timing_Data): Scheduler
78845
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   533
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   534
    /* global resources with common close() operation */
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   535
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   536
    private final lazy val _log_store: Build_Log.Store = Build_Log.store(build_options)
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   537
    private final lazy val _log_database: SQL.Database =
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   538
      try {
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   539
        val db = _log_store.open_database(server = this.server)
78851
db37cae970a6 more robust init_database();
wenzelm
parents: 78849
diff changeset
   540
        _log_store.init_database(db)
78845
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   541
        db
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   542
      }
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   543
      catch { case exn: Throwable => close(); throw exn }
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   544
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   545
    override def close(): Unit = {
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   546
      super.close()
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   547
      Option(_log_database).foreach(_.close())
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   548
    }
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   549
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   550
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   551
    /* previous results via build log */
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   552
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   553
    override def open_build_cluster(): Build_Cluster = {
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   554
      val build_cluster = super.open_build_cluster()
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   555
      build_cluster.init()
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   556
      if (build_context.master && build_context.max_jobs > 0) {
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   557
        val benchmark_options = build_options.string("build_hostname") = hostname
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   558
        Benchmark.benchmark(benchmark_options, progress)
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   559
      }
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   560
      build_cluster.benchmark()
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   561
      build_cluster
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   562
    }
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   563
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   564
    private val timing_data: Timing_Data = {
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   565
      val cluster_hosts: List[Build_Cluster.Host] =
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   566
        if (build_context.max_jobs == 0) build_context.build_hosts
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   567
        else {
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   568
          val local_build_host =
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   569
            Build_Cluster.Host(
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   570
              hostname, jobs = build_context.max_jobs, numa = build_context.numa_shuffling)
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   571
          local_build_host :: build_context.build_hosts
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   572
        }
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   573
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   574
      val host_infos = Host_Infos(cluster_hosts, _host_database)
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   575
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   576
      val build_history =
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   577
        for {
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   578
          log_name <- _log_database.execute_query_statement(
78849
df162316b6a7 clarified names;
wenzelm
parents: 78846
diff changeset
   579
            Build_Log.private_data.meta_info_table.select(List(Build_Log.private_data.log_name)),
df162316b6a7 clarified names;
wenzelm
parents: 78846
diff changeset
   580
            List.from[String], res => res.string(Build_Log.private_data.log_name))
78845
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   581
          meta_info <- _log_store.read_meta_info(_log_database, log_name)
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   582
          build_info = _log_store.read_build_info(_log_database, log_name)
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   583
        } yield (meta_info, build_info)
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   584
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   585
      Timing_Data.make(host_infos, build_history)
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   586
    }
78928
6c2c60b852e0 move timing data into scheduler for more efficient heuristics (e.g., with pre-calculated values);
Fabian Huch <huch@in.tum.de>
parents: 78888
diff changeset
   587
    private val scheduler = init_scheduler(timing_data)
78845
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   588
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   589
    def write_build_log(results: Build.Results, state: Build_Process.State.Results): Unit = {
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   590
      val sessions =
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   591
        for {
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   592
          (session_name, result) <- state.toList
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   593
          if !result.current
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   594
        } yield {
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   595
          val info = build_context.sessions_structure(session_name)
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   596
          val entry =
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   597
            if (!results.cancelled(session_name)) {
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   598
              val status =
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   599
                if (result.ok) Build_Log.Session_Status.finished
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   600
                else Build_Log.Session_Status.failed
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   601
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   602
              Build_Log.Session_Entry(
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   603
                chapter = info.chapter,
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   604
                groups = info.groups,
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   605
                hostname = Some(result.node_info.hostname),
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   606
                threads = Some(timing_data.host_infos.num_threads(result.node_info)),
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   607
                timing = result.process_result.timing,
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   608
                sources = Some(result.output_shasum.digest.toString),
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   609
                status = Some(status))
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   610
            }
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   611
            else
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   612
              Build_Log.Session_Entry(
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   613
                chapter = info.chapter,
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   614
                groups = info.groups,
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   615
                status = Some(Build_Log.Session_Status.cancelled))
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   616
          session_name -> entry
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   617
        }
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   618
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   619
      val settings =
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   620
        Build_Log.Settings.all_settings.map(_.name).map(name =>
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   621
          name -> Isabelle_System.getenv(name))
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   622
      val props =
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   623
        List(
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   624
          Build_Log.Prop.build_id.name -> build_context.build_uuid,
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   625
          Build_Log.Prop.build_engine.name -> build_context.engine.name,
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   626
          Build_Log.Prop.build_host.name -> hostname,
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   627
          Build_Log.Prop.build_start.name -> Build_Log.print_date(start_date))
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   628
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   629
      val meta_info = Build_Log.Meta_Info(props, settings)
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   630
      val build_info = Build_Log.Build_Info(sessions.toMap)
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   631
      val log_name = Build_Log.log_filename(engine = engine_name, date = start_date)
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   632
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   633
      _log_store.update_sessions(_log_database, log_name.file_name, build_info)
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   634
      _log_store.update_meta_info(_log_database, log_name.file_name, meta_info)
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   635
    }
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   636
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   637
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   638
    /* build process */
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   639
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   640
    case class Cache(state: Build_Process.State, configs: List[Config], estimate: Date) {
78975
4a5d35b35aeb better invalidation for schedule cache (only on relevant changes);
Fabian Huch <huch@in.tum.de>
parents: 78974
diff changeset
   641
      def is_current(state: Build_Process.State): Boolean =
4a5d35b35aeb better invalidation for schedule cache (only on relevant changes);
Fabian Huch <huch@in.tum.de>
parents: 78974
diff changeset
   642
        this.state.pending.nonEmpty && this.state.results == state.results
78845
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   643
      def is_current_estimate(estimate: Date): Boolean =
78975
4a5d35b35aeb better invalidation for schedule cache (only on relevant changes);
Fabian Huch <huch@in.tum.de>
parents: 78974
diff changeset
   644
        Math.abs((this.estimate.time - estimate.time).ms) < Time.minutes(1).ms
78845
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   645
    }
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   646
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   647
    private var cache = Cache(Build_Process.State(), Nil, Date.now())
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   648
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   649
    override def next_node_info(state: Build_Process.State, session_name: String): Node_Info = {
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   650
      val configs =
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   651
        if (cache.is_current(state)) cache.configs
78928
6c2c60b852e0 move timing data into scheduler for more efficient heuristics (e.g., with pre-calculated values);
Fabian Huch <huch@in.tum.de>
parents: 78888
diff changeset
   652
        else scheduler.next(state)
78845
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   653
      configs.find(_.job_name == session_name).get.node_info
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   654
    }
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   655
78969
1b05c2b10c9f finalize current sessions before generating schedule;
Fabian Huch <huch@in.tum.de>
parents: 78968
diff changeset
   656
    def is_current(state: Build_Process.State, session_name: String): Boolean =
1b05c2b10c9f finalize current sessions before generating schedule;
Fabian Huch <huch@in.tum.de>
parents: 78968
diff changeset
   657
      state.ancestor_results(session_name) match {
1b05c2b10c9f finalize current sessions before generating schedule;
Fabian Huch <huch@in.tum.de>
parents: 78968
diff changeset
   658
        case Some(ancestor_results) if ancestor_results.forall(_.current) =>
1b05c2b10c9f finalize current sessions before generating schedule;
Fabian Huch <huch@in.tum.de>
parents: 78968
diff changeset
   659
          val sources_shasum = state.sessions(session_name).sources_shasum
1b05c2b10c9f finalize current sessions before generating schedule;
Fabian Huch <huch@in.tum.de>
parents: 78968
diff changeset
   660
1b05c2b10c9f finalize current sessions before generating schedule;
Fabian Huch <huch@in.tum.de>
parents: 78968
diff changeset
   661
          val input_shasum =
1b05c2b10c9f finalize current sessions before generating schedule;
Fabian Huch <huch@in.tum.de>
parents: 78968
diff changeset
   662
            if (ancestor_results.isEmpty) ML_Process.bootstrap_shasum()
1b05c2b10c9f finalize current sessions before generating schedule;
Fabian Huch <huch@in.tum.de>
parents: 78968
diff changeset
   663
            else SHA1.flat_shasum(ancestor_results.map(_.output_shasum))
1b05c2b10c9f finalize current sessions before generating schedule;
Fabian Huch <huch@in.tum.de>
parents: 78968
diff changeset
   664
1b05c2b10c9f finalize current sessions before generating schedule;
Fabian Huch <huch@in.tum.de>
parents: 78968
diff changeset
   665
          val store_heap =
1b05c2b10c9f finalize current sessions before generating schedule;
Fabian Huch <huch@in.tum.de>
parents: 78968
diff changeset
   666
            build_context.build_heap || Sessions.is_pure(session_name) ||
1b05c2b10c9f finalize current sessions before generating schedule;
Fabian Huch <huch@in.tum.de>
parents: 78968
diff changeset
   667
              state.sessions.iterator.exists(_.ancestors.contains(session_name))
1b05c2b10c9f finalize current sessions before generating schedule;
Fabian Huch <huch@in.tum.de>
parents: 78968
diff changeset
   668
1b05c2b10c9f finalize current sessions before generating schedule;
Fabian Huch <huch@in.tum.de>
parents: 78968
diff changeset
   669
          store.check_output(
1b05c2b10c9f finalize current sessions before generating schedule;
Fabian Huch <huch@in.tum.de>
parents: 78968
diff changeset
   670
            _database_server, session_name,
1b05c2b10c9f finalize current sessions before generating schedule;
Fabian Huch <huch@in.tum.de>
parents: 78968
diff changeset
   671
            session_options = build_context.sessions_structure(session_name).options,
1b05c2b10c9f finalize current sessions before generating schedule;
Fabian Huch <huch@in.tum.de>
parents: 78968
diff changeset
   672
            sources_shasum = sources_shasum,
1b05c2b10c9f finalize current sessions before generating schedule;
Fabian Huch <huch@in.tum.de>
parents: 78968
diff changeset
   673
            input_shasum = input_shasum,
1b05c2b10c9f finalize current sessions before generating schedule;
Fabian Huch <huch@in.tum.de>
parents: 78968
diff changeset
   674
            fresh_build = build_context.fresh_build,
1b05c2b10c9f finalize current sessions before generating schedule;
Fabian Huch <huch@in.tum.de>
parents: 78968
diff changeset
   675
            store_heap = store_heap)._1
1b05c2b10c9f finalize current sessions before generating schedule;
Fabian Huch <huch@in.tum.de>
parents: 78968
diff changeset
   676
        case _ => false
1b05c2b10c9f finalize current sessions before generating schedule;
Fabian Huch <huch@in.tum.de>
parents: 78968
diff changeset
   677
    }
1b05c2b10c9f finalize current sessions before generating schedule;
Fabian Huch <huch@in.tum.de>
parents: 78968
diff changeset
   678
78970
5d38b72a1a66 finalize scheduled build only on master node;
Fabian Huch <huch@in.tum.de>
parents: 78969
diff changeset
   679
    override def next_jobs(state: Build_Process.State): List[String] = {
5d38b72a1a66 finalize scheduled build only on master node;
Fabian Huch <huch@in.tum.de>
parents: 78969
diff changeset
   680
      val finalize_limit = if (build_context.master) Int.MaxValue else 0
5d38b72a1a66 finalize scheduled build only on master node;
Fabian Huch <huch@in.tum.de>
parents: 78969
diff changeset
   681
79020
ef76705bf402 clarified ready vs. next ready;
Fabian Huch <huch@in.tum.de>
parents: 79019
diff changeset
   682
      if (progress.stopped) state.next_ready.map(_.name).take(finalize_limit)
78975
4a5d35b35aeb better invalidation for schedule cache (only on relevant changes);
Fabian Huch <huch@in.tum.de>
parents: 78974
diff changeset
   683
      else if (cache.is_current(state)) cache.configs.map(_.job_name).filterNot(state.is_running)
78845
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   684
      else {
79020
ef76705bf402 clarified ready vs. next ready;
Fabian Huch <huch@in.tum.de>
parents: 79019
diff changeset
   685
        val current = state.next_ready.filter(task => is_current(state, task.name))
78970
5d38b72a1a66 finalize scheduled build only on master node;
Fabian Huch <huch@in.tum.de>
parents: 78969
diff changeset
   686
        if (current.nonEmpty) current.map(_.name).take(finalize_limit)
78969
1b05c2b10c9f finalize current sessions before generating schedule;
Fabian Huch <huch@in.tum.de>
parents: 78968
diff changeset
   687
        else {
1b05c2b10c9f finalize current sessions before generating schedule;
Fabian Huch <huch@in.tum.de>
parents: 78968
diff changeset
   688
          val start = Time.now()
1b05c2b10c9f finalize current sessions before generating schedule;
Fabian Huch <huch@in.tum.de>
parents: 78968
diff changeset
   689
          val next = scheduler.next(state)
1b05c2b10c9f finalize current sessions before generating schedule;
Fabian Huch <huch@in.tum.de>
parents: 78968
diff changeset
   690
          val estimate = Date(Time.now() + scheduler.build_duration(state))
1b05c2b10c9f finalize current sessions before generating schedule;
Fabian Huch <huch@in.tum.de>
parents: 78968
diff changeset
   691
          val elapsed = Time.now() - start
78884
0233d5a5a4ca improved build messages;
Fabian Huch <huch@in.tum.de>
parents: 78851
diff changeset
   692
78976
8da0eedd562c tuned message;
Fabian Huch <huch@in.tum.de>
parents: 78975
diff changeset
   693
          val timing_msg = if (elapsed.is_relevant) " (took " + elapsed.message + ")" else ""
78969
1b05c2b10c9f finalize current sessions before generating schedule;
Fabian Huch <huch@in.tum.de>
parents: 78968
diff changeset
   694
          progress.echo_if(build_context.master && !cache.is_current_estimate(estimate),
1b05c2b10c9f finalize current sessions before generating schedule;
Fabian Huch <huch@in.tum.de>
parents: 78968
diff changeset
   695
            "Estimated completion: " + estimate + timing_msg)
78845
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   696
78969
1b05c2b10c9f finalize current sessions before generating schedule;
Fabian Huch <huch@in.tum.de>
parents: 78968
diff changeset
   697
          val configs = next.filter(_.node_info.hostname == hostname)
1b05c2b10c9f finalize current sessions before generating schedule;
Fabian Huch <huch@in.tum.de>
parents: 78968
diff changeset
   698
          cache = Cache(state, configs, estimate)
1b05c2b10c9f finalize current sessions before generating schedule;
Fabian Huch <huch@in.tum.de>
parents: 78968
diff changeset
   699
          configs.map(_.job_name)
1b05c2b10c9f finalize current sessions before generating schedule;
Fabian Huch <huch@in.tum.de>
parents: 78968
diff changeset
   700
        }
78845
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   701
      }
78970
5d38b72a1a66 finalize scheduled build only on master node;
Fabian Huch <huch@in.tum.de>
parents: 78969
diff changeset
   702
    }
78845
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   703
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   704
    override def run(): Build.Results = {
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   705
      val results = super.run()
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   706
      if (build_context.master) write_build_log(results, snapshot().results)
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   707
      results
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   708
    }
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   709
  }
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   710
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   711
  class Engine extends Build.Engine(engine_name) {
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   712
    override def open_build_process(
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   713
      context: Build.Context,
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   714
      progress: Progress,
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   715
      server: SSH.Server
78928
6c2c60b852e0 move timing data into scheduler for more efficient heuristics (e.g., with pre-calculated values);
Fabian Huch <huch@in.tum.de>
parents: 78888
diff changeset
   716
    ): Build_Process =
6c2c60b852e0 move timing data into scheduler for more efficient heuristics (e.g., with pre-calculated values);
Fabian Huch <huch@in.tum.de>
parents: 78888
diff changeset
   717
      new Scheduled_Build_Process(context, progress, server) {
6c2c60b852e0 move timing data into scheduler for more efficient heuristics (e.g., with pre-calculated values);
Fabian Huch <huch@in.tum.de>
parents: 78888
diff changeset
   718
        def init_scheduler(timing_data: Timing_Data): Scheduler = {
6c2c60b852e0 move timing data into scheduler for more efficient heuristics (e.g., with pre-calculated values);
Fabian Huch <huch@in.tum.de>
parents: 78888
diff changeset
   719
          val heuristics =
78929
df323f23dfde performance tuning for timing heuristic: pre-calculate graph operations;
Fabian Huch <huch@in.tum.de>
parents: 78928
diff changeset
   720
            List(5, 10, 20).map(minutes =>
df323f23dfde performance tuning for timing heuristic: pre-calculate graph operations;
Fabian Huch <huch@in.tum.de>
parents: 78928
diff changeset
   721
              Timing_Heuristic(
df323f23dfde performance tuning for timing heuristic: pre-calculate graph operations;
Fabian Huch <huch@in.tum.de>
parents: 78928
diff changeset
   722
                Time.minutes(minutes),
df323f23dfde performance tuning for timing heuristic: pre-calculate graph operations;
Fabian Huch <huch@in.tum.de>
parents: 78928
diff changeset
   723
                timing_data,
df323f23dfde performance tuning for timing heuristic: pre-calculate graph operations;
Fabian Huch <huch@in.tum.de>
parents: 78928
diff changeset
   724
                context.build_deps.sessions_structure))
78931
26841d3c568c performance tuning for build schedule: explicit schedule generation, without mixing heuristics;
Fabian Huch <huch@in.tum.de>
parents: 78930
diff changeset
   725
          new Meta_Heuristic(heuristics)
78928
6c2c60b852e0 move timing data into scheduler for more efficient heuristics (e.g., with pre-calculated values);
Fabian Huch <huch@in.tum.de>
parents: 78888
diff changeset
   726
        }
6c2c60b852e0 move timing data into scheduler for more efficient heuristics (e.g., with pre-calculated values);
Fabian Huch <huch@in.tum.de>
parents: 78888
diff changeset
   727
      }
78845
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   728
  }
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   729
}