src/Pure/Tools/build_schedule.scala
author Fabian Huch <huch@in.tum.de>
Thu, 23 Nov 2023 19:56:27 +0100
changeset 79025 f78ee2d48bf5
parent 79024 d989e00c3ff5
child 79026 6585acdd6505
permissions -rw-r--r--
handle inflection point in interpolation with monotone prefix;
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
78845
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
    49
    def best_threads(job_name: String): Option[Int] = by_job.get(job_name).map(_.best_entry.threads)
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
    50
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
    51
    def best_time(job_name: String): Time =
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
    52
      by_job.get(job_name).map(_.best_entry.elapsed).getOrElse(
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
    53
        estimate_config(Config(job_name, Node_Info(best_entry.hostname, None, Nil))))
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
    54
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
    55
    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
    56
      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
    57
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
    58
    def approximate_threads(threads: Int): Option[Time] = {
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
    59
      val approximations =
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
    60
        by_job.values.filter(_.size > 1).map { data =>
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
    61
          val (ref_hostname, x0) =
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
    62
            data.by_hostname.toList.flatMap((hostname, data) =>
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
    63
              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
    64
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
    65
          def unify_hosts(data: Timing_Data): List[Time] =
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
    66
            data.by_hostname.toList.map((hostname, data) =>
78888
95bbf9a576b3 prefer Time.scale(), following Isabelle/ML;
wenzelm
parents: 78884
diff changeset
    67
              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
    68
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
    69
          val entries =
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
    70
            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
    71
              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
    72
79024
d989e00c3ff5 proper computation of sorted prefix;
Fabian Huch <huch@in.tum.de>
parents: 79023
diff changeset
    73
          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
    74
            xs match {
d989e00c3ff5 proper computation of sorted prefix;
Fabian Huch <huch@in.tum.de>
parents: 79023
diff changeset
    75
              case x1 :: x2 :: xs =>
d989e00c3ff5 proper computation of sorted prefix;
Fabian Huch <huch@in.tum.de>
parents: 79023
diff changeset
    76
                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
    77
              case xs => xs
d989e00c3ff5 proper computation of sorted prefix;
Fabian Huch <huch@in.tum.de>
parents: 79023
diff changeset
    78
            }
79025
f78ee2d48bf5 handle inflection point in interpolation with monotone prefix;
Fabian Huch <huch@in.tum.de>
parents: 79024
diff changeset
    79
f78ee2d48bf5 handle inflection point in interpolation with monotone prefix;
Fabian Huch <huch@in.tum.de>
parents: 79024
diff changeset
    80
          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
    81
            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
    82
            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
    83
            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
    84
          }
f78ee2d48bf5 handle inflection point in interpolation with monotone prefix;
Fabian Huch <huch@in.tum.de>
parents: 79024
diff changeset
    85
79024
d989e00c3ff5 proper computation of sorted prefix;
Fabian Huch <huch@in.tum.de>
parents: 79023
diff changeset
    86
          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
    87
79025
f78ee2d48bf5 handle inflection point in interpolation with monotone prefix;
Fabian Huch <huch@in.tum.de>
parents: 79024
diff changeset
    88
          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
    89
          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
    90
          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
    91
          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
    92
            // 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
    93
            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
    94
              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
    95
                (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
    96
                (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
    97
                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
    98
              } 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
    99
            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
   100
              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
   101
79025
f78ee2d48bf5 handle inflection point in interpolation with monotone prefix;
Fabian Huch <huch@in.tum.de>
parents: 79024
diff changeset
   102
            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
   103
f78ee2d48bf5 handle inflection point in interpolation with monotone prefix;
Fabian Huch <huch@in.tum.de>
parents: 79024
diff changeset
   104
            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
   105
            else {
f78ee2d48bf5 handle inflection point in interpolation with monotone prefix;
Fabian Huch <huch@in.tum.de>
parents: 79024
diff changeset
   106
              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
   107
              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
   108
f78ee2d48bf5 handle inflection point in interpolation with monotone prefix;
Fabian Huch <huch@in.tum.de>
parents: 79024
diff changeset
   109
              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
   110
              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
   111
            }
79023
abc27a824419 better build time interpolation: model with Amdahl's law where applicable;
Fabian Huch <huch@in.tum.de>
parents: 79022
diff changeset
   112
          } else {
abc27a824419 better build time interpolation: model with Amdahl's law where applicable;
Fabian Huch <huch@in.tum.de>
parents: 79022
diff changeset
   113
            // Piecewise linear
79025
f78ee2d48bf5 handle inflection point in interpolation with monotone prefix;
Fabian Huch <huch@in.tum.de>
parents: 79024
diff changeset
   114
            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
   115
              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
   116
                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
   117
                (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
   118
              } else {
abc27a824419 better build time interpolation: model with Amdahl's law where applicable;
Fabian Huch <huch@in.tum.de>
parents: 79022
diff changeset
   119
                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
   120
                (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
   121
              }
abc27a824419 better build time interpolation: model with Amdahl's law where applicable;
Fabian Huch <huch@in.tum.de>
parents: 79022
diff changeset
   122
79025
f78ee2d48bf5 handle inflection point in interpolation with monotone prefix;
Fabian Huch <huch@in.tum.de>
parents: 79024
diff changeset
   123
            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
   124
          }
78845
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   125
        }
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   126
      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
   127
    }
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   128
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   129
    def threads_factor(divided: Int, divisor: Int): Double =
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   130
      (approximate_threads(divided), approximate_threads(divisor)) match {
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   131
        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
   132
        case _ => divided.toDouble / divisor
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
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   135
    def estimate_config(config: Config): Time =
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   136
      by_job.get(config.job_name) match {
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   137
        case None => mean_time
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   138
        case Some(data) =>
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   139
          val hostname = config.node_info.hostname
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   140
          val threads = host_infos.num_threads(config.node_info)
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   141
          data.by_threads.get(threads) match {
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   142
            case None => // interpolate threads
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   143
              data.by_hostname.get(hostname).flatMap(
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   144
                _.approximate_threads(threads)).getOrElse {
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   145
                  // per machine, try to approximate config for threads
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   146
                  val approximated =
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   147
                    data.by_hostname.toList.flatMap((hostname1, data) =>
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   148
                      data.approximate_threads(threads).map(time =>
78888
95bbf9a576b3 prefer Time.scale(), following Isabelle/ML;
wenzelm
parents: 78884
diff changeset
   149
                        time.scale(hostname_factor(hostname1, hostname))))
78845
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   150
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   151
                  if (approximated.nonEmpty) Timing_Data.mean_time(approximated)
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   152
                  else {
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   153
                    // no machine where config can be approximated
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   154
                    data.approximate_threads(threads).getOrElse {
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   155
                      // 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
   156
                      val global_factor = threads_factor(data.by_threads.keys.head, threads)
78888
95bbf9a576b3 prefer Time.scale(), following Isabelle/ML;
wenzelm
parents: 78884
diff changeset
   157
                      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
   158
                    }
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   159
                  }
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   160
                }
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
            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
   163
              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
   164
                Timing_Data.median_time(
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   165
                  data.by_hostname.toList.map((hostname1, data) =>
78888
95bbf9a576b3 prefer Time.scale(), following Isabelle/ML;
wenzelm
parents: 78884
diff changeset
   166
                    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
   167
              }
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   168
          }
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   169
      }
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
  object Timing_Data {
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   173
    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
   174
    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
   175
78934
5553a86a1091 proper dummy timing entries;
Fabian Huch <huch@in.tum.de>
parents: 78933
diff changeset
   176
    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
   177
      List(
78934
5553a86a1091 proper dummy timing entries;
Fabian Huch <huch@in.tum.de>
parents: 78933
diff changeset
   178
        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
   179
        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
   180
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   181
    def make(
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   182
      host_infos: Host_Infos,
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   183
      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
   184
    ): Timing_Data = {
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   185
      val hosts = host_infos.hosts
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   186
      val measurements =
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   187
        for {
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   188
          (meta_info, build_info) <- build_history
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   189
          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
   190
          (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
   191
          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
   192
          hostname = session_info.hostname.getOrElse(build_host)
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   193
          host <- hosts.find(_.info.hostname == build_host).toList
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   194
          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
   195
        } 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
   196
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   197
      val entries =
78934
5553a86a1091 proper dummy timing entries;
Fabian Huch <huch@in.tum.de>
parents: 78933
diff changeset
   198
        if (measurements.isEmpty) {
5553a86a1091 proper dummy timing entries;
Fabian Huch <huch@in.tum.de>
parents: 78933
diff changeset
   199
          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
   200
          host_infos.hosts.flatMap(host =>
5553a86a1091 proper dummy timing entries;
Fabian Huch <huch@in.tum.de>
parents: 78933
diff changeset
   201
            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
   202
        }
78845
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   203
        else
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   204
          measurements.groupMap(_._1)(_._2).toList.map {
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   205
            case ((job_name, hostname, threads), timings) =>
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   206
              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
   207
          }
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   208
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   209
      new Timing_Data(entries, host_infos)
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
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
  /* host information */
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
  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
   217
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   218
  object Host_Infos {
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   219
    def dummy: Host_Infos =
78846
966aa081929f tuned imports;
wenzelm
parents: 78845
diff changeset
   220
      new Host_Infos(
966aa081929f tuned imports;
wenzelm
parents: 78845
diff changeset
   221
        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
   222
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   223
    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
   224
      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
   225
        val info =
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   226
          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
   227
            error("No benchmark for " + quote(build_host.name)))
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   228
        Host(info, build_host)
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   229
      }
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   230
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   231
      new Host_Infos(build_hosts.map(get_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
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   235
  class Host_Infos private(val hosts: List[Host]) {
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   236
    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
   237
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   238
    def host_factor(from: Host, to: Host): Double =
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   239
      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
   240
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   241
    val host_speeds: Ordering[Host] =
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   242
      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
   243
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   244
    def the_host(hostname: String): Host =
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   245
      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
   246
    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
   247
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   248
    def num_threads(node_info: Node_Info): Int =
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   249
      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
   250
      else the_host(node_info).info.num_cpus
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   251
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   252
    def available(state: Build_Process.State): Resources = {
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   253
      val allocated =
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   254
        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
   255
      Resources(this, allocated)
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   256
    }
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   257
  }
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   258
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
  /* offline tracking of resource allocations */
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
  case class Resources(
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   263
    host_infos: Host_Infos,
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   264
    allocated_nodes: Map[Host, List[Node_Info]]
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   265
  ) {
78973
d91e131840a0 timing heuristic: parallelize more aggressively to utilize hosts fully;
Fabian Huch <huch@in.tum.de>
parents: 78972
diff changeset
   266
    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
   267
      val fully_allocated =
d91e131840a0 timing heuristic: parallelize more aggressively to utilize hosts fully;
Fabian Huch <huch@in.tum.de>
parents: 78972
diff changeset
   268
        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
   269
          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
   270
          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
   271
        }
d91e131840a0 timing heuristic: parallelize more aggressively to utilize hosts fully;
Fabian Huch <huch@in.tum.de>
parents: 78972
diff changeset
   272
      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
   273
      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
   274
    }
78845
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   275
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   276
    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
   277
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   278
    def allocate(node: Node_Info): Resources = {
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   279
      val host = host_infos.the_host(node)
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   280
      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
   281
    }
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   282
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   283
    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
   284
      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
   285
      tasks: List[(Build_Process.Task, Int, Int)],
78845
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   286
    ): (List[Config], Resources) =
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   287
      tasks match {
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   288
        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
   289
        case (task, min_threads, max_threads) :: tasks =>
78845
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   290
          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
   291
            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
   292
              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
   293
                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
   294
                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
   295
                (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
   296
              case None => (None, this)
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   297
            }
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   298
          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
   299
          (configs ++ config, resources1)
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
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   302
    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
   303
      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
   304
      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
   305
        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
   306
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   307
      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
   308
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   309
      val available_nodes = host.info.numa_nodes
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   310
      val numa_node =
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   311
        if (!host.build.numa) None
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   312
        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
   313
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   314
      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
   315
      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
   316
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   317
      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
   318
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   319
      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
   320
    }
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
    def available(host: Host, threads: Int): Boolean = {
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   323
      val used = allocated(host)
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
      if (used.length >= host.build.jobs) false
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   326
      else {
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   327
        if (host.info.numa_nodes.length <= 1)
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   328
          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
   329
        else {
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   330
          def node_threads(n: Int): Int =
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   331
            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
   332
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   333
          host.info.numa_nodes.exists(
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   334
            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
   335
        }
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   336
      }
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   337
    }
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
  /* schedule generation */
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
  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
   344
    def start(config: Config): State =
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   345
      copy(build_state =
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   346
        build_state.copy(running = build_state.running +
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   347
          (config.job_name -> config.job_of(current_time))))
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   348
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   349
    def step(timing_data: Timing_Data): State = {
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   350
      val remaining =
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   351
        build_state.running.values.toList.map { job =>
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   352
          val elapsed = current_time - job.start_date.time
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   353
          val predicted = timing_data.estimate_config(Config.from_job(job))
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   354
          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
   355
          job -> remaining
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   356
        }
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   357
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   358
      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
   359
      else {
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   360
        val (job, elapsed) = remaining.minBy(_._2.ms)
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   361
        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
   362
      }
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   363
    }
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   364
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   365
    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
   366
  }
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   367
78932
Fabian Huch <huch@in.tum.de>
parents: 78931
diff changeset
   368
  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
   369
    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
   370
    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
   371
  }
26841d3c568c performance tuning for build schedule: explicit schedule generation, without mixing heuristics;
Fabian Huch <huch@in.tum.de>
parents: 78930
diff changeset
   372
26841d3c568c performance tuning for build schedule: explicit schedule generation, without mixing heuristics;
Fabian Huch <huch@in.tum.de>
parents: 78930
diff changeset
   373
  abstract class Heuristic(timing_data: Timing_Data) extends Scheduler {
79019
4df053d29215 introduced path heuristic abstraction;
Fabian Huch <huch@in.tum.de>
parents: 78976
diff changeset
   374
    val host_infos = timing_data.host_infos
4df053d29215 introduced path heuristic abstraction;
Fabian Huch <huch@in.tum.de>
parents: 78976
diff changeset
   375
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
   376
    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
   377
      @tailrec
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   378
      def simulate(state: State): State =
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   379
        if (state.finished) state
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   380
        else {
78932
Fabian Huch <huch@in.tum.de>
parents: 78931
diff changeset
   381
          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
   382
          simulate(state1)
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   383
        }
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   384
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   385
      val start = Time.now()
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   386
      simulate(State(build_state, start)).current_time - start
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   387
    }
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   388
  }
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   389
78931
26841d3c568c performance tuning for build schedule: explicit schedule generation, without mixing heuristics;
Fabian Huch <huch@in.tum.de>
parents: 78930
diff changeset
   390
  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
   391
    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
   392
26841d3c568c performance tuning for build schedule: explicit schedule generation, without mixing heuristics;
Fabian Huch <huch@in.tum.de>
parents: 78930
diff changeset
   393
    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
   394
      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
   395
26841d3c568c performance tuning for build schedule: explicit schedule generation, without mixing heuristics;
Fabian Huch <huch@in.tum.de>
parents: 78930
diff changeset
   396
    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
   397
26841d3c568c performance tuning for build schedule: explicit schedule generation, without mixing heuristics;
Fabian Huch <huch@in.tum.de>
parents: 78930
diff changeset
   398
    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
   399
  }
26841d3c568c performance tuning for build schedule: explicit schedule generation, without mixing heuristics;
Fabian Huch <huch@in.tum.de>
parents: 78930
diff changeset
   400
78845
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   401
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   402
  /* heuristics */
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   403
79019
4df053d29215 introduced path heuristic abstraction;
Fabian Huch <huch@in.tum.de>
parents: 78976
diff changeset
   404
  abstract class Path_Heuristic(timing_data: Timing_Data, sessions_structure: Sessions.Structure)
4df053d29215 introduced path heuristic abstraction;
Fabian Huch <huch@in.tum.de>
parents: 78976
diff changeset
   405
    extends Heuristic(timing_data) {
78929
df323f23dfde performance tuning for timing heuristic: pre-calculate graph operations;
Fabian Huch <huch@in.tum.de>
parents: 78928
diff changeset
   406
    /* 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
   407
df323f23dfde performance tuning for timing heuristic: pre-calculate graph operations;
Fabian Huch <huch@in.tum.de>
parents: 78928
diff changeset
   408
    type Node = String
df323f23dfde performance tuning for timing heuristic: pre-calculate graph operations;
Fabian Huch <huch@in.tum.de>
parents: 78928
diff changeset
   409
df323f23dfde performance tuning for timing heuristic: pre-calculate graph operations;
Fabian Huch <huch@in.tum.de>
parents: 78928
diff changeset
   410
    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
   411
    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
   412
    val maximals_preds =
df323f23dfde performance tuning for timing heuristic: pre-calculate graph operations;
Fabian Huch <huch@in.tum.de>
parents: 78928
diff changeset
   413
      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
   414
78972
7a39f151e9a7 proper parallel paths for timing heuristic;
Fabian Huch <huch@in.tum.de>
parents: 78971
diff changeset
   415
    val best_times = build_graph.keys.map(node => node -> timing_data.best_time(node)).toMap
78974
Fabian Huch <huch@in.tum.de>
parents: 78973
diff changeset
   416
    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
   417
78974
Fabian Huch <huch@in.tum.de>
parents: 78973
diff changeset
   418
    def elapsed_times(node: Node): Map[Node, Time] =
Fabian Huch <huch@in.tum.de>
parents: 78973
diff changeset
   419
      build_graph.reachable_length(best_times(_).ms, build_graph.imm_succs, List(node)).map(
Fabian Huch <huch@in.tum.de>
parents: 78973
diff changeset
   420
        (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
   421
78974
Fabian Huch <huch@in.tum.de>
parents: 78973
diff changeset
   422
    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
   423
      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
   424
      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
   425
df323f23dfde performance tuning for timing heuristic: pre-calculate graph operations;
Fabian Huch <huch@in.tum.de>
parents: 78928
diff changeset
   426
      maximals
df323f23dfde performance tuning for timing heuristic: pre-calculate graph operations;
Fabian Huch <huch@in.tum.de>
parents: 78928
diff changeset
   427
        .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
   428
        .groupMapReduce(_._1)(_._2)(_ max _)
df323f23dfde performance tuning for timing heuristic: pre-calculate graph operations;
Fabian Huch <huch@in.tum.de>
parents: 78928
diff changeset
   429
    }
df323f23dfde performance tuning for timing heuristic: pre-calculate graph operations;
Fabian Huch <huch@in.tum.de>
parents: 78928
diff changeset
   430
78972
7a39f151e9a7 proper parallel paths for timing heuristic;
Fabian Huch <huch@in.tum.de>
parents: 78971
diff changeset
   431
    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
   432
      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
   433
7a39f151e9a7 proper parallel paths for timing heuristic;
Fabian Huch <huch@in.tum.de>
parents: 78971
diff changeset
   434
      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
   435
        node -> (time - elapsed)
7a39f151e9a7 proper parallel paths for timing heuristic;
Fabian Huch <huch@in.tum.de>
parents: 78971
diff changeset
   436
7a39f151e9a7 proper parallel paths for timing heuristic;
Fabian Huch <huch@in.tum.de>
parents: 78971
diff changeset
   437
      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
   438
        if (running.isEmpty) (0, running)
7a39f151e9a7 proper parallel paths for timing heuristic;
Fabian Huch <huch@in.tum.de>
parents: 78971
diff changeset
   439
        else {
7a39f151e9a7 proper parallel paths for timing heuristic;
Fabian Huch <huch@in.tum.de>
parents: 78971
diff changeset
   440
          def get_next(node: Node): List[Node] =
7a39f151e9a7 proper parallel paths for timing heuristic;
Fabian Huch <huch@in.tum.de>
parents: 78971
diff changeset
   441
            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
   442
              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
   443
7a39f151e9a7 proper parallel paths for timing heuristic;
Fabian Huch <huch@in.tum.de>
parents: 78971
diff changeset
   444
          val (next, elapsed) = running.minBy(_._2.ms)
7a39f151e9a7 proper parallel paths for timing heuristic;
Fabian Huch <huch@in.tum.de>
parents: 78971
diff changeset
   445
          val (remaining, finished) =
7a39f151e9a7 proper parallel paths for timing heuristic;
Fabian Huch <huch@in.tum.de>
parents: 78971
diff changeset
   446
            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
   447
7a39f151e9a7 proper parallel paths for timing heuristic;
Fabian Huch <huch@in.tum.de>
parents: 78971
diff changeset
   448
          val running1 =
7a39f151e9a7 proper parallel paths for timing heuristic;
Fabian Huch <huch@in.tum.de>
parents: 78971
diff changeset
   449
            remaining.map(pass_time(elapsed)).toMap ++
7a39f151e9a7 proper parallel paths for timing heuristic;
Fabian Huch <huch@in.tum.de>
parents: 78971
diff changeset
   450
              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
   451
          val (res, running2) = parallel_paths(running1)
7a39f151e9a7 proper parallel paths for timing heuristic;
Fabian Huch <huch@in.tum.de>
parents: 78971
diff changeset
   452
          (res max running1.size, running2)
7a39f151e9a7 proper parallel paths for timing heuristic;
Fabian Huch <huch@in.tum.de>
parents: 78971
diff changeset
   453
        }
7a39f151e9a7 proper parallel paths for timing heuristic;
Fabian Huch <huch@in.tum.de>
parents: 78971
diff changeset
   454
7a39f151e9a7 proper parallel paths for timing heuristic;
Fabian Huch <huch@in.tum.de>
parents: 78971
diff changeset
   455
      parallel_paths(minimals.map(start).toMap)._1
7a39f151e9a7 proper parallel paths for timing heuristic;
Fabian Huch <huch@in.tum.de>
parents: 78971
diff changeset
   456
    }
79019
4df053d29215 introduced path heuristic abstraction;
Fabian Huch <huch@in.tum.de>
parents: 78976
diff changeset
   457
  }
78929
df323f23dfde performance tuning for timing heuristic: pre-calculate graph operations;
Fabian Huch <huch@in.tum.de>
parents: 78928
diff changeset
   458
79019
4df053d29215 introduced path heuristic abstraction;
Fabian Huch <huch@in.tum.de>
parents: 78976
diff changeset
   459
  class Timing_Heuristic(
4df053d29215 introduced path heuristic abstraction;
Fabian Huch <huch@in.tum.de>
parents: 78976
diff changeset
   460
    threshold: Time,
4df053d29215 introduced path heuristic abstraction;
Fabian Huch <huch@in.tum.de>
parents: 78976
diff changeset
   461
    timing_data: Timing_Data,
4df053d29215 introduced path heuristic abstraction;
Fabian Huch <huch@in.tum.de>
parents: 78976
diff changeset
   462
    sessions_structure: Sessions.Structure,
4df053d29215 introduced path heuristic abstraction;
Fabian Huch <huch@in.tum.de>
parents: 78976
diff changeset
   463
    max_threads: Int = 8
4df053d29215 introduced path heuristic abstraction;
Fabian Huch <huch@in.tum.de>
parents: 78976
diff changeset
   464
  ) extends Path_Heuristic(timing_data, sessions_structure) {
4df053d29215 introduced path heuristic abstraction;
Fabian Huch <huch@in.tum.de>
parents: 78976
diff changeset
   465
    val critical_path_nodes =
4df053d29215 introduced path heuristic abstraction;
Fabian Huch <huch@in.tum.de>
parents: 78976
diff changeset
   466
      build_graph.keys.map(node =>
4df053d29215 introduced path heuristic abstraction;
Fabian Huch <huch@in.tum.de>
parents: 78976
diff changeset
   467
        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
   468
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
   469
    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
   470
      val resources = host_infos.available(state)
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   471
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   472
      def best_threads(task: Build_Process.Task): Int =
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   473
        timing_data.best_threads(task.name).getOrElse(
78971
f930d24f1548 scheduled build: allocate cpus more aggressively, to avoid idle threads;
Fabian Huch <huch@in.tum.de>
parents: 78970
diff changeset
   474
          host_infos.hosts.map(_.info.num_cpus).max min max_threads)
f930d24f1548 scheduled build: allocate cpus more aggressively, to avoid idle threads;
Fabian Huch <huch@in.tum.de>
parents: 78970
diff changeset
   475
78973
d91e131840a0 timing heuristic: parallelize more aggressively to utilize hosts fully;
Fabian Huch <huch@in.tum.de>
parents: 78972
diff changeset
   476
      val ordered_hosts =
d91e131840a0 timing heuristic: parallelize more aggressively to utilize hosts fully;
Fabian Huch <huch@in.tum.de>
parents: 78972
diff changeset
   477
        host_infos.hosts.sorted(host_infos.host_speeds).reverse.map(_ -> max_threads)
78845
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   478
79021
1c91e884035d properly incorporate running tasks into timing heuristic;
Fabian Huch <huch@in.tum.de>
parents: 79020
diff changeset
   479
      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
   480
      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
   481
      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
   482
d91e131840a0 timing heuristic: parallelize more aggressively to utilize hosts fully;
Fabian Huch <huch@in.tum.de>
parents: 78972
diff changeset
   483
      if (fully_parallelizable) {
79020
ef76705bf402 clarified ready vs. next ready;
Fabian Huch <huch@in.tum.de>
parents: 79019
diff changeset
   484
        val all_tasks = state.next_ready.map(task => (task, best_threads(task), best_threads(task)))
78973
d91e131840a0 timing heuristic: parallelize more aggressively to utilize hosts fully;
Fabian Huch <huch@in.tum.de>
parents: 78972
diff changeset
   485
        resources.try_allocate_tasks(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
   486
      }
78845
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   487
      else {
79021
1c91e884035d properly incorporate running tasks into timing heuristic;
Fabian Huch <huch@in.tum.de>
parents: 79020
diff changeset
   488
        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
   489
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   490
        val (critical, other) =
79020
ef76705bf402 clarified ready vs. next ready;
Fabian Huch <huch@in.tum.de>
parents: 79019
diff changeset
   491
          state.next_ready.sortBy(task => remaining_time_ms(task.name)).reverse.partition(task =>
78974
Fabian Huch <huch@in.tum.de>
parents: 78973
diff changeset
   492
            critical_nodes.contains(task.name))
78845
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   493
78971
f930d24f1548 scheduled build: allocate cpus more aggressively, to avoid idle threads;
Fabian Huch <huch@in.tum.de>
parents: 78970
diff changeset
   494
        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
   495
        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
   496
79021
1c91e884035d properly incorporate running tasks into timing heuristic;
Fabian Huch <huch@in.tum.de>
parents: 79020
diff changeset
   497
        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
   498
        val max_critical_parallel = parallel_paths(critical_minimals, critical_nodes.contains)
1c91e884035d properly incorporate running tasks into timing heuristic;
Fabian Huch <huch@in.tum.de>
parents: 79020
diff changeset
   499
        val (critical_hosts, other_hosts) = ordered_hosts.splitAt(max_critical_parallel)
78845
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   500
78971
f930d24f1548 scheduled build: allocate cpus more aggressively, to avoid idle threads;
Fabian Huch <huch@in.tum.de>
parents: 78970
diff changeset
   501
        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
   502
        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
   503
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   504
        configs1 ::: configs2
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   505
      }
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   506
    }
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   507
  }
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   508
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   509
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   510
  /* process for scheduled build */
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   511
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
   512
  abstract class Scheduled_Build_Process(
78845
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   513
    build_context: Build.Context,
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   514
    build_progress: Progress,
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   515
    server: SSH.Server,
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   516
  ) extends Build_Process(build_context, build_progress, server) {
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   517
    protected val start_date = Date.now()
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   518
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
   519
    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
   520
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   521
    /* global resources with common close() operation */
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
    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
   524
    private final lazy val _log_database: SQL.Database =
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   525
      try {
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   526
        val db = _log_store.open_database(server = this.server)
78851
db37cae970a6 more robust init_database();
wenzelm
parents: 78849
diff changeset
   527
        _log_store.init_database(db)
78845
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   528
        db
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   529
      }
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   530
      catch { case exn: Throwable => close(); throw exn }
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   531
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   532
    override def close(): Unit = {
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   533
      super.close()
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   534
      Option(_log_database).foreach(_.close())
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
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   537
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   538
    /* previous results via build log */
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   539
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   540
    override def open_build_cluster(): Build_Cluster = {
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   541
      val build_cluster = super.open_build_cluster()
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   542
      build_cluster.init()
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   543
      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
   544
        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
   545
        Benchmark.benchmark(benchmark_options, progress)
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   546
      }
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   547
      build_cluster.benchmark()
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   548
      build_cluster
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
    private val timing_data: Timing_Data = {
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   552
      val cluster_hosts: List[Build_Cluster.Host] =
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   553
        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
   554
        else {
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   555
          val local_build_host =
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   556
            Build_Cluster.Host(
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   557
              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
   558
          local_build_host :: build_context.build_hosts
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
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   561
      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
   562
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   563
      val build_history =
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   564
        for {
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   565
          log_name <- _log_database.execute_query_statement(
78849
df162316b6a7 clarified names;
wenzelm
parents: 78846
diff changeset
   566
            Build_Log.private_data.meta_info_table.select(List(Build_Log.private_data.log_name)),
df162316b6a7 clarified names;
wenzelm
parents: 78846
diff changeset
   567
            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
   568
          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
   569
          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
   570
        } yield (meta_info, build_info)
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   571
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   572
      Timing_Data.make(host_infos, build_history)
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   573
    }
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
   574
    private val scheduler = init_scheduler(timing_data)
78845
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
    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
   577
      val sessions =
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   578
        for {
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   579
          (session_name, result) <- state.toList
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   580
          if !result.current
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   581
        } yield {
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   582
          val info = build_context.sessions_structure(session_name)
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   583
          val entry =
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   584
            if (!results.cancelled(session_name)) {
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   585
              val status =
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   586
                if (result.ok) Build_Log.Session_Status.finished
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   587
                else Build_Log.Session_Status.failed
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
              Build_Log.Session_Entry(
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   590
                chapter = info.chapter,
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   591
                groups = info.groups,
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   592
                hostname = Some(result.node_info.hostname),
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   593
                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
   594
                timing = result.process_result.timing,
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   595
                sources = Some(result.output_shasum.digest.toString),
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   596
                status = Some(status))
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   597
            }
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   598
            else
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   599
              Build_Log.Session_Entry(
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   600
                chapter = info.chapter,
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   601
                groups = info.groups,
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   602
                status = Some(Build_Log.Session_Status.cancelled))
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   603
          session_name -> entry
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   604
        }
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   605
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   606
      val settings =
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   607
        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
   608
          name -> Isabelle_System.getenv(name))
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   609
      val props =
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   610
        List(
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   611
          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
   612
          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
   613
          Build_Log.Prop.build_host.name -> hostname,
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   614
          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
   615
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   616
      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
   617
      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
   618
      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
   619
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   620
      _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
   621
      _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
   622
    }
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   623
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   624
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   625
    /* build process */
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   626
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   627
    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
   628
      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
   629
        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
   630
      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
   631
        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
   632
    }
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   633
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   634
    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
   635
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   636
    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
   637
      val configs =
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   638
        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
   639
        else scheduler.next(state)
78845
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   640
      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
   641
    }
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   642
78969
1b05c2b10c9f finalize current sessions before generating schedule;
Fabian Huch <huch@in.tum.de>
parents: 78968
diff changeset
   643
    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
   644
      state.ancestor_results(session_name) match {
1b05c2b10c9f finalize current sessions before generating schedule;
Fabian Huch <huch@in.tum.de>
parents: 78968
diff changeset
   645
        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
   646
          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
   647
1b05c2b10c9f finalize current sessions before generating schedule;
Fabian Huch <huch@in.tum.de>
parents: 78968
diff changeset
   648
          val input_shasum =
1b05c2b10c9f finalize current sessions before generating schedule;
Fabian Huch <huch@in.tum.de>
parents: 78968
diff changeset
   649
            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
   650
            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
   651
1b05c2b10c9f finalize current sessions before generating schedule;
Fabian Huch <huch@in.tum.de>
parents: 78968
diff changeset
   652
          val store_heap =
1b05c2b10c9f finalize current sessions before generating schedule;
Fabian Huch <huch@in.tum.de>
parents: 78968
diff changeset
   653
            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
   654
              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
   655
1b05c2b10c9f finalize current sessions before generating schedule;
Fabian Huch <huch@in.tum.de>
parents: 78968
diff changeset
   656
          store.check_output(
1b05c2b10c9f finalize current sessions before generating schedule;
Fabian Huch <huch@in.tum.de>
parents: 78968
diff changeset
   657
            _database_server, session_name,
1b05c2b10c9f finalize current sessions before generating schedule;
Fabian Huch <huch@in.tum.de>
parents: 78968
diff changeset
   658
            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
   659
            sources_shasum = sources_shasum,
1b05c2b10c9f finalize current sessions before generating schedule;
Fabian Huch <huch@in.tum.de>
parents: 78968
diff changeset
   660
            input_shasum = input_shasum,
1b05c2b10c9f finalize current sessions before generating schedule;
Fabian Huch <huch@in.tum.de>
parents: 78968
diff changeset
   661
            fresh_build = build_context.fresh_build,
1b05c2b10c9f finalize current sessions before generating schedule;
Fabian Huch <huch@in.tum.de>
parents: 78968
diff changeset
   662
            store_heap = store_heap)._1
1b05c2b10c9f finalize current sessions before generating schedule;
Fabian Huch <huch@in.tum.de>
parents: 78968
diff changeset
   663
        case _ => false
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
78970
5d38b72a1a66 finalize scheduled build only on master node;
Fabian Huch <huch@in.tum.de>
parents: 78969
diff changeset
   666
    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
   667
      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
   668
79020
ef76705bf402 clarified ready vs. next ready;
Fabian Huch <huch@in.tum.de>
parents: 79019
diff changeset
   669
      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
   670
      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
   671
      else {
79020
ef76705bf402 clarified ready vs. next ready;
Fabian Huch <huch@in.tum.de>
parents: 79019
diff changeset
   672
        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
   673
        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
   674
        else {
1b05c2b10c9f finalize current sessions before generating schedule;
Fabian Huch <huch@in.tum.de>
parents: 78968
diff changeset
   675
          val start = Time.now()
1b05c2b10c9f finalize current sessions before generating schedule;
Fabian Huch <huch@in.tum.de>
parents: 78968
diff changeset
   676
          val next = scheduler.next(state)
1b05c2b10c9f finalize current sessions before generating schedule;
Fabian Huch <huch@in.tum.de>
parents: 78968
diff changeset
   677
          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
   678
          val elapsed = Time.now() - start
78884
0233d5a5a4ca improved build messages;
Fabian Huch <huch@in.tum.de>
parents: 78851
diff changeset
   679
78976
8da0eedd562c tuned message;
Fabian Huch <huch@in.tum.de>
parents: 78975
diff changeset
   680
          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
   681
          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
   682
            "Estimated completion: " + estimate + timing_msg)
78845
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   683
78969
1b05c2b10c9f finalize current sessions before generating schedule;
Fabian Huch <huch@in.tum.de>
parents: 78968
diff changeset
   684
          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
   685
          cache = Cache(state, configs, estimate)
1b05c2b10c9f finalize current sessions before generating schedule;
Fabian Huch <huch@in.tum.de>
parents: 78968
diff changeset
   686
          configs.map(_.job_name)
1b05c2b10c9f finalize current sessions before generating schedule;
Fabian Huch <huch@in.tum.de>
parents: 78968
diff changeset
   687
        }
78845
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   688
      }
78970
5d38b72a1a66 finalize scheduled build only on master node;
Fabian Huch <huch@in.tum.de>
parents: 78969
diff changeset
   689
    }
78845
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   690
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   691
    override def run(): Build.Results = {
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   692
      val results = super.run()
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   693
      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
   694
      results
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   695
    }
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   696
  }
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   697
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   698
  class Engine extends Build.Engine(engine_name) {
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   699
    override def open_build_process(
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   700
      context: Build.Context,
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   701
      progress: Progress,
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   702
      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
   703
    ): 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
   704
      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
   705
        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
   706
          val heuristics =
78929
df323f23dfde performance tuning for timing heuristic: pre-calculate graph operations;
Fabian Huch <huch@in.tum.de>
parents: 78928
diff changeset
   707
            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
   708
              Timing_Heuristic(
df323f23dfde performance tuning for timing heuristic: pre-calculate graph operations;
Fabian Huch <huch@in.tum.de>
parents: 78928
diff changeset
   709
                Time.minutes(minutes),
df323f23dfde performance tuning for timing heuristic: pre-calculate graph operations;
Fabian Huch <huch@in.tum.de>
parents: 78928
diff changeset
   710
                timing_data,
df323f23dfde performance tuning for timing heuristic: pre-calculate graph operations;
Fabian Huch <huch@in.tum.de>
parents: 78928
diff changeset
   711
                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
   712
          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
   713
        }
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
   714
      }
78845
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   715
  }
ff96d94957cb add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff changeset
   716
}