author | Fabian Huch <huch@in.tum.de> |
Fri, 26 Jan 2024 16:06:48 +0100 | |
changeset 79534 | 1dcc97227442 |
parent 79527 | f1f08ca40d96 |
child 79592 | 7db599be70cc |
permissions | -rw-r--r-- |
79502 | 1 |
/* Title: Pure/Build/build_schedule.scala |
78845
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 | 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 |
79182
6202d0ff36b4
added build schedule command-line wrapper;
Fabian Huch <huch@in.tum.de>
parents:
79181
diff
changeset
|
11 |
import scala.collection.mutable |
78845
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 |
|
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
14 |
object Build_Schedule { |
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
15 |
/* organized historic timing information (extracted from build logs) */ |
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
16 |
|
79085
cf51ccfd3e39
use full timing information in build schedule;
Fabian Huch <huch@in.tum.de>
parents:
79084
diff
changeset
|
17 |
case class Timing_Entry(job_name: String, hostname: String, threads: Int, timing: Timing) { |
cf51ccfd3e39
use full timing information in build schedule;
Fabian Huch <huch@in.tum.de>
parents:
79084
diff
changeset
|
18 |
def elapsed: Time = timing.elapsed |
79087
3620010c410a
use cpu time for approximation;
Fabian Huch <huch@in.tum.de>
parents:
79086
diff
changeset
|
19 |
def proper_cpu: Option[Time] = timing.cpu.proper_ms.map(Time.ms) |
79085
cf51ccfd3e39
use full timing information in build schedule;
Fabian Huch <huch@in.tum.de>
parents:
79084
diff
changeset
|
20 |
} |
79189 | 21 |
|
79035
6beb60b508e6
clarified timing data vs. timing entries: full top-level data view vs. dynamic partial data;
Fabian Huch <huch@in.tum.de>
parents:
79034
diff
changeset
|
22 |
case class Timing_Entries(entries: List[Timing_Entry]) { |
6beb60b508e6
clarified timing data vs. timing entries: full top-level data view vs. dynamic partial data;
Fabian Huch <huch@in.tum.de>
parents:
79034
diff
changeset
|
23 |
require(entries.nonEmpty) |
78845
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
24 |
|
79035
6beb60b508e6
clarified timing data vs. timing entries: full top-level data view vs. dynamic partial data;
Fabian Huch <huch@in.tum.de>
parents:
79034
diff
changeset
|
25 |
def is_empty = entries.isEmpty |
6beb60b508e6
clarified timing data vs. timing entries: full top-level data view vs. dynamic partial data;
Fabian Huch <huch@in.tum.de>
parents:
79034
diff
changeset
|
26 |
def size = entries.length |
78845
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
27 |
|
79035
6beb60b508e6
clarified timing data vs. timing entries: full top-level data view vs. dynamic partial data;
Fabian Huch <huch@in.tum.de>
parents:
79034
diff
changeset
|
28 |
lazy val by_job = entries.groupBy(_.job_name).view.mapValues(Timing_Entries(_)).toMap |
6beb60b508e6
clarified timing data vs. timing entries: full top-level data view vs. dynamic partial data;
Fabian Huch <huch@in.tum.de>
parents:
79034
diff
changeset
|
29 |
lazy val by_threads = entries.groupBy(_.threads).view.mapValues(Timing_Entries(_)).toMap |
6beb60b508e6
clarified timing data vs. timing entries: full top-level data view vs. dynamic partial data;
Fabian Huch <huch@in.tum.de>
parents:
79034
diff
changeset
|
30 |
lazy val by_hostname = entries.groupBy(_.hostname).view.mapValues(Timing_Entries(_)).toMap |
78845
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
31 |
|
79035
6beb60b508e6
clarified timing data vs. timing entries: full top-level data view vs. dynamic partial data;
Fabian Huch <huch@in.tum.de>
parents:
79034
diff
changeset
|
32 |
def mean_time: Time = Timing_Data.mean_time(entries.map(_.elapsed)) |
6beb60b508e6
clarified timing data vs. timing entries: full top-level data view vs. dynamic partial data;
Fabian Huch <huch@in.tum.de>
parents:
79034
diff
changeset
|
33 |
def best_entry: Timing_Entry = entries.minBy(_.elapsed.ms) |
6beb60b508e6
clarified timing data vs. timing entries: full top-level data view vs. dynamic partial data;
Fabian Huch <huch@in.tum.de>
parents:
79034
diff
changeset
|
34 |
} |
78845
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
35 |
|
79189 | 36 |
object Timing_Data { |
37 |
def median_timing(obs: List[Timing]): Timing = obs.sortBy(_.elapsed.ms).apply(obs.length / 2) |
|
38 |
||
39 |
def median_time(obs: List[Time]): Time = obs.sortBy(_.ms).apply(obs.length / 2) |
|
40 |
||
41 |
def mean_time(obs: Iterable[Time]): Time = Time.ms(obs.map(_.ms).sum / obs.size) |
|
42 |
||
43 |
private def dummy_entries(host: Host, host_factor: Double) = { |
|
44 |
val baseline = Time.minutes(5).scale(host_factor) |
|
45 |
val gc = Time.seconds(10).scale(host_factor) |
|
46 |
List( |
|
47 |
Timing_Entry("dummy", host.name, 1, Timing(baseline, baseline, gc)), |
|
48 |
Timing_Entry("dummy", host.name, 8, Timing(baseline.scale(0.2), baseline, gc))) |
|
49 |
} |
|
50 |
||
51 |
def make( |
|
52 |
host_infos: Host_Infos, |
|
53 |
build_history: List[(Build_Log.Meta_Info, Build_Log.Build_Info)], |
|
54 |
): Timing_Data = { |
|
55 |
val hosts = host_infos.hosts |
|
56 |
val measurements = |
|
57 |
for { |
|
58 |
(meta_info, build_info) <- build_history |
|
59 |
build_host = meta_info.get(Build_Log.Prop.build_host) |
|
60 |
(job_name, session_info) <- build_info.sessions.toList |
|
61 |
if build_info.finished_sessions.contains(job_name) |
|
62 |
hostname <- session_info.hostname.orElse(build_host).toList |
|
63 |
host <- hosts.find(_.info.hostname == hostname).toList |
|
64 |
threads = session_info.threads.getOrElse(host.info.num_cpus) |
|
65 |
} yield (job_name, hostname, threads) -> session_info.timing |
|
66 |
||
67 |
val entries = |
|
68 |
if (measurements.isEmpty) { |
|
69 |
val default_host = host_infos.hosts.sorted(host_infos.host_speeds).last |
|
70 |
host_infos.hosts.flatMap(host => |
|
71 |
dummy_entries(host, host_infos.host_factor(default_host, host))) |
|
72 |
} |
|
73 |
else |
|
74 |
measurements.groupMap(_._1)(_._2).toList.map { |
|
75 |
case ((job_name, hostname, threads), timings) => |
|
76 |
Timing_Entry(job_name, hostname, threads, median_timing(timings)) |
|
77 |
} |
|
78 |
||
79 |
new Timing_Data(Timing_Entries(entries), host_infos) |
|
80 |
} |
|
81 |
||
82 |
def load(host_infos: Host_Infos, log_database: SQL.Database): Timing_Data = { |
|
83 |
val build_history = |
|
84 |
for { |
|
85 |
log_name <- log_database.execute_query_statement( |
|
86 |
Build_Log.private_data.meta_info_table.select(List(Build_Log.Column.log_name)), |
|
87 |
List.from[String], res => res.string(Build_Log.Column.log_name)) |
|
88 |
meta_info <- Build_Log.private_data.read_meta_info(log_database, log_name) |
|
89 |
build_info = Build_Log.private_data.read_build_info(log_database, log_name) |
|
90 |
} yield (meta_info, build_info) |
|
91 |
||
92 |
make(host_infos, build_history) |
|
93 |
} |
|
94 |
} |
|
95 |
||
79035
6beb60b508e6
clarified timing data vs. timing entries: full top-level data view vs. dynamic partial data;
Fabian Huch <huch@in.tum.de>
parents:
79034
diff
changeset
|
96 |
class Timing_Data private(data: Timing_Entries, val host_infos: Host_Infos) { |
79025
f78ee2d48bf5
handle inflection point in interpolation with monotone prefix;
Fabian Huch <huch@in.tum.de>
parents:
79024
diff
changeset
|
97 |
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
|
98 |
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
|
99 |
|
79028
6bada416ba55
clarified timing data operations: proper estimation (instead of known points);
Fabian Huch <huch@in.tum.de>
parents:
79027
diff
changeset
|
100 |
def best_threads(job_name: String, max_threads: Int): Int = { |
6bada416ba55
clarified timing data operations: proper estimation (instead of known points);
Fabian Huch <huch@in.tum.de>
parents:
79027
diff
changeset
|
101 |
val worse_threads = |
79035
6beb60b508e6
clarified timing data vs. timing entries: full top-level data view vs. dynamic partial data;
Fabian Huch <huch@in.tum.de>
parents:
79034
diff
changeset
|
102 |
data.by_job.get(job_name).toList.flatMap(_.by_hostname).flatMap { |
79028
6bada416ba55
clarified timing data operations: proper estimation (instead of known points);
Fabian Huch <huch@in.tum.de>
parents:
79027
diff
changeset
|
103 |
case (hostname, data) => |
6bada416ba55
clarified timing data operations: proper estimation (instead of known points);
Fabian Huch <huch@in.tum.de>
parents:
79027
diff
changeset
|
104 |
val best_threads = data.best_entry.threads |
6bada416ba55
clarified timing data operations: proper estimation (instead of known points);
Fabian Huch <huch@in.tum.de>
parents:
79027
diff
changeset
|
105 |
data.by_threads.keys.toList.sorted.find(_ > best_threads).map( |
6bada416ba55
clarified timing data operations: proper estimation (instead of known points);
Fabian Huch <huch@in.tum.de>
parents:
79027
diff
changeset
|
106 |
inflection_point(best_threads, _)) |
6bada416ba55
clarified timing data operations: proper estimation (instead of known points);
Fabian Huch <huch@in.tum.de>
parents:
79027
diff
changeset
|
107 |
} |
6bada416ba55
clarified timing data operations: proper estimation (instead of known points);
Fabian Huch <huch@in.tum.de>
parents:
79027
diff
changeset
|
108 |
(max_threads :: worse_threads).min |
6bada416ba55
clarified timing data operations: proper estimation (instead of known points);
Fabian Huch <huch@in.tum.de>
parents:
79027
diff
changeset
|
109 |
} |
78845
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
110 |
|
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
111 |
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
|
112 |
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
|
113 |
|
79041 | 114 |
private def approximate_threads(entries_unsorted: List[(Int, Time)], threads: Int): Time = { |
115 |
val entries = entries_unsorted.sortBy(_._1) |
|
116 |
||
79036
be42ba4b4672
split actual approximation from data handling;
Fabian Huch <huch@in.tum.de>
parents:
79035
diff
changeset
|
117 |
def sorted_prefix[A](xs: List[A], f: A => Long): List[A] = |
be42ba4b4672
split actual approximation from data handling;
Fabian Huch <huch@in.tum.de>
parents:
79035
diff
changeset
|
118 |
xs match { |
be42ba4b4672
split actual approximation from data handling;
Fabian Huch <huch@in.tum.de>
parents:
79035
diff
changeset
|
119 |
case x1 :: x2 :: xs => |
be42ba4b4672
split actual approximation from data handling;
Fabian Huch <huch@in.tum.de>
parents:
79035
diff
changeset
|
120 |
if (f(x1) <= f(x2)) x1 :: sorted_prefix(x2 :: xs, f) else x1 :: Nil |
be42ba4b4672
split actual approximation from data handling;
Fabian Huch <huch@in.tum.de>
parents:
79035
diff
changeset
|
121 |
case xs => xs |
be42ba4b4672
split actual approximation from data handling;
Fabian Huch <huch@in.tum.de>
parents:
79035
diff
changeset
|
122 |
} |
be42ba4b4672
split actual approximation from data handling;
Fabian Huch <huch@in.tum.de>
parents:
79035
diff
changeset
|
123 |
|
be42ba4b4672
split actual approximation from data handling;
Fabian Huch <huch@in.tum.de>
parents:
79035
diff
changeset
|
124 |
def linear(p0: (Int, Time), p1: (Int, Time)): Time = { |
be42ba4b4672
split actual approximation from data handling;
Fabian Huch <huch@in.tum.de>
parents:
79035
diff
changeset
|
125 |
val a = (p1._2 - p0._2).scale(1.0 / (p1._1 - p0._1)) |
be42ba4b4672
split actual approximation from data handling;
Fabian Huch <huch@in.tum.de>
parents:
79035
diff
changeset
|
126 |
val b = p0._2 - a.scale(p0._1) |
79184 | 127 |
(a.scale(threads) + b) max Time.zero |
79036
be42ba4b4672
split actual approximation from data handling;
Fabian Huch <huch@in.tum.de>
parents:
79035
diff
changeset
|
128 |
} |
be42ba4b4672
split actual approximation from data handling;
Fabian Huch <huch@in.tum.de>
parents:
79035
diff
changeset
|
129 |
|
be42ba4b4672
split actual approximation from data handling;
Fabian Huch <huch@in.tum.de>
parents:
79035
diff
changeset
|
130 |
val mono_prefix = sorted_prefix(entries, e => -e._2.ms) |
be42ba4b4672
split actual approximation from data handling;
Fabian Huch <huch@in.tum.de>
parents:
79035
diff
changeset
|
131 |
|
be42ba4b4672
split actual approximation from data handling;
Fabian Huch <huch@in.tum.de>
parents:
79035
diff
changeset
|
132 |
val is_mono = entries == mono_prefix |
be42ba4b4672
split actual approximation from data handling;
Fabian Huch <huch@in.tum.de>
parents:
79035
diff
changeset
|
133 |
val in_prefix = mono_prefix.length > 1 && threads <= mono_prefix.last._1 |
be42ba4b4672
split actual approximation from data handling;
Fabian Huch <huch@in.tum.de>
parents:
79035
diff
changeset
|
134 |
val in_inflection = |
be42ba4b4672
split actual approximation from data handling;
Fabian Huch <huch@in.tum.de>
parents:
79035
diff
changeset
|
135 |
!is_mono && mono_prefix.length > 1 && threads < entries.drop(mono_prefix.length).head._1 |
be42ba4b4672
split actual approximation from data handling;
Fabian Huch <huch@in.tum.de>
parents:
79035
diff
changeset
|
136 |
if (is_mono || in_prefix || in_inflection) { |
be42ba4b4672
split actual approximation from data handling;
Fabian Huch <huch@in.tum.de>
parents:
79035
diff
changeset
|
137 |
// Model with Amdahl's law |
be42ba4b4672
split actual approximation from data handling;
Fabian Huch <huch@in.tum.de>
parents:
79035
diff
changeset
|
138 |
val t_p = |
be42ba4b4672
split actual approximation from data handling;
Fabian Huch <huch@in.tum.de>
parents:
79035
diff
changeset
|
139 |
Timing_Data.median_time(for { |
be42ba4b4672
split actual approximation from data handling;
Fabian Huch <huch@in.tum.de>
parents:
79035
diff
changeset
|
140 |
(n, t0) <- mono_prefix |
be42ba4b4672
split actual approximation from data handling;
Fabian Huch <huch@in.tum.de>
parents:
79035
diff
changeset
|
141 |
(m, t1) <- mono_prefix |
be42ba4b4672
split actual approximation from data handling;
Fabian Huch <huch@in.tum.de>
parents:
79035
diff
changeset
|
142 |
if m != n |
be42ba4b4672
split actual approximation from data handling;
Fabian Huch <huch@in.tum.de>
parents:
79035
diff
changeset
|
143 |
} yield (t0 - t1).scale(n.toDouble * m / (m - n))) |
be42ba4b4672
split actual approximation from data handling;
Fabian Huch <huch@in.tum.de>
parents:
79035
diff
changeset
|
144 |
val t_c = |
be42ba4b4672
split actual approximation from data handling;
Fabian Huch <huch@in.tum.de>
parents:
79035
diff
changeset
|
145 |
Timing_Data.median_time(for ((n, t) <- mono_prefix) yield t - t_p.scale(1.0 / n)) |
be42ba4b4672
split actual approximation from data handling;
Fabian Huch <huch@in.tum.de>
parents:
79035
diff
changeset
|
146 |
|
79184 | 147 |
def model(threads: Int): Time = (t_c + t_p.scale(1.0 / threads)) max Time.zero |
79036
be42ba4b4672
split actual approximation from data handling;
Fabian Huch <huch@in.tum.de>
parents:
79035
diff
changeset
|
148 |
|
be42ba4b4672
split actual approximation from data handling;
Fabian Huch <huch@in.tum.de>
parents:
79035
diff
changeset
|
149 |
if (is_mono || in_prefix) model(threads) |
be42ba4b4672
split actual approximation from data handling;
Fabian Huch <huch@in.tum.de>
parents:
79035
diff
changeset
|
150 |
else { |
be42ba4b4672
split actual approximation from data handling;
Fabian Huch <huch@in.tum.de>
parents:
79035
diff
changeset
|
151 |
val post_inflection = entries.drop(mono_prefix.length).head |
be42ba4b4672
split actual approximation from data handling;
Fabian Huch <huch@in.tum.de>
parents:
79035
diff
changeset
|
152 |
val inflection_threads = inflection_point(mono_prefix.last._1, post_inflection._1) |
be42ba4b4672
split actual approximation from data handling;
Fabian Huch <huch@in.tum.de>
parents:
79035
diff
changeset
|
153 |
|
be42ba4b4672
split actual approximation from data handling;
Fabian Huch <huch@in.tum.de>
parents:
79035
diff
changeset
|
154 |
if (threads <= inflection_threads) model(threads) |
be42ba4b4672
split actual approximation from data handling;
Fabian Huch <huch@in.tum.de>
parents:
79035
diff
changeset
|
155 |
else linear((inflection_threads, model(inflection_threads)), post_inflection) |
be42ba4b4672
split actual approximation from data handling;
Fabian Huch <huch@in.tum.de>
parents:
79035
diff
changeset
|
156 |
} |
be42ba4b4672
split actual approximation from data handling;
Fabian Huch <huch@in.tum.de>
parents:
79035
diff
changeset
|
157 |
} else { |
be42ba4b4672
split actual approximation from data handling;
Fabian Huch <huch@in.tum.de>
parents:
79035
diff
changeset
|
158 |
// Piecewise linear |
be42ba4b4672
split actual approximation from data handling;
Fabian Huch <huch@in.tum.de>
parents:
79035
diff
changeset
|
159 |
val (p0, p1) = |
79042 | 160 |
if (entries.head._1 < threads && threads < entries.last._1) { |
161 |
val split = entries.partition(_._1 < threads) |
|
79036
be42ba4b4672
split actual approximation from data handling;
Fabian Huch <huch@in.tum.de>
parents:
79035
diff
changeset
|
162 |
(split._1.last, split._2.head) |
be42ba4b4672
split actual approximation from data handling;
Fabian Huch <huch@in.tum.de>
parents:
79035
diff
changeset
|
163 |
} else { |
be42ba4b4672
split actual approximation from data handling;
Fabian Huch <huch@in.tum.de>
parents:
79035
diff
changeset
|
164 |
val piece = if (threads < entries.head._1) entries.take(2) else entries.takeRight(2) |
be42ba4b4672
split actual approximation from data handling;
Fabian Huch <huch@in.tum.de>
parents:
79035
diff
changeset
|
165 |
(piece.head, piece.last) |
be42ba4b4672
split actual approximation from data handling;
Fabian Huch <huch@in.tum.de>
parents:
79035
diff
changeset
|
166 |
} |
be42ba4b4672
split actual approximation from data handling;
Fabian Huch <huch@in.tum.de>
parents:
79035
diff
changeset
|
167 |
|
be42ba4b4672
split actual approximation from data handling;
Fabian Huch <huch@in.tum.de>
parents:
79035
diff
changeset
|
168 |
linear(p0, p1) |
be42ba4b4672
split actual approximation from data handling;
Fabian Huch <huch@in.tum.de>
parents:
79035
diff
changeset
|
169 |
} |
be42ba4b4672
split actual approximation from data handling;
Fabian Huch <huch@in.tum.de>
parents:
79035
diff
changeset
|
170 |
} |
be42ba4b4672
split actual approximation from data handling;
Fabian Huch <huch@in.tum.de>
parents:
79035
diff
changeset
|
171 |
|
79037
1b3a6cc4a2bf
clarified and tuned timing estimation;
Fabian Huch <huch@in.tum.de>
parents:
79036
diff
changeset
|
172 |
private def unify_hosts(job_name: String, on_host: String): List[(Int, Time)] = { |
1b3a6cc4a2bf
clarified and tuned timing estimation;
Fabian Huch <huch@in.tum.de>
parents:
79036
diff
changeset
|
173 |
def unify(hostname: String, data: Timing_Entries) = |
1b3a6cc4a2bf
clarified and tuned timing estimation;
Fabian Huch <huch@in.tum.de>
parents:
79036
diff
changeset
|
174 |
data.mean_time.scale(hostname_factor(hostname, on_host)) |
1b3a6cc4a2bf
clarified and tuned timing estimation;
Fabian Huch <huch@in.tum.de>
parents:
79036
diff
changeset
|
175 |
|
1b3a6cc4a2bf
clarified and tuned timing estimation;
Fabian Huch <huch@in.tum.de>
parents:
79036
diff
changeset
|
176 |
for { |
1b3a6cc4a2bf
clarified and tuned timing estimation;
Fabian Huch <huch@in.tum.de>
parents:
79036
diff
changeset
|
177 |
data <- data.by_job.get(job_name).toList |
1b3a6cc4a2bf
clarified and tuned timing estimation;
Fabian Huch <huch@in.tum.de>
parents:
79036
diff
changeset
|
178 |
(threads, data) <- data.by_threads |
1b3a6cc4a2bf
clarified and tuned timing estimation;
Fabian Huch <huch@in.tum.de>
parents:
79036
diff
changeset
|
179 |
entries = data.by_hostname.toList.map(unify) |
1b3a6cc4a2bf
clarified and tuned timing estimation;
Fabian Huch <huch@in.tum.de>
parents:
79036
diff
changeset
|
180 |
} yield threads -> Timing_Data.median_time(entries) |
1b3a6cc4a2bf
clarified and tuned timing estimation;
Fabian Huch <huch@in.tum.de>
parents:
79036
diff
changeset
|
181 |
} |
1b3a6cc4a2bf
clarified and tuned timing estimation;
Fabian Huch <huch@in.tum.de>
parents:
79036
diff
changeset
|
182 |
|
1b3a6cc4a2bf
clarified and tuned timing estimation;
Fabian Huch <huch@in.tum.de>
parents:
79036
diff
changeset
|
183 |
def estimate_threads(job_name: String, hostname: String, threads: Int): Option[Time] = { |
79087
3620010c410a
use cpu time for approximation;
Fabian Huch <huch@in.tum.de>
parents:
79086
diff
changeset
|
184 |
def try_approximate(data: Timing_Entries): Option[Time] = { |
3620010c410a
use cpu time for approximation;
Fabian Huch <huch@in.tum.de>
parents:
79086
diff
changeset
|
185 |
val entries = |
3620010c410a
use cpu time for approximation;
Fabian Huch <huch@in.tum.de>
parents:
79086
diff
changeset
|
186 |
data.by_threads.toList match { |
3620010c410a
use cpu time for approximation;
Fabian Huch <huch@in.tum.de>
parents:
79086
diff
changeset
|
187 |
case List((i, Timing_Entries(List(entry)))) if i != 1 => |
3620010c410a
use cpu time for approximation;
Fabian Huch <huch@in.tum.de>
parents:
79086
diff
changeset
|
188 |
(i, data.mean_time) :: entry.proper_cpu.map(1 -> _).toList |
3620010c410a
use cpu time for approximation;
Fabian Huch <huch@in.tum.de>
parents:
79086
diff
changeset
|
189 |
case entries => entries.map((threads, data) => threads -> data.mean_time) |
3620010c410a
use cpu time for approximation;
Fabian Huch <huch@in.tum.de>
parents:
79086
diff
changeset
|
190 |
} |
3620010c410a
use cpu time for approximation;
Fabian Huch <huch@in.tum.de>
parents:
79086
diff
changeset
|
191 |
if (entries.size < 2) None else Some(approximate_threads(entries, threads)) |
3620010c410a
use cpu time for approximation;
Fabian Huch <huch@in.tum.de>
parents:
79086
diff
changeset
|
192 |
} |
3620010c410a
use cpu time for approximation;
Fabian Huch <huch@in.tum.de>
parents:
79086
diff
changeset
|
193 |
|
79037
1b3a6cc4a2bf
clarified and tuned timing estimation;
Fabian Huch <huch@in.tum.de>
parents:
79036
diff
changeset
|
194 |
for { |
1b3a6cc4a2bf
clarified and tuned timing estimation;
Fabian Huch <huch@in.tum.de>
parents:
79036
diff
changeset
|
195 |
data <- data.by_job.get(job_name) |
1b3a6cc4a2bf
clarified and tuned timing estimation;
Fabian Huch <huch@in.tum.de>
parents:
79036
diff
changeset
|
196 |
data <- data.by_hostname.get(hostname) |
79087
3620010c410a
use cpu time for approximation;
Fabian Huch <huch@in.tum.de>
parents:
79086
diff
changeset
|
197 |
time <- data.by_threads.get(threads).map(_.mean_time).orElse(try_approximate(data)) |
79037
1b3a6cc4a2bf
clarified and tuned timing estimation;
Fabian Huch <huch@in.tum.de>
parents:
79036
diff
changeset
|
198 |
} yield time |
1b3a6cc4a2bf
clarified and tuned timing estimation;
Fabian Huch <huch@in.tum.de>
parents:
79036
diff
changeset
|
199 |
} |
1b3a6cc4a2bf
clarified and tuned timing estimation;
Fabian Huch <huch@in.tum.de>
parents:
79036
diff
changeset
|
200 |
|
1b3a6cc4a2bf
clarified and tuned timing estimation;
Fabian Huch <huch@in.tum.de>
parents:
79036
diff
changeset
|
201 |
def global_threads_factor(from: Int, to: Int): Double = { |
1b3a6cc4a2bf
clarified and tuned timing estimation;
Fabian Huch <huch@in.tum.de>
parents:
79036
diff
changeset
|
202 |
def median(xs: Iterable[Double]): Double = xs.toList.sorted.apply(xs.size / 2) |
79036
be42ba4b4672
split actual approximation from data handling;
Fabian Huch <huch@in.tum.de>
parents:
79035
diff
changeset
|
203 |
|
79037
1b3a6cc4a2bf
clarified and tuned timing estimation;
Fabian Huch <huch@in.tum.de>
parents:
79036
diff
changeset
|
204 |
val estimates = |
1b3a6cc4a2bf
clarified and tuned timing estimation;
Fabian Huch <huch@in.tum.de>
parents:
79036
diff
changeset
|
205 |
for { |
1b3a6cc4a2bf
clarified and tuned timing estimation;
Fabian Huch <huch@in.tum.de>
parents:
79036
diff
changeset
|
206 |
(hostname, data) <- data.by_hostname |
1b3a6cc4a2bf
clarified and tuned timing estimation;
Fabian Huch <huch@in.tum.de>
parents:
79036
diff
changeset
|
207 |
job_name <- data.by_job.keys |
1b3a6cc4a2bf
clarified and tuned timing estimation;
Fabian Huch <huch@in.tum.de>
parents:
79036
diff
changeset
|
208 |
from_time <- estimate_threads(job_name, hostname, from) |
1b3a6cc4a2bf
clarified and tuned timing estimation;
Fabian Huch <huch@in.tum.de>
parents:
79036
diff
changeset
|
209 |
to_time <- estimate_threads(job_name, hostname, to) |
1b3a6cc4a2bf
clarified and tuned timing estimation;
Fabian Huch <huch@in.tum.de>
parents:
79036
diff
changeset
|
210 |
} yield from_time.ms.toDouble / to_time.ms |
78845
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
211 |
|
79037
1b3a6cc4a2bf
clarified and tuned timing estimation;
Fabian Huch <huch@in.tum.de>
parents:
79036
diff
changeset
|
212 |
if (estimates.nonEmpty) median(estimates) |
1b3a6cc4a2bf
clarified and tuned timing estimation;
Fabian Huch <huch@in.tum.de>
parents:
79036
diff
changeset
|
213 |
else { |
1b3a6cc4a2bf
clarified and tuned timing estimation;
Fabian Huch <huch@in.tum.de>
parents:
79036
diff
changeset
|
214 |
// unify hosts |
1b3a6cc4a2bf
clarified and tuned timing estimation;
Fabian Huch <huch@in.tum.de>
parents:
79036
diff
changeset
|
215 |
val estimates = |
1b3a6cc4a2bf
clarified and tuned timing estimation;
Fabian Huch <huch@in.tum.de>
parents:
79036
diff
changeset
|
216 |
for { |
1b3a6cc4a2bf
clarified and tuned timing estimation;
Fabian Huch <huch@in.tum.de>
parents:
79036
diff
changeset
|
217 |
(job_name, data) <- data.by_job |
1b3a6cc4a2bf
clarified and tuned timing estimation;
Fabian Huch <huch@in.tum.de>
parents:
79036
diff
changeset
|
218 |
hostname = data.by_hostname.keys.head |
1b3a6cc4a2bf
clarified and tuned timing estimation;
Fabian Huch <huch@in.tum.de>
parents:
79036
diff
changeset
|
219 |
entries = unify_hosts(job_name, hostname) |
1b3a6cc4a2bf
clarified and tuned timing estimation;
Fabian Huch <huch@in.tum.de>
parents:
79036
diff
changeset
|
220 |
if entries.length > 1 |
1b3a6cc4a2bf
clarified and tuned timing estimation;
Fabian Huch <huch@in.tum.de>
parents:
79036
diff
changeset
|
221 |
} yield |
1b3a6cc4a2bf
clarified and tuned timing estimation;
Fabian Huch <huch@in.tum.de>
parents:
79036
diff
changeset
|
222 |
approximate_threads(entries, from).ms.toDouble / approximate_threads(entries, to).ms |
78845
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
223 |
|
79037
1b3a6cc4a2bf
clarified and tuned timing estimation;
Fabian Huch <huch@in.tum.de>
parents:
79036
diff
changeset
|
224 |
if (estimates.nonEmpty) median(estimates) |
1b3a6cc4a2bf
clarified and tuned timing estimation;
Fabian Huch <huch@in.tum.de>
parents:
79036
diff
changeset
|
225 |
else from.toDouble / to.toDouble |
1b3a6cc4a2bf
clarified and tuned timing estimation;
Fabian Huch <huch@in.tum.de>
parents:
79036
diff
changeset
|
226 |
} |
78845
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
227 |
} |
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
228 |
|
79178
96e5d12c82fd
performance tuning: cache estimates;
Fabian Huch <huch@in.tum.de>
parents:
79110
diff
changeset
|
229 |
private var cache: Map[(String, String, Int), Time] = Map.empty |
79534
1dcc97227442
add approximation factors in build schedule to estimate build times more conservatively;
Fabian Huch <huch@in.tum.de>
parents:
79527
diff
changeset
|
230 |
|
1dcc97227442
add approximation factors in build schedule to estimate build times more conservatively;
Fabian Huch <huch@in.tum.de>
parents:
79527
diff
changeset
|
231 |
|
1dcc97227442
add approximation factors in build schedule to estimate build times more conservatively;
Fabian Huch <huch@in.tum.de>
parents:
79527
diff
changeset
|
232 |
/* approximation factors -- penalize estimations with less information */ |
1dcc97227442
add approximation factors in build schedule to estimate build times more conservatively;
Fabian Huch <huch@in.tum.de>
parents:
79527
diff
changeset
|
233 |
|
1dcc97227442
add approximation factors in build schedule to estimate build times more conservatively;
Fabian Huch <huch@in.tum.de>
parents:
79527
diff
changeset
|
234 |
val FACTOR_NO_THREADS_GLOBAL_CURVE = 2.5 |
1dcc97227442
add approximation factors in build schedule to estimate build times more conservatively;
Fabian Huch <huch@in.tum.de>
parents:
79527
diff
changeset
|
235 |
val FACTOR_NO_THREADS_UNIFY_MACHINES = 1.7 |
1dcc97227442
add approximation factors in build schedule to estimate build times more conservatively;
Fabian Huch <huch@in.tum.de>
parents:
79527
diff
changeset
|
236 |
val FACTOR_NO_THREADS_OTHER_MACHINE = 1.5 |
1dcc97227442
add approximation factors in build schedule to estimate build times more conservatively;
Fabian Huch <huch@in.tum.de>
parents:
79527
diff
changeset
|
237 |
val FACTOR_NO_THREADS_SAME_MACHINE = 1.4 |
1dcc97227442
add approximation factors in build schedule to estimate build times more conservatively;
Fabian Huch <huch@in.tum.de>
parents:
79527
diff
changeset
|
238 |
val FACTOR_THREADS_OTHER_MACHINE = 1.2 |
1dcc97227442
add approximation factors in build schedule to estimate build times more conservatively;
Fabian Huch <huch@in.tum.de>
parents:
79527
diff
changeset
|
239 |
|
79178
96e5d12c82fd
performance tuning: cache estimates;
Fabian Huch <huch@in.tum.de>
parents:
79110
diff
changeset
|
240 |
def estimate(job_name: String, hostname: String, threads: Int): Time = { |
96e5d12c82fd
performance tuning: cache estimates;
Fabian Huch <huch@in.tum.de>
parents:
79110
diff
changeset
|
241 |
def estimate: Time = |
96e5d12c82fd
performance tuning: cache estimates;
Fabian Huch <huch@in.tum.de>
parents:
79110
diff
changeset
|
242 |
data.by_job.get(job_name) match { |
96e5d12c82fd
performance tuning: cache estimates;
Fabian Huch <huch@in.tum.de>
parents:
79110
diff
changeset
|
243 |
case None => |
96e5d12c82fd
performance tuning: cache estimates;
Fabian Huch <huch@in.tum.de>
parents:
79110
diff
changeset
|
244 |
// no data for job, take average of other jobs for given threads |
96e5d12c82fd
performance tuning: cache estimates;
Fabian Huch <huch@in.tum.de>
parents:
79110
diff
changeset
|
245 |
val job_estimates = data.by_job.keys.flatMap(estimate_threads(_, hostname, threads)) |
96e5d12c82fd
performance tuning: cache estimates;
Fabian Huch <huch@in.tum.de>
parents:
79110
diff
changeset
|
246 |
if (job_estimates.nonEmpty) Timing_Data.mean_time(job_estimates) |
96e5d12c82fd
performance tuning: cache estimates;
Fabian Huch <huch@in.tum.de>
parents:
79110
diff
changeset
|
247 |
else { |
96e5d12c82fd
performance tuning: cache estimates;
Fabian Huch <huch@in.tum.de>
parents:
79110
diff
changeset
|
248 |
// no other job to estimate from, use global curve to approximate any other job |
96e5d12c82fd
performance tuning: cache estimates;
Fabian Huch <huch@in.tum.de>
parents:
79110
diff
changeset
|
249 |
val (threads1, data1) = data.by_threads.head |
96e5d12c82fd
performance tuning: cache estimates;
Fabian Huch <huch@in.tum.de>
parents:
79110
diff
changeset
|
250 |
data1.mean_time.scale(global_threads_factor(threads1, threads)) |
96e5d12c82fd
performance tuning: cache estimates;
Fabian Huch <huch@in.tum.de>
parents:
79110
diff
changeset
|
251 |
} |
79038
cd7c1acc9cf2
better estimation for unknown jobs;
Fabian Huch <huch@in.tum.de>
parents:
79037
diff
changeset
|
252 |
|
79178
96e5d12c82fd
performance tuning: cache estimates;
Fabian Huch <huch@in.tum.de>
parents:
79110
diff
changeset
|
253 |
case Some(data) => |
96e5d12c82fd
performance tuning: cache estimates;
Fabian Huch <huch@in.tum.de>
parents:
79110
diff
changeset
|
254 |
data.by_threads.get(threads) match { |
96e5d12c82fd
performance tuning: cache estimates;
Fabian Huch <huch@in.tum.de>
parents:
79110
diff
changeset
|
255 |
case None => // interpolate threads |
79534
1dcc97227442
add approximation factors in build schedule to estimate build times more conservatively;
Fabian Huch <huch@in.tum.de>
parents:
79527
diff
changeset
|
256 |
estimate_threads(job_name, hostname, threads).map(_.scale( |
1dcc97227442
add approximation factors in build schedule to estimate build times more conservatively;
Fabian Huch <huch@in.tum.de>
parents:
79527
diff
changeset
|
257 |
FACTOR_NO_THREADS_SAME_MACHINE)).getOrElse { |
79178
96e5d12c82fd
performance tuning: cache estimates;
Fabian Huch <huch@in.tum.de>
parents:
79110
diff
changeset
|
258 |
// per machine, try to approximate config for threads |
96e5d12c82fd
performance tuning: cache estimates;
Fabian Huch <huch@in.tum.de>
parents:
79110
diff
changeset
|
259 |
val approximated = |
96e5d12c82fd
performance tuning: cache estimates;
Fabian Huch <huch@in.tum.de>
parents:
79110
diff
changeset
|
260 |
for { |
96e5d12c82fd
performance tuning: cache estimates;
Fabian Huch <huch@in.tum.de>
parents:
79110
diff
changeset
|
261 |
hostname1 <- data.by_hostname.keys |
96e5d12c82fd
performance tuning: cache estimates;
Fabian Huch <huch@in.tum.de>
parents:
79110
diff
changeset
|
262 |
estimate <- estimate_threads(job_name, hostname1, threads) |
96e5d12c82fd
performance tuning: cache estimates;
Fabian Huch <huch@in.tum.de>
parents:
79110
diff
changeset
|
263 |
factor = hostname_factor(hostname1, hostname) |
96e5d12c82fd
performance tuning: cache estimates;
Fabian Huch <huch@in.tum.de>
parents:
79110
diff
changeset
|
264 |
} yield estimate.scale(factor) |
78845
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
265 |
|
79534
1dcc97227442
add approximation factors in build schedule to estimate build times more conservatively;
Fabian Huch <huch@in.tum.de>
parents:
79527
diff
changeset
|
266 |
if (approximated.nonEmpty) |
1dcc97227442
add approximation factors in build schedule to estimate build times more conservatively;
Fabian Huch <huch@in.tum.de>
parents:
79527
diff
changeset
|
267 |
Timing_Data.mean_time(approximated).scale(FACTOR_NO_THREADS_OTHER_MACHINE) |
79178
96e5d12c82fd
performance tuning: cache estimates;
Fabian Huch <huch@in.tum.de>
parents:
79110
diff
changeset
|
268 |
else { |
96e5d12c82fd
performance tuning: cache estimates;
Fabian Huch <huch@in.tum.de>
parents:
79110
diff
changeset
|
269 |
// no single machine where config can be approximated, unify data points |
96e5d12c82fd
performance tuning: cache estimates;
Fabian Huch <huch@in.tum.de>
parents:
79110
diff
changeset
|
270 |
val unified_entries = unify_hosts(job_name, hostname) |
79037
1b3a6cc4a2bf
clarified and tuned timing estimation;
Fabian Huch <huch@in.tum.de>
parents:
79036
diff
changeset
|
271 |
|
79534
1dcc97227442
add approximation factors in build schedule to estimate build times more conservatively;
Fabian Huch <huch@in.tum.de>
parents:
79527
diff
changeset
|
272 |
if (unified_entries.length > 1) |
1dcc97227442
add approximation factors in build schedule to estimate build times more conservatively;
Fabian Huch <huch@in.tum.de>
parents:
79527
diff
changeset
|
273 |
approximate_threads(unified_entries, threads).scale( |
1dcc97227442
add approximation factors in build schedule to estimate build times more conservatively;
Fabian Huch <huch@in.tum.de>
parents:
79527
diff
changeset
|
274 |
FACTOR_NO_THREADS_UNIFY_MACHINES) |
79178
96e5d12c82fd
performance tuning: cache estimates;
Fabian Huch <huch@in.tum.de>
parents:
79110
diff
changeset
|
275 |
else { |
96e5d12c82fd
performance tuning: cache estimates;
Fabian Huch <huch@in.tum.de>
parents:
79110
diff
changeset
|
276 |
// only single data point, use global curve to approximate |
96e5d12c82fd
performance tuning: cache estimates;
Fabian Huch <huch@in.tum.de>
parents:
79110
diff
changeset
|
277 |
val (job_threads, job_time) = unified_entries.head |
79534
1dcc97227442
add approximation factors in build schedule to estimate build times more conservatively;
Fabian Huch <huch@in.tum.de>
parents:
79527
diff
changeset
|
278 |
job_time.scale(global_threads_factor(job_threads, threads)).scale( |
1dcc97227442
add approximation factors in build schedule to estimate build times more conservatively;
Fabian Huch <huch@in.tum.de>
parents:
79527
diff
changeset
|
279 |
FACTOR_NO_THREADS_GLOBAL_CURVE) |
79178
96e5d12c82fd
performance tuning: cache estimates;
Fabian Huch <huch@in.tum.de>
parents:
79110
diff
changeset
|
280 |
} |
78845
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 |
|
79534
1dcc97227442
add approximation factors in build schedule to estimate build times more conservatively;
Fabian Huch <huch@in.tum.de>
parents:
79527
diff
changeset
|
284 |
case Some(data) => // time for job/thread exists, interpolate machine if necessary |
79178
96e5d12c82fd
performance tuning: cache estimates;
Fabian Huch <huch@in.tum.de>
parents:
79110
diff
changeset
|
285 |
data.by_hostname.get(hostname).map(_.mean_time).getOrElse { |
96e5d12c82fd
performance tuning: cache estimates;
Fabian Huch <huch@in.tum.de>
parents:
79110
diff
changeset
|
286 |
Timing_Data.median_time( |
96e5d12c82fd
performance tuning: cache estimates;
Fabian Huch <huch@in.tum.de>
parents:
79110
diff
changeset
|
287 |
data.by_hostname.toList.map((hostname1, data) => |
79534
1dcc97227442
add approximation factors in build schedule to estimate build times more conservatively;
Fabian Huch <huch@in.tum.de>
parents:
79527
diff
changeset
|
288 |
data.mean_time.scale(hostname_factor(hostname1, hostname)))).scale( |
1dcc97227442
add approximation factors in build schedule to estimate build times more conservatively;
Fabian Huch <huch@in.tum.de>
parents:
79527
diff
changeset
|
289 |
FACTOR_THREADS_OTHER_MACHINE) |
79178
96e5d12c82fd
performance tuning: cache estimates;
Fabian Huch <huch@in.tum.de>
parents:
79110
diff
changeset
|
290 |
} |
96e5d12c82fd
performance tuning: cache estimates;
Fabian Huch <huch@in.tum.de>
parents:
79110
diff
changeset
|
291 |
} |
96e5d12c82fd
performance tuning: cache estimates;
Fabian Huch <huch@in.tum.de>
parents:
79110
diff
changeset
|
292 |
} |
96e5d12c82fd
performance tuning: cache estimates;
Fabian Huch <huch@in.tum.de>
parents:
79110
diff
changeset
|
293 |
|
96e5d12c82fd
performance tuning: cache estimates;
Fabian Huch <huch@in.tum.de>
parents:
79110
diff
changeset
|
294 |
cache.get(job_name, hostname, threads) match { |
96e5d12c82fd
performance tuning: cache estimates;
Fabian Huch <huch@in.tum.de>
parents:
79110
diff
changeset
|
295 |
case Some(time) => time |
96e5d12c82fd
performance tuning: cache estimates;
Fabian Huch <huch@in.tum.de>
parents:
79110
diff
changeset
|
296 |
case None => |
96e5d12c82fd
performance tuning: cache estimates;
Fabian Huch <huch@in.tum.de>
parents:
79110
diff
changeset
|
297 |
val time = estimate |
96e5d12c82fd
performance tuning: cache estimates;
Fabian Huch <huch@in.tum.de>
parents:
79110
diff
changeset
|
298 |
cache = cache + ((job_name, hostname, threads) -> time) |
96e5d12c82fd
performance tuning: cache estimates;
Fabian Huch <huch@in.tum.de>
parents:
79110
diff
changeset
|
299 |
time |
78845
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
300 |
} |
79178
96e5d12c82fd
performance tuning: cache estimates;
Fabian Huch <huch@in.tum.de>
parents:
79110
diff
changeset
|
301 |
} |
78845
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
302 |
} |
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
303 |
|
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
304 |
|
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
305 |
/* host information */ |
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
306 |
|
79103
883f61f0beda
clarified build schedule host: more operations;
Fabian Huch <huch@in.tum.de>
parents:
79102
diff
changeset
|
307 |
case class Host(info: isabelle.Host.Info, build: Build_Cluster.Host) { |
883f61f0beda
clarified build schedule host: more operations;
Fabian Huch <huch@in.tum.de>
parents:
79102
diff
changeset
|
308 |
def name: String = info.hostname |
883f61f0beda
clarified build schedule host: more operations;
Fabian Huch <huch@in.tum.de>
parents:
79102
diff
changeset
|
309 |
def num_cpus: Int = info.num_cpus |
883f61f0beda
clarified build schedule host: more operations;
Fabian Huch <huch@in.tum.de>
parents:
79102
diff
changeset
|
310 |
} |
78845
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
311 |
|
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
312 |
object Host_Infos { |
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
313 |
def dummy: Host_Infos = |
78846 | 314 |
new Host_Infos( |
315 |
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
|
316 |
|
79090
20be5b925720
clarified load vs. apply vs. make;
Fabian Huch <huch@in.tum.de>
parents:
79089
diff
changeset
|
317 |
def load(build_hosts: List[Build_Cluster.Host], db: SQL.Database): Host_Infos = { |
78845
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
318 |
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
|
319 |
val info = |
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
320 |
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
|
321 |
error("No benchmark for " + quote(build_host.name))) |
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
322 |
Host(info, build_host) |
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
323 |
} |
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
324 |
|
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
325 |
new Host_Infos(build_hosts.map(get_host)) |
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
326 |
} |
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
327 |
} |
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
328 |
|
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
329 |
class Host_Infos private(val hosts: List[Host]) { |
79040 | 330 |
require(hosts.nonEmpty) |
331 |
||
79103
883f61f0beda
clarified build schedule host: more operations;
Fabian Huch <huch@in.tum.de>
parents:
79102
diff
changeset
|
332 |
private val by_hostname = hosts.map(host => host.name -> host).toMap |
78845
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
333 |
|
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
334 |
def host_factor(from: Host, to: Host): Double = |
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
335 |
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
|
336 |
|
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
337 |
val host_speeds: Ordering[Host] = |
79084 | 338 |
Ordering.fromLessThan((host1, host2) => host_factor(host1, host2) < 1) |
78845
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 |
def the_host(hostname: String): Host = |
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
341 |
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
|
342 |
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
|
343 |
|
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
344 |
def num_threads(node_info: Node_Info): Int = |
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
345 |
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
|
346 |
else the_host(node_info).info.num_cpus |
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
347 |
|
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
348 |
def available(state: Build_Process.State): Resources = { |
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
349 |
val allocated = |
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
350 |
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
|
351 |
Resources(this, allocated) |
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
352 |
} |
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
353 |
} |
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
354 |
|
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
355 |
|
79029 | 356 |
/* offline tracking of job configurations and resource allocations */ |
357 |
||
358 |
case class Config(job_name: String, node_info: Node_Info) { |
|
359 |
def job_of(start_time: Time): Build_Process.Job = |
|
360 |
Build_Process.Job(job_name, "", "", node_info, Date(start_time), None) |
|
361 |
} |
|
78845
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 |
case class Resources( |
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
364 |
host_infos: Host_Infos, |
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
365 |
allocated_nodes: Map[Host, List[Node_Info]] |
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
366 |
) { |
79106 | 367 |
def unused_nodes(host: Host, threads: Int): List[Node_Info] = |
368 |
if (!available(host, threads)) Nil |
|
369 |
else { |
|
370 |
val node = next_node(host, threads) |
|
371 |
node :: allocate(node).unused_nodes(host, threads) |
|
372 |
} |
|
373 |
||
374 |
def unused_nodes(threads: Int): List[Node_Info] = |
|
375 |
host_infos.hosts.flatMap(unused_nodes(_, threads)) |
|
78845
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
376 |
|
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
377 |
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
|
378 |
|
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
379 |
def allocate(node: Node_Info): Resources = { |
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
380 |
val host = host_infos.the_host(node) |
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
381 |
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
|
382 |
} |
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 |
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
|
385 |
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
|
386 |
tasks: List[(Build_Process.Task, Int, Int)], |
78845
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
387 |
): (List[Config], Resources) = |
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
388 |
tasks match { |
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
389 |
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
|
390 |
case (task, min_threads, max_threads) :: tasks => |
78845
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
391 |
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
|
392 |
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
|
393 |
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
|
394 |
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
|
395 |
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
|
396 |
(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
|
397 |
case None => (None, this) |
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
398 |
} |
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
399 |
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
|
400 |
(configs ++ config, resources1) |
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 |
|
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
403 |
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
|
404 |
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
|
405 |
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
|
406 |
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
|
407 |
|
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
408 |
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
|
409 |
|
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
410 |
val available_nodes = host.info.numa_nodes |
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
411 |
val numa_node = |
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
412 |
if (!host.build.numa) None |
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
413 |
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
|
414 |
|
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
415 |
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
|
416 |
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
|
417 |
|
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
418 |
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
|
419 |
|
79103
883f61f0beda
clarified build schedule host: more operations;
Fabian Huch <huch@in.tum.de>
parents:
79102
diff
changeset
|
420 |
Node_Info(host.name, numa_node, rel_cpus) |
78845
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
421 |
} |
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
422 |
|
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
423 |
def available(host: Host, threads: Int): Boolean = { |
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
424 |
val used = allocated(host) |
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
425 |
|
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
426 |
if (used.length >= host.build.jobs) false |
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
427 |
else { |
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
428 |
if (host.info.numa_nodes.length <= 1) |
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
429 |
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
|
430 |
else { |
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
431 |
def node_threads(n: Int): Int = |
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
432 |
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
|
433 |
|
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
434 |
host.info.numa_nodes.exists( |
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
435 |
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
|
436 |
} |
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
437 |
} |
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
438 |
} |
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
439 |
} |
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
440 |
|
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
441 |
|
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
442 |
/* schedule generation */ |
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
443 |
|
79073
b3fee0dafd72
generated build schedule explicitly (e.g., for further analysis);
Fabian Huch <huch@in.tum.de>
parents:
79064
diff
changeset
|
444 |
object Schedule { |
b3fee0dafd72
generated build schedule explicitly (e.g., for further analysis);
Fabian Huch <huch@in.tum.de>
parents:
79064
diff
changeset
|
445 |
case class Node(job_name: String, node_info: Node_Info, start: Date, duration: Time) { |
b3fee0dafd72
generated build schedule explicitly (e.g., for further analysis);
Fabian Huch <huch@in.tum.de>
parents:
79064
diff
changeset
|
446 |
def end: Date = Date(start.time + duration) |
b3fee0dafd72
generated build schedule explicitly (e.g., for further analysis);
Fabian Huch <huch@in.tum.de>
parents:
79064
diff
changeset
|
447 |
} |
b3fee0dafd72
generated build schedule explicitly (e.g., for further analysis);
Fabian Huch <huch@in.tum.de>
parents:
79064
diff
changeset
|
448 |
|
b3fee0dafd72
generated build schedule explicitly (e.g., for further analysis);
Fabian Huch <huch@in.tum.de>
parents:
79064
diff
changeset
|
449 |
type Graph = isabelle.Graph[String, Node] |
79183
32d00ec387f4
use schedule directly instead of extra cache;
Fabian Huch <huch@in.tum.de>
parents:
79182
diff
changeset
|
450 |
|
79185 | 451 |
def init(build_uuid: String): Schedule = Schedule(build_uuid, "none", Date.now(), Graph.empty) |
79073
b3fee0dafd72
generated build schedule explicitly (e.g., for further analysis);
Fabian Huch <huch@in.tum.de>
parents:
79064
diff
changeset
|
452 |
} |
b3fee0dafd72
generated build schedule explicitly (e.g., for further analysis);
Fabian Huch <huch@in.tum.de>
parents:
79064
diff
changeset
|
453 |
|
79190
2039f3609884
add serial for build schedule to avoid unnecessary db read/writes;
Fabian Huch <huch@in.tum.de>
parents:
79189
diff
changeset
|
454 |
case class Schedule( |
2039f3609884
add serial for build schedule to avoid unnecessary db read/writes;
Fabian Huch <huch@in.tum.de>
parents:
79189
diff
changeset
|
455 |
build_uuid: String, |
2039f3609884
add serial for build schedule to avoid unnecessary db read/writes;
Fabian Huch <huch@in.tum.de>
parents:
79189
diff
changeset
|
456 |
generator: String, |
2039f3609884
add serial for build schedule to avoid unnecessary db read/writes;
Fabian Huch <huch@in.tum.de>
parents:
79189
diff
changeset
|
457 |
start: Date, |
2039f3609884
add serial for build schedule to avoid unnecessary db read/writes;
Fabian Huch <huch@in.tum.de>
parents:
79189
diff
changeset
|
458 |
graph: Schedule.Graph, |
2039f3609884
add serial for build schedule to avoid unnecessary db read/writes;
Fabian Huch <huch@in.tum.de>
parents:
79189
diff
changeset
|
459 |
serial: Long = 0, |
2039f3609884
add serial for build schedule to avoid unnecessary db read/writes;
Fabian Huch <huch@in.tum.de>
parents:
79189
diff
changeset
|
460 |
) { |
2039f3609884
add serial for build schedule to avoid unnecessary db read/writes;
Fabian Huch <huch@in.tum.de>
parents:
79189
diff
changeset
|
461 |
require(serial >= 0, "serial underflow") |
2039f3609884
add serial for build schedule to avoid unnecessary db read/writes;
Fabian Huch <huch@in.tum.de>
parents:
79189
diff
changeset
|
462 |
def inc_serial: Schedule = { |
2039f3609884
add serial for build schedule to avoid unnecessary db read/writes;
Fabian Huch <huch@in.tum.de>
parents:
79189
diff
changeset
|
463 |
require(serial < Long.MaxValue, "serial overflow") |
2039f3609884
add serial for build schedule to avoid unnecessary db read/writes;
Fabian Huch <huch@in.tum.de>
parents:
79189
diff
changeset
|
464 |
copy(serial = serial + 1) |
2039f3609884
add serial for build schedule to avoid unnecessary db read/writes;
Fabian Huch <huch@in.tum.de>
parents:
79189
diff
changeset
|
465 |
} |
2039f3609884
add serial for build schedule to avoid unnecessary db read/writes;
Fabian Huch <huch@in.tum.de>
parents:
79189
diff
changeset
|
466 |
|
79073
b3fee0dafd72
generated build schedule explicitly (e.g., for further analysis);
Fabian Huch <huch@in.tum.de>
parents:
79064
diff
changeset
|
467 |
def end: Date = |
b3fee0dafd72
generated build schedule explicitly (e.g., for further analysis);
Fabian Huch <huch@in.tum.de>
parents:
79064
diff
changeset
|
468 |
if (graph.is_empty) start |
b3fee0dafd72
generated build schedule explicitly (e.g., for further analysis);
Fabian Huch <huch@in.tum.de>
parents:
79064
diff
changeset
|
469 |
else graph.maximals.map(graph.get_node).map(_.end).maxBy(_.unix_epoch) |
b3fee0dafd72
generated build schedule explicitly (e.g., for further analysis);
Fabian Huch <huch@in.tum.de>
parents:
79064
diff
changeset
|
470 |
|
b3fee0dafd72
generated build schedule explicitly (e.g., for further analysis);
Fabian Huch <huch@in.tum.de>
parents:
79064
diff
changeset
|
471 |
def duration: Time = end.time - start.time |
79109
c1255d9870f6
clarified heuristics toString;
Fabian Huch <huch@in.tum.de>
parents:
79108
diff
changeset
|
472 |
def message: String = "Estimated " + duration.message_hms + " build time with " + generator |
79183
32d00ec387f4
use schedule directly instead of extra cache;
Fabian Huch <huch@in.tum.de>
parents:
79182
diff
changeset
|
473 |
|
79192
5db03f9276e2
clarified: build schedules may be outdated when empty, after some time, or due to build progress;
Fabian Huch <huch@in.tum.de>
parents:
79191
diff
changeset
|
474 |
def deviation(other: Schedule): Time = Time.ms((end.time - other.end.time).ms.abs) |
5db03f9276e2
clarified: build schedules may be outdated when empty, after some time, or due to build progress;
Fabian Huch <huch@in.tum.de>
parents:
79191
diff
changeset
|
475 |
|
5db03f9276e2
clarified: build schedules may be outdated when empty, after some time, or due to build progress;
Fabian Huch <huch@in.tum.de>
parents:
79191
diff
changeset
|
476 |
def num_built(state: Build_Process.State): Int = graph.keys.count(state.results.contains) |
5db03f9276e2
clarified: build schedules may be outdated when empty, after some time, or due to build progress;
Fabian Huch <huch@in.tum.de>
parents:
79191
diff
changeset
|
477 |
def elapsed(): Time = Time.now() - start.time |
79293 | 478 |
def is_empty: Boolean = graph.is_empty |
79289
7c1faa16554b
add delay and limit options for when schedule is considered outdated;
Fabian Huch <huch@in.tum.de>
parents:
79288
diff
changeset
|
479 |
def is_outdated(options: Options, state: Build_Process.State): Boolean = |
79293 | 480 |
if (is_empty) true |
79289
7c1faa16554b
add delay and limit options for when schedule is considered outdated;
Fabian Huch <huch@in.tum.de>
parents:
79288
diff
changeset
|
481 |
else { |
7c1faa16554b
add delay and limit options for when schedule is considered outdated;
Fabian Huch <huch@in.tum.de>
parents:
79288
diff
changeset
|
482 |
num_built(state) > options.int("build_schedule_outdated_limit") && |
7c1faa16554b
add delay and limit options for when schedule is considered outdated;
Fabian Huch <huch@in.tum.de>
parents:
79288
diff
changeset
|
483 |
elapsed() > options.seconds("build_schedule_outdated_delay") |
7c1faa16554b
add delay and limit options for when schedule is considered outdated;
Fabian Huch <huch@in.tum.de>
parents:
79288
diff
changeset
|
484 |
} |
79183
32d00ec387f4
use schedule directly instead of extra cache;
Fabian Huch <huch@in.tum.de>
parents:
79182
diff
changeset
|
485 |
|
32d00ec387f4
use schedule directly instead of extra cache;
Fabian Huch <huch@in.tum.de>
parents:
79182
diff
changeset
|
486 |
def next(hostname: String, state: Build_Process.State): List[String] = |
32d00ec387f4
use schedule directly instead of extra cache;
Fabian Huch <huch@in.tum.de>
parents:
79182
diff
changeset
|
487 |
for { |
32d00ec387f4
use schedule directly instead of extra cache;
Fabian Huch <huch@in.tum.de>
parents:
79182
diff
changeset
|
488 |
task <- state.next_ready |
32d00ec387f4
use schedule directly instead of extra cache;
Fabian Huch <huch@in.tum.de>
parents:
79182
diff
changeset
|
489 |
node = graph.get_node(task.name) |
32d00ec387f4
use schedule directly instead of extra cache;
Fabian Huch <huch@in.tum.de>
parents:
79182
diff
changeset
|
490 |
if hostname == node.node_info.hostname |
79191
ee405c40db72
store previous build jobs in graph so schedules can be used later in the build process;
Fabian Huch <huch@in.tum.de>
parents:
79190
diff
changeset
|
491 |
if graph.imm_preds(node.job_name).subsetOf(state.results.keySet) |
79183
32d00ec387f4
use schedule directly instead of extra cache;
Fabian Huch <huch@in.tum.de>
parents:
79182
diff
changeset
|
492 |
} yield task.name |
79193
d1d6dbab2901
compare previous build schedule with new one, to prevent regressions;
Fabian Huch <huch@in.tum.de>
parents:
79192
diff
changeset
|
493 |
|
d1d6dbab2901
compare previous build schedule with new one, to prevent regressions;
Fabian Huch <huch@in.tum.de>
parents:
79192
diff
changeset
|
494 |
def update(state: Build_Process.State): Schedule = { |
d1d6dbab2901
compare previous build schedule with new one, to prevent regressions;
Fabian Huch <huch@in.tum.de>
parents:
79192
diff
changeset
|
495 |
val start1 = Date.now() |
d1d6dbab2901
compare previous build schedule with new one, to prevent regressions;
Fabian Huch <huch@in.tum.de>
parents:
79192
diff
changeset
|
496 |
val pending = state.pending.map(_.name).toSet |
d1d6dbab2901
compare previous build schedule with new one, to prevent regressions;
Fabian Huch <huch@in.tum.de>
parents:
79192
diff
changeset
|
497 |
|
d1d6dbab2901
compare previous build schedule with new one, to prevent regressions;
Fabian Huch <huch@in.tum.de>
parents:
79192
diff
changeset
|
498 |
def shift_elapsed(graph: Schedule.Graph, name: String): Schedule.Graph = |
d1d6dbab2901
compare previous build schedule with new one, to prevent regressions;
Fabian Huch <huch@in.tum.de>
parents:
79192
diff
changeset
|
499 |
graph.map_node(name, { node => |
d1d6dbab2901
compare previous build schedule with new one, to prevent regressions;
Fabian Huch <huch@in.tum.de>
parents:
79192
diff
changeset
|
500 |
val elapsed = start1.time - state.running(name).start_date.time |
d1d6dbab2901
compare previous build schedule with new one, to prevent regressions;
Fabian Huch <huch@in.tum.de>
parents:
79192
diff
changeset
|
501 |
node.copy(duration = node.duration - elapsed) |
d1d6dbab2901
compare previous build schedule with new one, to prevent regressions;
Fabian Huch <huch@in.tum.de>
parents:
79192
diff
changeset
|
502 |
}) |
d1d6dbab2901
compare previous build schedule with new one, to prevent regressions;
Fabian Huch <huch@in.tum.de>
parents:
79192
diff
changeset
|
503 |
|
d1d6dbab2901
compare previous build schedule with new one, to prevent regressions;
Fabian Huch <huch@in.tum.de>
parents:
79192
diff
changeset
|
504 |
def shift_starts(graph: Schedule.Graph, name: String): Schedule.Graph = |
d1d6dbab2901
compare previous build schedule with new one, to prevent regressions;
Fabian Huch <huch@in.tum.de>
parents:
79192
diff
changeset
|
505 |
graph.map_node(name, { node => |
d1d6dbab2901
compare previous build schedule with new one, to prevent regressions;
Fabian Huch <huch@in.tum.de>
parents:
79192
diff
changeset
|
506 |
val starts = start1 :: graph.imm_preds(node.job_name).toList.map(graph.get_node(_).end) |
d1d6dbab2901
compare previous build schedule with new one, to prevent regressions;
Fabian Huch <huch@in.tum.de>
parents:
79192
diff
changeset
|
507 |
node.copy(start = starts.max(Date.Ordering)) |
d1d6dbab2901
compare previous build schedule with new one, to prevent regressions;
Fabian Huch <huch@in.tum.de>
parents:
79192
diff
changeset
|
508 |
}) |
d1d6dbab2901
compare previous build schedule with new one, to prevent regressions;
Fabian Huch <huch@in.tum.de>
parents:
79192
diff
changeset
|
509 |
|
d1d6dbab2901
compare previous build schedule with new one, to prevent regressions;
Fabian Huch <huch@in.tum.de>
parents:
79192
diff
changeset
|
510 |
val graph0 = state.running.keys.foldLeft(graph.restrict(pending.contains))(shift_elapsed) |
d1d6dbab2901
compare previous build schedule with new one, to prevent regressions;
Fabian Huch <huch@in.tum.de>
parents:
79192
diff
changeset
|
511 |
val graph1 = graph0.topological_order.foldLeft(graph0)(shift_starts) |
d1d6dbab2901
compare previous build schedule with new one, to prevent regressions;
Fabian Huch <huch@in.tum.de>
parents:
79192
diff
changeset
|
512 |
|
d1d6dbab2901
compare previous build schedule with new one, to prevent regressions;
Fabian Huch <huch@in.tum.de>
parents:
79192
diff
changeset
|
513 |
copy(start = start1, graph = graph1) |
d1d6dbab2901
compare previous build schedule with new one, to prevent regressions;
Fabian Huch <huch@in.tum.de>
parents:
79192
diff
changeset
|
514 |
} |
79073
b3fee0dafd72
generated build schedule explicitly (e.g., for further analysis);
Fabian Huch <huch@in.tum.de>
parents:
79064
diff
changeset
|
515 |
} |
b3fee0dafd72
generated build schedule explicitly (e.g., for further analysis);
Fabian Huch <huch@in.tum.de>
parents:
79064
diff
changeset
|
516 |
|
b3fee0dafd72
generated build schedule explicitly (e.g., for further analysis);
Fabian Huch <huch@in.tum.de>
parents:
79064
diff
changeset
|
517 |
case class State(build_state: Build_Process.State, current_time: Time, finished: Schedule) { |
78845
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
518 |
def start(config: Config): State = |
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
519 |
copy(build_state = |
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
520 |
build_state.copy(running = build_state.running + |
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
521 |
(config.job_name -> config.job_of(current_time)))) |
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 |
def step(timing_data: Timing_Data): State = { |
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
524 |
val remaining = |
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
525 |
build_state.running.values.toList.map { job => |
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
526 |
val elapsed = current_time - job.start_date.time |
79026
6585acdd6505
clarified time estimation: does not use config;
Fabian Huch <huch@in.tum.de>
parents:
79025
diff
changeset
|
527 |
val threads = timing_data.host_infos.num_threads(job.node_info) |
6585acdd6505
clarified time estimation: does not use config;
Fabian Huch <huch@in.tum.de>
parents:
79025
diff
changeset
|
528 |
val predicted = timing_data.estimate(job.name, job.node_info.hostname, threads) |
78845
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
529 |
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
|
530 |
job -> remaining |
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 |
|
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
533 |
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
|
534 |
else { |
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
535 |
val (job, elapsed) = remaining.minBy(_._2.ms) |
79073
b3fee0dafd72
generated build schedule explicitly (e.g., for further analysis);
Fabian Huch <huch@in.tum.de>
parents:
79064
diff
changeset
|
536 |
val now = current_time + elapsed |
b3fee0dafd72
generated build schedule explicitly (e.g., for further analysis);
Fabian Huch <huch@in.tum.de>
parents:
79064
diff
changeset
|
537 |
val node = Schedule.Node(job.name, job.node_info, job.start_date, now - job.start_date.time) |
b3fee0dafd72
generated build schedule explicitly (e.g., for further analysis);
Fabian Huch <huch@in.tum.de>
parents:
79064
diff
changeset
|
538 |
|
79191
ee405c40db72
store previous build jobs in graph so schedules can be used later in the build process;
Fabian Huch <huch@in.tum.de>
parents:
79190
diff
changeset
|
539 |
val host_preds = |
ee405c40db72
store previous build jobs in graph so schedules can be used later in the build process;
Fabian Huch <huch@in.tum.de>
parents:
79190
diff
changeset
|
540 |
for { |
79236
6dc4fd89987f
filter predecessors properly (amending ee405c40db72);
Fabian Huch <huch@in.tum.de>
parents:
79235
diff
changeset
|
541 |
(name, (pred_node, _)) <- finished.graph.iterator.toSet |
6dc4fd89987f
filter predecessors properly (amending ee405c40db72);
Fabian Huch <huch@in.tum.de>
parents:
79235
diff
changeset
|
542 |
if pred_node.node_info.hostname == job.node_info.hostname |
6dc4fd89987f
filter predecessors properly (amending ee405c40db72);
Fabian Huch <huch@in.tum.de>
parents:
79235
diff
changeset
|
543 |
if pred_node.end.time <= node.start.time |
79191
ee405c40db72
store previous build jobs in graph so schedules can be used later in the build process;
Fabian Huch <huch@in.tum.de>
parents:
79190
diff
changeset
|
544 |
} yield name |
ee405c40db72
store previous build jobs in graph so schedules can be used later in the build process;
Fabian Huch <huch@in.tum.de>
parents:
79190
diff
changeset
|
545 |
val build_preds = |
79073
b3fee0dafd72
generated build schedule explicitly (e.g., for further analysis);
Fabian Huch <huch@in.tum.de>
parents:
79064
diff
changeset
|
546 |
build_state.sessions.graph.imm_preds(job.name).filter(finished.graph.defined) |
79191
ee405c40db72
store previous build jobs in graph so schedules can be used later in the build process;
Fabian Huch <huch@in.tum.de>
parents:
79190
diff
changeset
|
547 |
val preds = build_preds ++ host_preds |
ee405c40db72
store previous build jobs in graph so schedules can be used later in the build process;
Fabian Huch <huch@in.tum.de>
parents:
79190
diff
changeset
|
548 |
|
ee405c40db72
store previous build jobs in graph so schedules can be used later in the build process;
Fabian Huch <huch@in.tum.de>
parents:
79190
diff
changeset
|
549 |
val graph = preds.foldLeft(finished.graph.new_node(job.name, node))(_.add_edge(_, job.name)) |
79073
b3fee0dafd72
generated build schedule explicitly (e.g., for further analysis);
Fabian Huch <huch@in.tum.de>
parents:
79064
diff
changeset
|
550 |
|
b3fee0dafd72
generated build schedule explicitly (e.g., for further analysis);
Fabian Huch <huch@in.tum.de>
parents:
79064
diff
changeset
|
551 |
val build_state1 = build_state.remove_running(job.name).remove_pending(job.name) |
b3fee0dafd72
generated build schedule explicitly (e.g., for further analysis);
Fabian Huch <huch@in.tum.de>
parents:
79064
diff
changeset
|
552 |
State(build_state1, now, finished.copy(graph = graph)) |
78845
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
553 |
} |
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
554 |
} |
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
555 |
|
79073
b3fee0dafd72
generated build schedule explicitly (e.g., for further analysis);
Fabian Huch <huch@in.tum.de>
parents:
79064
diff
changeset
|
556 |
def is_finished: Boolean = build_state.pending.isEmpty && build_state.running.isEmpty |
78845
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
557 |
} |
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
558 |
|
79188 | 559 |
trait Scheduler { def build_schedule(build_state: Build_Process.State): Schedule } |
78931
26841d3c568c
performance tuning for build schedule: explicit schedule generation, without mixing heuristics;
Fabian Huch <huch@in.tum.de>
parents:
78930
diff
changeset
|
560 |
|
79185 | 561 |
abstract class Heuristic(timing_data: Timing_Data, build_uuid: String) |
562 |
extends Scheduler { |
|
79019
4df053d29215
introduced path heuristic abstraction;
Fabian Huch <huch@in.tum.de>
parents:
78976
diff
changeset
|
563 |
val host_infos = timing_data.host_infos |
79028
6bada416ba55
clarified timing data operations: proper estimation (instead of known points);
Fabian Huch <huch@in.tum.de>
parents:
79027
diff
changeset
|
564 |
val ordered_hosts = host_infos.hosts.sorted(host_infos.host_speeds) |
6bada416ba55
clarified timing data operations: proper estimation (instead of known points);
Fabian Huch <huch@in.tum.de>
parents:
79027
diff
changeset
|
565 |
|
79188 | 566 |
def next(state: Build_Process.State): List[Config] |
567 |
||
79073
b3fee0dafd72
generated build schedule explicitly (e.g., for further analysis);
Fabian Huch <huch@in.tum.de>
parents:
79064
diff
changeset
|
568 |
def build_schedule(build_state: Build_Process.State): Schedule = { |
78845
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
569 |
@tailrec |
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
570 |
def simulate(state: State): State = |
79073
b3fee0dafd72
generated build schedule explicitly (e.g., for further analysis);
Fabian Huch <huch@in.tum.de>
parents:
79064
diff
changeset
|
571 |
if (state.is_finished) state |
78845
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
572 |
else { |
78932 | 573 |
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
|
574 |
simulate(state1) |
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 |
|
79073
b3fee0dafd72
generated build schedule explicitly (e.g., for further analysis);
Fabian Huch <huch@in.tum.de>
parents:
79064
diff
changeset
|
577 |
val start = Date.now() |
79109
c1255d9870f6
clarified heuristics toString;
Fabian Huch <huch@in.tum.de>
parents:
79108
diff
changeset
|
578 |
val end_state = |
79185 | 579 |
simulate(State(build_state, start.time, Schedule(build_uuid, toString, start, Graph.empty))) |
79073
b3fee0dafd72
generated build schedule explicitly (e.g., for further analysis);
Fabian Huch <huch@in.tum.de>
parents:
79064
diff
changeset
|
580 |
|
b3fee0dafd72
generated build schedule explicitly (e.g., for further analysis);
Fabian Huch <huch@in.tum.de>
parents:
79064
diff
changeset
|
581 |
end_state.finished |
78845
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
582 |
} |
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
583 |
} |
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
584 |
|
79185 | 585 |
class Default_Heuristic(timing_data: Timing_Data, options: Options, build_uuid: String) |
586 |
extends Heuristic(timing_data, build_uuid) { |
|
79109
c1255d9870f6
clarified heuristics toString;
Fabian Huch <huch@in.tum.de>
parents:
79108
diff
changeset
|
587 |
override def toString: String = "default build heuristic" |
79107
f5a2f956b531
add heuristic for non-scheduled (standard) build behaviour;
Fabian Huch <huch@in.tum.de>
parents:
79106
diff
changeset
|
588 |
|
f5a2f956b531
add heuristic for non-scheduled (standard) build behaviour;
Fabian Huch <huch@in.tum.de>
parents:
79106
diff
changeset
|
589 |
def host_threads(host: Host): Int = { |
f5a2f956b531
add heuristic for non-scheduled (standard) build behaviour;
Fabian Huch <huch@in.tum.de>
parents:
79106
diff
changeset
|
590 |
val m = (options ++ host.build.options).int("threads") |
f5a2f956b531
add heuristic for non-scheduled (standard) build behaviour;
Fabian Huch <huch@in.tum.de>
parents:
79106
diff
changeset
|
591 |
if (m > 0) m else (host.num_cpus max 1) min 8 |
f5a2f956b531
add heuristic for non-scheduled (standard) build behaviour;
Fabian Huch <huch@in.tum.de>
parents:
79106
diff
changeset
|
592 |
} |
79185 | 593 |
|
79107
f5a2f956b531
add heuristic for non-scheduled (standard) build behaviour;
Fabian Huch <huch@in.tum.de>
parents:
79106
diff
changeset
|
594 |
def next_jobs(resources: Resources, sorted_jobs: List[String], host: Host): List[Config] = |
f5a2f956b531
add heuristic for non-scheduled (standard) build behaviour;
Fabian Huch <huch@in.tum.de>
parents:
79106
diff
changeset
|
595 |
sorted_jobs.zip(resources.unused_nodes(host, host_threads(host))).map(Config(_, _)) |
f5a2f956b531
add heuristic for non-scheduled (standard) build behaviour;
Fabian Huch <huch@in.tum.de>
parents:
79106
diff
changeset
|
596 |
|
f5a2f956b531
add heuristic for non-scheduled (standard) build behaviour;
Fabian Huch <huch@in.tum.de>
parents:
79106
diff
changeset
|
597 |
def next(state: Build_Process.State): List[Config] = { |
f5a2f956b531
add heuristic for non-scheduled (standard) build behaviour;
Fabian Huch <huch@in.tum.de>
parents:
79106
diff
changeset
|
598 |
val sorted_jobs = state.next_ready.sortBy(_.name)(state.sessions.ordering).map(_.name) |
f5a2f956b531
add heuristic for non-scheduled (standard) build behaviour;
Fabian Huch <huch@in.tum.de>
parents:
79106
diff
changeset
|
599 |
val resources = host_infos.available(state) |
f5a2f956b531
add heuristic for non-scheduled (standard) build behaviour;
Fabian Huch <huch@in.tum.de>
parents:
79106
diff
changeset
|
600 |
|
f5a2f956b531
add heuristic for non-scheduled (standard) build behaviour;
Fabian Huch <huch@in.tum.de>
parents:
79106
diff
changeset
|
601 |
host_infos.hosts.foldLeft((sorted_jobs, List.empty[Config])) { |
f5a2f956b531
add heuristic for non-scheduled (standard) build behaviour;
Fabian Huch <huch@in.tum.de>
parents:
79106
diff
changeset
|
602 |
case ((jobs, res), host) => |
f5a2f956b531
add heuristic for non-scheduled (standard) build behaviour;
Fabian Huch <huch@in.tum.de>
parents:
79106
diff
changeset
|
603 |
val configs = next_jobs(resources, jobs, host) |
f5a2f956b531
add heuristic for non-scheduled (standard) build behaviour;
Fabian Huch <huch@in.tum.de>
parents:
79106
diff
changeset
|
604 |
val config_jobs = configs.map(_.job_name).toSet |
f5a2f956b531
add heuristic for non-scheduled (standard) build behaviour;
Fabian Huch <huch@in.tum.de>
parents:
79106
diff
changeset
|
605 |
(jobs.filterNot(config_jobs.contains), configs ::: res) |
f5a2f956b531
add heuristic for non-scheduled (standard) build behaviour;
Fabian Huch <huch@in.tum.de>
parents:
79106
diff
changeset
|
606 |
}._2 |
f5a2f956b531
add heuristic for non-scheduled (standard) build behaviour;
Fabian Huch <huch@in.tum.de>
parents:
79106
diff
changeset
|
607 |
} |
f5a2f956b531
add heuristic for non-scheduled (standard) build behaviour;
Fabian Huch <huch@in.tum.de>
parents:
79106
diff
changeset
|
608 |
} |
f5a2f956b531
add heuristic for non-scheduled (standard) build behaviour;
Fabian Huch <huch@in.tum.de>
parents:
79106
diff
changeset
|
609 |
|
78931
26841d3c568c
performance tuning for build schedule: explicit schedule generation, without mixing heuristics;
Fabian Huch <huch@in.tum.de>
parents:
78930
diff
changeset
|
610 |
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
|
611 |
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
|
612 |
|
79073
b3fee0dafd72
generated build schedule explicitly (e.g., for further analysis);
Fabian Huch <huch@in.tum.de>
parents:
79064
diff
changeset
|
613 |
def best_result(state: Build_Process.State): (Heuristic, Schedule) = |
b3fee0dafd72
generated build schedule explicitly (e.g., for further analysis);
Fabian Huch <huch@in.tum.de>
parents:
79064
diff
changeset
|
614 |
heuristics.map(heuristic => |
b3fee0dafd72
generated build schedule explicitly (e.g., for further analysis);
Fabian Huch <huch@in.tum.de>
parents:
79064
diff
changeset
|
615 |
heuristic -> heuristic.build_schedule(state)).minBy(_._2.duration.ms) |
78931
26841d3c568c
performance tuning for build schedule: explicit schedule generation, without mixing heuristics;
Fabian Huch <huch@in.tum.de>
parents:
78930
diff
changeset
|
616 |
|
26841d3c568c
performance tuning for build schedule: explicit schedule generation, without mixing heuristics;
Fabian Huch <huch@in.tum.de>
parents:
78930
diff
changeset
|
617 |
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
|
618 |
|
79073
b3fee0dafd72
generated build schedule explicitly (e.g., for further analysis);
Fabian Huch <huch@in.tum.de>
parents:
79064
diff
changeset
|
619 |
def build_schedule(state: Build_Process.State): Schedule = best_result(state)._2 |
78931
26841d3c568c
performance tuning for build schedule: explicit schedule generation, without mixing heuristics;
Fabian Huch <huch@in.tum.de>
parents:
78930
diff
changeset
|
620 |
} |
26841d3c568c
performance tuning for build schedule: explicit schedule generation, without mixing heuristics;
Fabian Huch <huch@in.tum.de>
parents:
78930
diff
changeset
|
621 |
|
78845
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 |
/* heuristics */ |
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
624 |
|
79027
d08fb157e300
use proper max threads (limited by available hardware) in heuristics;
Fabian Huch <huch@in.tum.de>
parents:
79026
diff
changeset
|
625 |
abstract class Path_Heuristic( |
d08fb157e300
use proper max threads (limited by available hardware) in heuristics;
Fabian Huch <huch@in.tum.de>
parents:
79026
diff
changeset
|
626 |
timing_data: Timing_Data, |
d08fb157e300
use proper max threads (limited by available hardware) in heuristics;
Fabian Huch <huch@in.tum.de>
parents:
79026
diff
changeset
|
627 |
sessions_structure: Sessions.Structure, |
79185 | 628 |
max_threads_limit: Int, |
629 |
build_uuid: String |
|
630 |
) extends Heuristic(timing_data, build_uuid) { |
|
78929
df323f23dfde
performance tuning for timing heuristic: pre-calculate graph operations;
Fabian Huch <huch@in.tum.de>
parents:
78928
diff
changeset
|
631 |
/* 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
|
632 |
|
79102 | 633 |
val max_threads = host_infos.hosts.map(_.info.num_cpus).max min max_threads_limit |
634 |
||
78929
df323f23dfde
performance tuning for timing heuristic: pre-calculate graph operations;
Fabian Huch <huch@in.tum.de>
parents:
78928
diff
changeset
|
635 |
type Node = String |
df323f23dfde
performance tuning for timing heuristic: pre-calculate graph operations;
Fabian Huch <huch@in.tum.de>
parents:
78928
diff
changeset
|
636 |
val build_graph = sessions_structure.build_graph |
79101
4e47b34fbb8e
clarified graph operations in timing heuristic;
Fabian Huch <huch@in.tum.de>
parents:
79091
diff
changeset
|
637 |
|
4e47b34fbb8e
clarified graph operations in timing heuristic;
Fabian Huch <huch@in.tum.de>
parents:
79091
diff
changeset
|
638 |
val minimals = build_graph.minimals |
4e47b34fbb8e
clarified graph operations in timing heuristic;
Fabian Huch <huch@in.tum.de>
parents:
79091
diff
changeset
|
639 |
val maximals = build_graph.maximals |
4e47b34fbb8e
clarified graph operations in timing heuristic;
Fabian Huch <huch@in.tum.de>
parents:
79091
diff
changeset
|
640 |
|
4e47b34fbb8e
clarified graph operations in timing heuristic;
Fabian Huch <huch@in.tum.de>
parents:
79091
diff
changeset
|
641 |
def all_preds(node: Node): Set[Node] = build_graph.all_preds(List(node)).toSet |
4e47b34fbb8e
clarified graph operations in timing heuristic;
Fabian Huch <huch@in.tum.de>
parents:
79091
diff
changeset
|
642 |
val maximals_all_preds = maximals.map(node => node -> all_preds(node)).toMap |
78929
df323f23dfde
performance tuning for timing heuristic: pre-calculate graph operations;
Fabian Huch <huch@in.tum.de>
parents:
78928
diff
changeset
|
643 |
|
79102 | 644 |
def best_time(node: Node): Time = { |
645 |
val host = ordered_hosts.last |
|
646 |
val threads = timing_data.best_threads(node, max_threads) min host.info.num_cpus |
|
79103
883f61f0beda
clarified build schedule host: more operations;
Fabian Huch <huch@in.tum.de>
parents:
79102
diff
changeset
|
647 |
timing_data.estimate(node, host.name, threads) |
79102 | 648 |
} |
79028
6bada416ba55
clarified timing data operations: proper estimation (instead of known points);
Fabian Huch <huch@in.tum.de>
parents:
79027
diff
changeset
|
649 |
val best_times = build_graph.keys.map(node => node -> best_time(node)).toMap |
78929
df323f23dfde
performance tuning for timing heuristic: pre-calculate graph operations;
Fabian Huch <huch@in.tum.de>
parents:
78928
diff
changeset
|
650 |
|
79101
4e47b34fbb8e
clarified graph operations in timing heuristic;
Fabian Huch <huch@in.tum.de>
parents:
79091
diff
changeset
|
651 |
val succs_max_time_ms = build_graph.node_height(best_times(_).ms) |
4e47b34fbb8e
clarified graph operations in timing heuristic;
Fabian Huch <huch@in.tum.de>
parents:
79091
diff
changeset
|
652 |
def max_time(node: Node): Time = Time.ms(succs_max_time_ms(node)) + best_times(node) |
4e47b34fbb8e
clarified graph operations in timing heuristic;
Fabian Huch <huch@in.tum.de>
parents:
79091
diff
changeset
|
653 |
def max_time(task: Build_Process.Task): Time = max_time(task.name) |
78929
df323f23dfde
performance tuning for timing heuristic: pre-calculate graph operations;
Fabian Huch <huch@in.tum.de>
parents:
78928
diff
changeset
|
654 |
|
79101
4e47b34fbb8e
clarified graph operations in timing heuristic;
Fabian Huch <huch@in.tum.de>
parents:
79091
diff
changeset
|
655 |
def path_times(minimals: List[Node]): Map[Node, Time] = { |
4e47b34fbb8e
clarified graph operations in timing heuristic;
Fabian Huch <huch@in.tum.de>
parents:
79091
diff
changeset
|
656 |
def time_ms(node: Node): Long = best_times(node).ms |
4e47b34fbb8e
clarified graph operations in timing heuristic;
Fabian Huch <huch@in.tum.de>
parents:
79091
diff
changeset
|
657 |
val path_times_ms = build_graph.reachable_length(time_ms, build_graph.imm_succs, minimals) |
4e47b34fbb8e
clarified graph operations in timing heuristic;
Fabian Huch <huch@in.tum.de>
parents:
79091
diff
changeset
|
658 |
path_times_ms.view.mapValues(Time.ms).toMap |
78929
df323f23dfde
performance tuning for timing heuristic: pre-calculate graph operations;
Fabian Huch <huch@in.tum.de>
parents:
78928
diff
changeset
|
659 |
} |
df323f23dfde
performance tuning for timing heuristic: pre-calculate graph operations;
Fabian Huch <huch@in.tum.de>
parents:
78928
diff
changeset
|
660 |
|
79101
4e47b34fbb8e
clarified graph operations in timing heuristic;
Fabian Huch <huch@in.tum.de>
parents:
79091
diff
changeset
|
661 |
def path_max_times(minimals: List[Node]): Map[Node, Time] = |
4e47b34fbb8e
clarified graph operations in timing heuristic;
Fabian Huch <huch@in.tum.de>
parents:
79091
diff
changeset
|
662 |
path_times(minimals).toList.map((node, time) => node -> (time + max_time(node))).toMap |
4e47b34fbb8e
clarified graph operations in timing heuristic;
Fabian Huch <huch@in.tum.de>
parents:
79091
diff
changeset
|
663 |
|
79179
7ed43417770f
proper parallel paths: factor in elapsed time;
Fabian Huch <huch@in.tum.de>
parents:
79178
diff
changeset
|
664 |
def parallel_paths(running: List[(Node, Time)], pred: Node => Boolean = _ => true): Int = { |
78972
7a39f151e9a7
proper parallel paths for timing heuristic;
Fabian Huch <huch@in.tum.de>
parents:
78971
diff
changeset
|
665 |
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
|
666 |
|
7a39f151e9a7
proper parallel paths for timing heuristic;
Fabian Huch <huch@in.tum.de>
parents:
78971
diff
changeset
|
667 |
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
|
668 |
node -> (time - elapsed) |
7a39f151e9a7
proper parallel paths for timing heuristic;
Fabian Huch <huch@in.tum.de>
parents:
78971
diff
changeset
|
669 |
|
7a39f151e9a7
proper parallel paths for timing heuristic;
Fabian Huch <huch@in.tum.de>
parents:
78971
diff
changeset
|
670 |
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
|
671 |
if (running.isEmpty) (0, running) |
7a39f151e9a7
proper parallel paths for timing heuristic;
Fabian Huch <huch@in.tum.de>
parents:
78971
diff
changeset
|
672 |
else { |
7a39f151e9a7
proper parallel paths for timing heuristic;
Fabian Huch <huch@in.tum.de>
parents:
78971
diff
changeset
|
673 |
def get_next(node: Node): List[Node] = |
7a39f151e9a7
proper parallel paths for timing heuristic;
Fabian Huch <huch@in.tum.de>
parents:
78971
diff
changeset
|
674 |
build_graph.imm_succs(node).filter(pred).filter( |
79104 | 675 |
build_graph.imm_preds(_).intersect(running.keySet) == Set(node)).toList |
78972
7a39f151e9a7
proper parallel paths for timing heuristic;
Fabian Huch <huch@in.tum.de>
parents:
78971
diff
changeset
|
676 |
|
7a39f151e9a7
proper parallel paths for timing heuristic;
Fabian Huch <huch@in.tum.de>
parents:
78971
diff
changeset
|
677 |
val (next, elapsed) = running.minBy(_._2.ms) |
7a39f151e9a7
proper parallel paths for timing heuristic;
Fabian Huch <huch@in.tum.de>
parents:
78971
diff
changeset
|
678 |
val (remaining, finished) = |
7a39f151e9a7
proper parallel paths for timing heuristic;
Fabian Huch <huch@in.tum.de>
parents:
78971
diff
changeset
|
679 |
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
|
680 |
|
7a39f151e9a7
proper parallel paths for timing heuristic;
Fabian Huch <huch@in.tum.de>
parents:
78971
diff
changeset
|
681 |
val running1 = |
7a39f151e9a7
proper parallel paths for timing heuristic;
Fabian Huch <huch@in.tum.de>
parents:
78971
diff
changeset
|
682 |
remaining.map(pass_time(elapsed)).toMap ++ |
7a39f151e9a7
proper parallel paths for timing heuristic;
Fabian Huch <huch@in.tum.de>
parents:
78971
diff
changeset
|
683 |
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
|
684 |
val (res, running2) = parallel_paths(running1) |
79104 | 685 |
(res max running.size, running2) |
78972
7a39f151e9a7
proper parallel paths for timing heuristic;
Fabian Huch <huch@in.tum.de>
parents:
78971
diff
changeset
|
686 |
} |
7a39f151e9a7
proper parallel paths for timing heuristic;
Fabian Huch <huch@in.tum.de>
parents:
78971
diff
changeset
|
687 |
|
79179
7ed43417770f
proper parallel paths: factor in elapsed time;
Fabian Huch <huch@in.tum.de>
parents:
79178
diff
changeset
|
688 |
parallel_paths(running.toMap)._1 |
78972
7a39f151e9a7
proper parallel paths for timing heuristic;
Fabian Huch <huch@in.tum.de>
parents:
78971
diff
changeset
|
689 |
} |
79019
4df053d29215
introduced path heuristic abstraction;
Fabian Huch <huch@in.tum.de>
parents:
78976
diff
changeset
|
690 |
} |
78929
df323f23dfde
performance tuning for timing heuristic: pre-calculate graph operations;
Fabian Huch <huch@in.tum.de>
parents:
78928
diff
changeset
|
691 |
|
79110
ff68cbfa3550
clarified path time heuristic: configurable parameters for larger search space;
Fabian Huch <huch@in.tum.de>
parents:
79109
diff
changeset
|
692 |
|
ff68cbfa3550
clarified path time heuristic: configurable parameters for larger search space;
Fabian Huch <huch@in.tum.de>
parents:
79109
diff
changeset
|
693 |
object Path_Time_Heuristic { |
79180
229f49204603
clarified build heuristics parameters;
Fabian Huch <huch@in.tum.de>
parents:
79179
diff
changeset
|
694 |
sealed trait Critical_Criterion |
229f49204603
clarified build heuristics parameters;
Fabian Huch <huch@in.tum.de>
parents:
79179
diff
changeset
|
695 |
case class Absolute_Time(time: Time) extends Critical_Criterion { |
79110
ff68cbfa3550
clarified path time heuristic: configurable parameters for larger search space;
Fabian Huch <huch@in.tum.de>
parents:
79109
diff
changeset
|
696 |
override def toString: String = "absolute time (" + time.message_hms + ")" |
ff68cbfa3550
clarified path time heuristic: configurable parameters for larger search space;
Fabian Huch <huch@in.tum.de>
parents:
79109
diff
changeset
|
697 |
} |
79180
229f49204603
clarified build heuristics parameters;
Fabian Huch <huch@in.tum.de>
parents:
79179
diff
changeset
|
698 |
case class Relative_Time(factor: Double) extends Critical_Criterion { |
79110
ff68cbfa3550
clarified path time heuristic: configurable parameters for larger search space;
Fabian Huch <huch@in.tum.de>
parents:
79109
diff
changeset
|
699 |
override def toString: String = "relative time (" + factor + ")" |
ff68cbfa3550
clarified path time heuristic: configurable parameters for larger search space;
Fabian Huch <huch@in.tum.de>
parents:
79109
diff
changeset
|
700 |
} |
ff68cbfa3550
clarified path time heuristic: configurable parameters for larger search space;
Fabian Huch <huch@in.tum.de>
parents:
79109
diff
changeset
|
701 |
|
79180
229f49204603
clarified build heuristics parameters;
Fabian Huch <huch@in.tum.de>
parents:
79179
diff
changeset
|
702 |
sealed trait Parallel_Strategy |
229f49204603
clarified build heuristics parameters;
Fabian Huch <huch@in.tum.de>
parents:
79179
diff
changeset
|
703 |
case class Fixed_Thread(threads: Int) extends Parallel_Strategy { |
79110
ff68cbfa3550
clarified path time heuristic: configurable parameters for larger search space;
Fabian Huch <huch@in.tum.de>
parents:
79109
diff
changeset
|
704 |
override def toString: String = "fixed threads (" + threads + ")" |
ff68cbfa3550
clarified path time heuristic: configurable parameters for larger search space;
Fabian Huch <huch@in.tum.de>
parents:
79109
diff
changeset
|
705 |
} |
79180
229f49204603
clarified build heuristics parameters;
Fabian Huch <huch@in.tum.de>
parents:
79179
diff
changeset
|
706 |
case class Time_Based_Threads(f: Time => Int) extends Parallel_Strategy { |
79110
ff68cbfa3550
clarified path time heuristic: configurable parameters for larger search space;
Fabian Huch <huch@in.tum.de>
parents:
79109
diff
changeset
|
707 |
override def toString: String = "time based threads" |
ff68cbfa3550
clarified path time heuristic: configurable parameters for larger search space;
Fabian Huch <huch@in.tum.de>
parents:
79109
diff
changeset
|
708 |
} |
79180
229f49204603
clarified build heuristics parameters;
Fabian Huch <huch@in.tum.de>
parents:
79179
diff
changeset
|
709 |
|
229f49204603
clarified build heuristics parameters;
Fabian Huch <huch@in.tum.de>
parents:
79179
diff
changeset
|
710 |
sealed trait Host_Criterion |
229f49204603
clarified build heuristics parameters;
Fabian Huch <huch@in.tum.de>
parents:
79179
diff
changeset
|
711 |
case object Critical_Nodes extends Host_Criterion { |
229f49204603
clarified build heuristics parameters;
Fabian Huch <huch@in.tum.de>
parents:
79179
diff
changeset
|
712 |
override def toString: String = "per critical node" |
229f49204603
clarified build heuristics parameters;
Fabian Huch <huch@in.tum.de>
parents:
79179
diff
changeset
|
713 |
} |
229f49204603
clarified build heuristics parameters;
Fabian Huch <huch@in.tum.de>
parents:
79179
diff
changeset
|
714 |
case class Fixed_Fraction(fraction: Double) extends Host_Criterion { |
229f49204603
clarified build heuristics parameters;
Fabian Huch <huch@in.tum.de>
parents:
79179
diff
changeset
|
715 |
override def toString: String = "fixed fraction (" + fraction + ")" |
229f49204603
clarified build heuristics parameters;
Fabian Huch <huch@in.tum.de>
parents:
79179
diff
changeset
|
716 |
} |
229f49204603
clarified build heuristics parameters;
Fabian Huch <huch@in.tum.de>
parents:
79179
diff
changeset
|
717 |
case class Host_Speed(min_factor: Double) extends Host_Criterion { |
229f49204603
clarified build heuristics parameters;
Fabian Huch <huch@in.tum.de>
parents:
79179
diff
changeset
|
718 |
override def toString: String = "host speed (" + min_factor + ")" |
229f49204603
clarified build heuristics parameters;
Fabian Huch <huch@in.tum.de>
parents:
79179
diff
changeset
|
719 |
} |
79110
ff68cbfa3550
clarified path time heuristic: configurable parameters for larger search space;
Fabian Huch <huch@in.tum.de>
parents:
79109
diff
changeset
|
720 |
} |
ff68cbfa3550
clarified path time heuristic: configurable parameters for larger search space;
Fabian Huch <huch@in.tum.de>
parents:
79109
diff
changeset
|
721 |
|
ff68cbfa3550
clarified path time heuristic: configurable parameters for larger search space;
Fabian Huch <huch@in.tum.de>
parents:
79109
diff
changeset
|
722 |
class Path_Time_Heuristic( |
79180
229f49204603
clarified build heuristics parameters;
Fabian Huch <huch@in.tum.de>
parents:
79179
diff
changeset
|
723 |
is_critical: Path_Time_Heuristic.Critical_Criterion, |
229f49204603
clarified build heuristics parameters;
Fabian Huch <huch@in.tum.de>
parents:
79179
diff
changeset
|
724 |
parallel_threads: Path_Time_Heuristic.Parallel_Strategy, |
229f49204603
clarified build heuristics parameters;
Fabian Huch <huch@in.tum.de>
parents:
79179
diff
changeset
|
725 |
host_criterion: Path_Time_Heuristic.Host_Criterion, |
79019
4df053d29215
introduced path heuristic abstraction;
Fabian Huch <huch@in.tum.de>
parents:
78976
diff
changeset
|
726 |
timing_data: Timing_Data, |
4df053d29215
introduced path heuristic abstraction;
Fabian Huch <huch@in.tum.de>
parents:
78976
diff
changeset
|
727 |
sessions_structure: Sessions.Structure, |
79185 | 728 |
build_uuid: String, |
79027
d08fb157e300
use proper max threads (limited by available hardware) in heuristics;
Fabian Huch <huch@in.tum.de>
parents:
79026
diff
changeset
|
729 |
max_threads_limit: Int = 8 |
79185 | 730 |
) extends Path_Heuristic(timing_data, sessions_structure, max_threads_limit, build_uuid) { |
79110
ff68cbfa3550
clarified path time heuristic: configurable parameters for larger search space;
Fabian Huch <huch@in.tum.de>
parents:
79109
diff
changeset
|
731 |
import Path_Time_Heuristic.* |
ff68cbfa3550
clarified path time heuristic: configurable parameters for larger search space;
Fabian Huch <huch@in.tum.de>
parents:
79109
diff
changeset
|
732 |
|
79180
229f49204603
clarified build heuristics parameters;
Fabian Huch <huch@in.tum.de>
parents:
79179
diff
changeset
|
733 |
override def toString: Node = { |
229f49204603
clarified build heuristics parameters;
Fabian Huch <huch@in.tum.de>
parents:
79179
diff
changeset
|
734 |
val params = |
229f49204603
clarified build heuristics parameters;
Fabian Huch <huch@in.tum.de>
parents:
79179
diff
changeset
|
735 |
List( |
229f49204603
clarified build heuristics parameters;
Fabian Huch <huch@in.tum.de>
parents:
79179
diff
changeset
|
736 |
"critical: " + is_critical, |
229f49204603
clarified build heuristics parameters;
Fabian Huch <huch@in.tum.de>
parents:
79179
diff
changeset
|
737 |
"parallel: " + parallel_threads, |
229f49204603
clarified build heuristics parameters;
Fabian Huch <huch@in.tum.de>
parents:
79179
diff
changeset
|
738 |
"fast hosts: " + host_criterion) |
229f49204603
clarified build heuristics parameters;
Fabian Huch <huch@in.tum.de>
parents:
79179
diff
changeset
|
739 |
"path time heuristic (" + params.mkString(", ") + ")" |
229f49204603
clarified build heuristics parameters;
Fabian Huch <huch@in.tum.de>
parents:
79179
diff
changeset
|
740 |
} |
78929
df323f23dfde
performance tuning for timing heuristic: pre-calculate graph operations;
Fabian Huch <huch@in.tum.de>
parents:
78928
diff
changeset
|
741 |
|
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
|
742 |
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
|
743 |
val resources = host_infos.available(state) |
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
744 |
|
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
745 |
def best_threads(task: Build_Process.Task): Int = |
79028
6bada416ba55
clarified timing data operations: proper estimation (instead of known points);
Fabian Huch <huch@in.tum.de>
parents:
79027
diff
changeset
|
746 |
timing_data.best_threads(task.name, max_threads) |
78971
f930d24f1548
scheduled build: allocate cpus more aggressively, to avoid idle threads;
Fabian Huch <huch@in.tum.de>
parents:
78970
diff
changeset
|
747 |
|
79028
6bada416ba55
clarified timing data operations: proper estimation (instead of known points);
Fabian Huch <huch@in.tum.de>
parents:
79027
diff
changeset
|
748 |
val rev_ordered_hosts = ordered_hosts.reverse.map(_ -> max_threads) |
78845
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
749 |
|
79180
229f49204603
clarified build heuristics parameters;
Fabian Huch <huch@in.tum.de>
parents:
79179
diff
changeset
|
750 |
val available_nodes = |
229f49204603
clarified build heuristics parameters;
Fabian Huch <huch@in.tum.de>
parents:
79179
diff
changeset
|
751 |
host_infos.available(state.copy(running = Map.empty)) |
229f49204603
clarified build heuristics parameters;
Fabian Huch <huch@in.tum.de>
parents:
79179
diff
changeset
|
752 |
.unused_nodes(max_threads) |
229f49204603
clarified build heuristics parameters;
Fabian Huch <huch@in.tum.de>
parents:
79179
diff
changeset
|
753 |
.sortBy(node => host_infos.the_host(node))(host_infos.host_speeds).reverse |
79179
7ed43417770f
proper parallel paths: factor in elapsed time;
Fabian Huch <huch@in.tum.de>
parents:
79178
diff
changeset
|
754 |
|
7ed43417770f
proper parallel paths: factor in elapsed time;
Fabian Huch <huch@in.tum.de>
parents:
79178
diff
changeset
|
755 |
def remaining_time(node: Node): (Node, Time) = |
7ed43417770f
proper parallel paths: factor in elapsed time;
Fabian Huch <huch@in.tum.de>
parents:
79178
diff
changeset
|
756 |
state.running.get(node) match { |
7ed43417770f
proper parallel paths: factor in elapsed time;
Fabian Huch <huch@in.tum.de>
parents:
79178
diff
changeset
|
757 |
case None => node -> best_time(node) |
7ed43417770f
proper parallel paths: factor in elapsed time;
Fabian Huch <huch@in.tum.de>
parents:
79178
diff
changeset
|
758 |
case Some(job) => |
7ed43417770f
proper parallel paths: factor in elapsed time;
Fabian Huch <huch@in.tum.de>
parents:
79178
diff
changeset
|
759 |
val estimate = |
7ed43417770f
proper parallel paths: factor in elapsed time;
Fabian Huch <huch@in.tum.de>
parents:
79178
diff
changeset
|
760 |
timing_data.estimate(job.name, job.node_info.hostname, |
7ed43417770f
proper parallel paths: factor in elapsed time;
Fabian Huch <huch@in.tum.de>
parents:
79178
diff
changeset
|
761 |
host_infos.num_threads(job.node_info)) |
79184 | 762 |
node -> ((Time.now() - job.start_date.time + estimate) max Time.zero) |
79179
7ed43417770f
proper parallel paths: factor in elapsed time;
Fabian Huch <huch@in.tum.de>
parents:
79178
diff
changeset
|
763 |
} |
7ed43417770f
proper parallel paths: factor in elapsed time;
Fabian Huch <huch@in.tum.de>
parents:
79178
diff
changeset
|
764 |
|
7ed43417770f
proper parallel paths: factor in elapsed time;
Fabian Huch <huch@in.tum.de>
parents:
79178
diff
changeset
|
765 |
val max_parallel = parallel_paths(state.ready.map(_.name).map(remaining_time)) |
79101
4e47b34fbb8e
clarified graph operations in timing heuristic;
Fabian Huch <huch@in.tum.de>
parents:
79091
diff
changeset
|
766 |
val next_sorted = state.next_ready.sortBy(max_time(_).ms).reverse |
79088 | 767 |
|
79180
229f49204603
clarified build heuristics parameters;
Fabian Huch <huch@in.tum.de>
parents:
79179
diff
changeset
|
768 |
if (max_parallel <= available_nodes.length) { |
79101
4e47b34fbb8e
clarified graph operations in timing heuristic;
Fabian Huch <huch@in.tum.de>
parents:
79091
diff
changeset
|
769 |
val all_tasks = next_sorted.map(task => (task, best_threads(task), best_threads(task))) |
79028
6bada416ba55
clarified timing data operations: proper estimation (instead of known points);
Fabian Huch <huch@in.tum.de>
parents:
79027
diff
changeset
|
770 |
resources.try_allocate_tasks(rev_ordered_hosts, all_tasks)._1 |
78971
f930d24f1548
scheduled build: allocate cpus more aggressively, to avoid idle threads;
Fabian Huch <huch@in.tum.de>
parents:
78970
diff
changeset
|
771 |
} |
78845
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
772 |
else { |
79110
ff68cbfa3550
clarified path time heuristic: configurable parameters for larger search space;
Fabian Huch <huch@in.tum.de>
parents:
79109
diff
changeset
|
773 |
def is_critical(time: Time): Boolean = |
ff68cbfa3550
clarified path time heuristic: configurable parameters for larger search space;
Fabian Huch <huch@in.tum.de>
parents:
79109
diff
changeset
|
774 |
this.is_critical match { |
ff68cbfa3550
clarified path time heuristic: configurable parameters for larger search space;
Fabian Huch <huch@in.tum.de>
parents:
79109
diff
changeset
|
775 |
case Absolute_Time(threshold) => time > threshold |
ff68cbfa3550
clarified path time heuristic: configurable parameters for larger search space;
Fabian Huch <huch@in.tum.de>
parents:
79109
diff
changeset
|
776 |
case Relative_Time(factor) => time > minimals.map(max_time).maxBy(_.ms).scale(factor) |
ff68cbfa3550
clarified path time heuristic: configurable parameters for larger search space;
Fabian Huch <huch@in.tum.de>
parents:
79109
diff
changeset
|
777 |
} |
ff68cbfa3550
clarified path time heuristic: configurable parameters for larger search space;
Fabian Huch <huch@in.tum.de>
parents:
79109
diff
changeset
|
778 |
|
ff68cbfa3550
clarified path time heuristic: configurable parameters for larger search space;
Fabian Huch <huch@in.tum.de>
parents:
79109
diff
changeset
|
779 |
val critical_minimals = state.ready.filter(task => is_critical(max_time(task))).map(_.name) |
ff68cbfa3550
clarified path time heuristic: configurable parameters for larger search space;
Fabian Huch <huch@in.tum.de>
parents:
79109
diff
changeset
|
780 |
val critical_nodes = |
ff68cbfa3550
clarified path time heuristic: configurable parameters for larger search space;
Fabian Huch <huch@in.tum.de>
parents:
79109
diff
changeset
|
781 |
path_max_times(critical_minimals).filter((_, time) => is_critical(time)).keySet |
78845
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
782 |
|
79101
4e47b34fbb8e
clarified graph operations in timing heuristic;
Fabian Huch <huch@in.tum.de>
parents:
79091
diff
changeset
|
783 |
val (critical, other) = next_sorted.partition(task => critical_nodes.contains(task.name)) |
78845
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
784 |
|
78971
f930d24f1548
scheduled build: allocate cpus more aggressively, to avoid idle threads;
Fabian Huch <huch@in.tum.de>
parents:
78970
diff
changeset
|
785 |
val critical_tasks = critical.map(task => (task, best_threads(task), best_threads(task))) |
79110
ff68cbfa3550
clarified path time heuristic: configurable parameters for larger search space;
Fabian Huch <huch@in.tum.de>
parents:
79109
diff
changeset
|
786 |
|
ff68cbfa3550
clarified path time heuristic: configurable parameters for larger search space;
Fabian Huch <huch@in.tum.de>
parents:
79109
diff
changeset
|
787 |
def parallel_threads(task: Build_Process.Task): Int = |
ff68cbfa3550
clarified path time heuristic: configurable parameters for larger search space;
Fabian Huch <huch@in.tum.de>
parents:
79109
diff
changeset
|
788 |
this.parallel_threads match { |
ff68cbfa3550
clarified path time heuristic: configurable parameters for larger search space;
Fabian Huch <huch@in.tum.de>
parents:
79109
diff
changeset
|
789 |
case Fixed_Thread(threads) => threads |
ff68cbfa3550
clarified path time heuristic: configurable parameters for larger search space;
Fabian Huch <huch@in.tum.de>
parents:
79109
diff
changeset
|
790 |
case Time_Based_Threads(f) => f(best_time(task.name)) |
ff68cbfa3550
clarified path time heuristic: configurable parameters for larger search space;
Fabian Huch <huch@in.tum.de>
parents:
79109
diff
changeset
|
791 |
} |
ff68cbfa3550
clarified path time heuristic: configurable parameters for larger search space;
Fabian Huch <huch@in.tum.de>
parents:
79109
diff
changeset
|
792 |
|
ff68cbfa3550
clarified path time heuristic: configurable parameters for larger search space;
Fabian Huch <huch@in.tum.de>
parents:
79109
diff
changeset
|
793 |
val other_tasks = other.map(task => (task, parallel_threads(task), best_threads(task))) |
78971
f930d24f1548
scheduled build: allocate cpus more aggressively, to avoid idle threads;
Fabian Huch <huch@in.tum.de>
parents:
78970
diff
changeset
|
794 |
|
79179
7ed43417770f
proper parallel paths: factor in elapsed time;
Fabian Huch <huch@in.tum.de>
parents:
79178
diff
changeset
|
795 |
val max_critical_parallel = |
7ed43417770f
proper parallel paths: factor in elapsed time;
Fabian Huch <huch@in.tum.de>
parents:
79178
diff
changeset
|
796 |
parallel_paths(critical_minimals.map(remaining_time), critical_nodes.contains) |
79180
229f49204603
clarified build heuristics parameters;
Fabian Huch <huch@in.tum.de>
parents:
79179
diff
changeset
|
797 |
val max_critical_hosts = |
229f49204603
clarified build heuristics parameters;
Fabian Huch <huch@in.tum.de>
parents:
79179
diff
changeset
|
798 |
available_nodes.take(max_critical_parallel).map(_.hostname).distinct.length |
229f49204603
clarified build heuristics parameters;
Fabian Huch <huch@in.tum.de>
parents:
79179
diff
changeset
|
799 |
|
229f49204603
clarified build heuristics parameters;
Fabian Huch <huch@in.tum.de>
parents:
79179
diff
changeset
|
800 |
val split = |
229f49204603
clarified build heuristics parameters;
Fabian Huch <huch@in.tum.de>
parents:
79179
diff
changeset
|
801 |
this.host_criterion match { |
229f49204603
clarified build heuristics parameters;
Fabian Huch <huch@in.tum.de>
parents:
79179
diff
changeset
|
802 |
case Critical_Nodes => max_critical_hosts |
229f49204603
clarified build heuristics parameters;
Fabian Huch <huch@in.tum.de>
parents:
79179
diff
changeset
|
803 |
case Fixed_Fraction(fraction) => |
229f49204603
clarified build heuristics parameters;
Fabian Huch <huch@in.tum.de>
parents:
79179
diff
changeset
|
804 |
((rev_ordered_hosts.length * fraction).ceil.toInt max 1) min max_critical_hosts |
229f49204603
clarified build heuristics parameters;
Fabian Huch <huch@in.tum.de>
parents:
79179
diff
changeset
|
805 |
case Host_Speed(min_factor) => |
229f49204603
clarified build heuristics parameters;
Fabian Huch <huch@in.tum.de>
parents:
79179
diff
changeset
|
806 |
val best = rev_ordered_hosts.head._1.info.benchmark_score.get |
229f49204603
clarified build heuristics parameters;
Fabian Huch <huch@in.tum.de>
parents:
79179
diff
changeset
|
807 |
val num_fast = |
229f49204603
clarified build heuristics parameters;
Fabian Huch <huch@in.tum.de>
parents:
79179
diff
changeset
|
808 |
rev_ordered_hosts.count(_._1.info.benchmark_score.exists(_ >= best * min_factor)) |
229f49204603
clarified build heuristics parameters;
Fabian Huch <huch@in.tum.de>
parents:
79179
diff
changeset
|
809 |
num_fast min max_critical_hosts |
229f49204603
clarified build heuristics parameters;
Fabian Huch <huch@in.tum.de>
parents:
79179
diff
changeset
|
810 |
} |
229f49204603
clarified build heuristics parameters;
Fabian Huch <huch@in.tum.de>
parents:
79179
diff
changeset
|
811 |
|
229f49204603
clarified build heuristics parameters;
Fabian Huch <huch@in.tum.de>
parents:
79179
diff
changeset
|
812 |
val (critical_hosts, other_hosts) = rev_ordered_hosts.splitAt(split) |
78845
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
813 |
|
78971
f930d24f1548
scheduled build: allocate cpus more aggressively, to avoid idle threads;
Fabian Huch <huch@in.tum.de>
parents:
78970
diff
changeset
|
814 |
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
|
815 |
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
|
816 |
|
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
817 |
configs1 ::: configs2 |
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
818 |
} |
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
819 |
} |
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
820 |
} |
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
821 |
|
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
822 |
|
79290
9deadc9d8872
separate build processes for scheduler and scheduled;
Fabian Huch <huch@in.tum.de>
parents:
79289
diff
changeset
|
823 |
/* master and slave processes for scheduled build */ |
78845
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
824 |
|
79290
9deadc9d8872
separate build processes for scheduler and scheduled;
Fabian Huch <huch@in.tum.de>
parents:
79289
diff
changeset
|
825 |
class Scheduled_Build_Process( |
78845
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
826 |
build_context: Build.Context, |
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
827 |
build_progress: Progress, |
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
828 |
server: SSH.Server, |
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
829 |
) extends Build_Process(build_context, build_progress, server) { |
79186
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
830 |
/* global state: internal var vs. external database */ |
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
831 |
|
79290
9deadc9d8872
separate build processes for scheduler and scheduled;
Fabian Huch <huch@in.tum.de>
parents:
79289
diff
changeset
|
832 |
protected var _schedule = Schedule.init(build_uuid) |
79186
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
833 |
|
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
834 |
override protected def synchronized_database[A](label: String)(body: => A): A = |
79527
f1f08ca40d96
make build process state protected to avoid copying in subclasses (e.g. for database connections);
Fabian Huch <huch@in.tum.de>
parents:
79502
diff
changeset
|
835 |
synchronized { |
79186
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
836 |
_build_database match { |
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
837 |
case None => body |
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
838 |
case Some(db) => |
79527
f1f08ca40d96
make build process state protected to avoid copying in subclasses (e.g. for database connections);
Fabian Huch <huch@in.tum.de>
parents:
79502
diff
changeset
|
839 |
val tables = |
f1f08ca40d96
make build process state protected to avoid copying in subclasses (e.g. for database connections);
Fabian Huch <huch@in.tum.de>
parents:
79502
diff
changeset
|
840 |
Build_Process.private_data.tables.list ::: Build_Schedule.private_data.tables.list |
f1f08ca40d96
make build process state protected to avoid copying in subclasses (e.g. for database connections);
Fabian Huch <huch@in.tum.de>
parents:
79502
diff
changeset
|
841 |
db.transaction_lock(SQL.Tables.list(tables), label = label) { |
f1f08ca40d96
make build process state protected to avoid copying in subclasses (e.g. for database connections);
Fabian Huch <huch@in.tum.de>
parents:
79502
diff
changeset
|
842 |
val old_state = Build_Process.private_data.pull_database(db, worker_uuid, _state) |
79186
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
843 |
val old_schedule = Build_Schedule.private_data.pull_schedule(db, _schedule) |
79527
f1f08ca40d96
make build process state protected to avoid copying in subclasses (e.g. for database connections);
Fabian Huch <huch@in.tum.de>
parents:
79502
diff
changeset
|
844 |
_state = old_state |
79186
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
845 |
_schedule = old_schedule |
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
846 |
val res = body |
79527
f1f08ca40d96
make build process state protected to avoid copying in subclasses (e.g. for database connections);
Fabian Huch <huch@in.tum.de>
parents:
79502
diff
changeset
|
847 |
_state = |
f1f08ca40d96
make build process state protected to avoid copying in subclasses (e.g. for database connections);
Fabian Huch <huch@in.tum.de>
parents:
79502
diff
changeset
|
848 |
Build_Process.private_data.update_database(db, worker_uuid, _state, old_state) |
79190
2039f3609884
add serial for build schedule to avoid unnecessary db read/writes;
Fabian Huch <huch@in.tum.de>
parents:
79189
diff
changeset
|
849 |
_schedule = Build_Schedule.private_data.update_schedule(db, _schedule, old_schedule) |
79186
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
850 |
res |
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
851 |
} |
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
852 |
} |
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
853 |
} |
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
854 |
|
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
855 |
|
79290
9deadc9d8872
separate build processes for scheduler and scheduled;
Fabian Huch <huch@in.tum.de>
parents:
79289
diff
changeset
|
856 |
/* build process */ |
9deadc9d8872
separate build processes for scheduler and scheduled;
Fabian Huch <huch@in.tum.de>
parents:
79289
diff
changeset
|
857 |
|
9deadc9d8872
separate build processes for scheduler and scheduled;
Fabian Huch <huch@in.tum.de>
parents:
79289
diff
changeset
|
858 |
override def next_node_info(state: Build_Process.State, session_name: String): Node_Info = |
9deadc9d8872
separate build processes for scheduler and scheduled;
Fabian Huch <huch@in.tum.de>
parents:
79289
diff
changeset
|
859 |
_schedule.graph.get_node(session_name).node_info |
9deadc9d8872
separate build processes for scheduler and scheduled;
Fabian Huch <huch@in.tum.de>
parents:
79289
diff
changeset
|
860 |
|
9deadc9d8872
separate build processes for scheduler and scheduled;
Fabian Huch <huch@in.tum.de>
parents:
79289
diff
changeset
|
861 |
override def next_jobs(state: Build_Process.State): List[String] = |
79294
ae0a2cb42b05
continue build while waiting for updated schedule;
Fabian Huch <huch@in.tum.de>
parents:
79293
diff
changeset
|
862 |
if (progress.stopped || _schedule.is_empty) Nil else _schedule.next(hostname, state) |
79290
9deadc9d8872
separate build processes for scheduler and scheduled;
Fabian Huch <huch@in.tum.de>
parents:
79289
diff
changeset
|
863 |
} |
9deadc9d8872
separate build processes for scheduler and scheduled;
Fabian Huch <huch@in.tum.de>
parents:
79289
diff
changeset
|
864 |
|
9deadc9d8872
separate build processes for scheduler and scheduled;
Fabian Huch <huch@in.tum.de>
parents:
79289
diff
changeset
|
865 |
abstract class Scheduler_Build_Process( |
9deadc9d8872
separate build processes for scheduler and scheduled;
Fabian Huch <huch@in.tum.de>
parents:
79289
diff
changeset
|
866 |
build_context: Build.Context, |
9deadc9d8872
separate build processes for scheduler and scheduled;
Fabian Huch <huch@in.tum.de>
parents:
79289
diff
changeset
|
867 |
build_progress: Progress, |
9deadc9d8872
separate build processes for scheduler and scheduled;
Fabian Huch <huch@in.tum.de>
parents:
79289
diff
changeset
|
868 |
server: SSH.Server, |
9deadc9d8872
separate build processes for scheduler and scheduled;
Fabian Huch <huch@in.tum.de>
parents:
79289
diff
changeset
|
869 |
) extends Scheduled_Build_Process(build_context, build_progress, server) { |
9deadc9d8872
separate build processes for scheduler and scheduled;
Fabian Huch <huch@in.tum.de>
parents:
79289
diff
changeset
|
870 |
require(build_context.master) |
9deadc9d8872
separate build processes for scheduler and scheduled;
Fabian Huch <huch@in.tum.de>
parents:
79289
diff
changeset
|
871 |
|
9deadc9d8872
separate build processes for scheduler and scheduled;
Fabian Huch <huch@in.tum.de>
parents:
79289
diff
changeset
|
872 |
protected val start_date = Date.now() |
9deadc9d8872
separate build processes for scheduler and scheduled;
Fabian Huch <huch@in.tum.de>
parents:
79289
diff
changeset
|
873 |
|
79527
f1f08ca40d96
make build process state protected to avoid copying in subclasses (e.g. for database connections);
Fabian Huch <huch@in.tum.de>
parents:
79502
diff
changeset
|
874 |
for (db <- _build_database) { |
f1f08ca40d96
make build process state protected to avoid copying in subclasses (e.g. for database connections);
Fabian Huch <huch@in.tum.de>
parents:
79502
diff
changeset
|
875 |
Build_Schedule.private_data.transaction_lock( |
f1f08ca40d96
make build process state protected to avoid copying in subclasses (e.g. for database connections);
Fabian Huch <huch@in.tum.de>
parents:
79502
diff
changeset
|
876 |
db, |
f1f08ca40d96
make build process state protected to avoid copying in subclasses (e.g. for database connections);
Fabian Huch <huch@in.tum.de>
parents:
79502
diff
changeset
|
877 |
create = true, |
f1f08ca40d96
make build process state protected to avoid copying in subclasses (e.g. for database connections);
Fabian Huch <huch@in.tum.de>
parents:
79502
diff
changeset
|
878 |
label = "Scheduler_Build_Process.create" |
f1f08ca40d96
make build process state protected to avoid copying in subclasses (e.g. for database connections);
Fabian Huch <huch@in.tum.de>
parents:
79502
diff
changeset
|
879 |
) { Build_Schedule.private_data.clean_build_schedules(db) } |
f1f08ca40d96
make build process state protected to avoid copying in subclasses (e.g. for database connections);
Fabian Huch <huch@in.tum.de>
parents:
79502
diff
changeset
|
880 |
db.vacuum(Build_Schedule.private_data.tables.list) |
f1f08ca40d96
make build process state protected to avoid copying in subclasses (e.g. for database connections);
Fabian Huch <huch@in.tum.de>
parents:
79502
diff
changeset
|
881 |
} |
f1f08ca40d96
make build process state protected to avoid copying in subclasses (e.g. for database connections);
Fabian Huch <huch@in.tum.de>
parents:
79502
diff
changeset
|
882 |
|
f1f08ca40d96
make build process state protected to avoid copying in subclasses (e.g. for database connections);
Fabian Huch <huch@in.tum.de>
parents:
79502
diff
changeset
|
883 |
|
79290
9deadc9d8872
separate build processes for scheduler and scheduled;
Fabian Huch <huch@in.tum.de>
parents:
79289
diff
changeset
|
884 |
def init_scheduler(timing_data: Timing_Data): Scheduler |
9deadc9d8872
separate build processes for scheduler and scheduled;
Fabian Huch <huch@in.tum.de>
parents:
79289
diff
changeset
|
885 |
|
9deadc9d8872
separate build processes for scheduler and scheduled;
Fabian Huch <huch@in.tum.de>
parents:
79289
diff
changeset
|
886 |
|
9deadc9d8872
separate build processes for scheduler and scheduled;
Fabian Huch <huch@in.tum.de>
parents:
79289
diff
changeset
|
887 |
/* global resources with common close() operation */ |
9deadc9d8872
separate build processes for scheduler and scheduled;
Fabian Huch <huch@in.tum.de>
parents:
79289
diff
changeset
|
888 |
|
9deadc9d8872
separate build processes for scheduler and scheduled;
Fabian Huch <huch@in.tum.de>
parents:
79289
diff
changeset
|
889 |
private final lazy val _log_store: Build_Log.Store = Build_Log.store(build_options) |
9deadc9d8872
separate build processes for scheduler and scheduled;
Fabian Huch <huch@in.tum.de>
parents:
79289
diff
changeset
|
890 |
private final lazy val _log_database: SQL.Database = |
9deadc9d8872
separate build processes for scheduler and scheduled;
Fabian Huch <huch@in.tum.de>
parents:
79289
diff
changeset
|
891 |
try { |
9deadc9d8872
separate build processes for scheduler and scheduled;
Fabian Huch <huch@in.tum.de>
parents:
79289
diff
changeset
|
892 |
val db = _log_store.open_database(server = this.server) |
9deadc9d8872
separate build processes for scheduler and scheduled;
Fabian Huch <huch@in.tum.de>
parents:
79289
diff
changeset
|
893 |
_log_store.init_database(db) |
9deadc9d8872
separate build processes for scheduler and scheduled;
Fabian Huch <huch@in.tum.de>
parents:
79289
diff
changeset
|
894 |
db |
9deadc9d8872
separate build processes for scheduler and scheduled;
Fabian Huch <huch@in.tum.de>
parents:
79289
diff
changeset
|
895 |
} |
9deadc9d8872
separate build processes for scheduler and scheduled;
Fabian Huch <huch@in.tum.de>
parents:
79289
diff
changeset
|
896 |
catch { case exn: Throwable => close(); throw exn } |
9deadc9d8872
separate build processes for scheduler and scheduled;
Fabian Huch <huch@in.tum.de>
parents:
79289
diff
changeset
|
897 |
|
9deadc9d8872
separate build processes for scheduler and scheduled;
Fabian Huch <huch@in.tum.de>
parents:
79289
diff
changeset
|
898 |
override def close(): Unit = { |
9deadc9d8872
separate build processes for scheduler and scheduled;
Fabian Huch <huch@in.tum.de>
parents:
79289
diff
changeset
|
899 |
Option(_log_database).foreach(_.close()) |
9deadc9d8872
separate build processes for scheduler and scheduled;
Fabian Huch <huch@in.tum.de>
parents:
79289
diff
changeset
|
900 |
super.close() |
9deadc9d8872
separate build processes for scheduler and scheduled;
Fabian Huch <huch@in.tum.de>
parents:
79289
diff
changeset
|
901 |
} |
9deadc9d8872
separate build processes for scheduler and scheduled;
Fabian Huch <huch@in.tum.de>
parents:
79289
diff
changeset
|
902 |
|
9deadc9d8872
separate build processes for scheduler and scheduled;
Fabian Huch <huch@in.tum.de>
parents:
79289
diff
changeset
|
903 |
|
78845
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
904 |
/* previous results via build log */ |
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
905 |
|
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
906 |
private val timing_data: Timing_Data = { |
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
907 |
val cluster_hosts: List[Build_Cluster.Host] = |
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
908 |
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
|
909 |
else { |
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
910 |
val local_build_host = |
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
911 |
Build_Cluster.Host( |
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
912 |
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
|
913 |
local_build_host :: build_context.build_hosts |
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
914 |
} |
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
915 |
|
79090
20be5b925720
clarified load vs. apply vs. make;
Fabian Huch <huch@in.tum.de>
parents:
79089
diff
changeset
|
916 |
val host_infos = Host_Infos.load(cluster_hosts, _host_database) |
20be5b925720
clarified load vs. apply vs. make;
Fabian Huch <huch@in.tum.de>
parents:
79089
diff
changeset
|
917 |
Timing_Data.load(host_infos, _log_database) |
78845
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
918 |
} |
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
|
919 |
private val scheduler = init_scheduler(timing_data) |
78845
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
920 |
|
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
921 |
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
|
922 |
val sessions = |
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
923 |
for { |
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
924 |
(session_name, result) <- state.toList |
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
925 |
if !result.current |
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
926 |
} yield { |
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
927 |
val info = build_context.sessions_structure(session_name) |
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
928 |
val entry = |
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
929 |
if (!results.cancelled(session_name)) { |
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
930 |
val status = |
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
931 |
if (result.ok) Build_Log.Session_Status.finished |
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
932 |
else Build_Log.Session_Status.failed |
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
933 |
|
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
934 |
Build_Log.Session_Entry( |
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
935 |
chapter = info.chapter, |
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
936 |
groups = info.groups, |
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
937 |
hostname = Some(result.node_info.hostname), |
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
938 |
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
|
939 |
timing = result.process_result.timing, |
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
940 |
sources = Some(result.output_shasum.digest.toString), |
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
941 |
status = Some(status)) |
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
942 |
} |
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
943 |
else |
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
944 |
Build_Log.Session_Entry( |
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
945 |
chapter = info.chapter, |
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
946 |
groups = info.groups, |
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
947 |
status = Some(Build_Log.Session_Status.cancelled)) |
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
948 |
session_name -> entry |
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
949 |
} |
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
950 |
|
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
951 |
val settings = |
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
952 |
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
|
953 |
name -> Isabelle_System.getenv(name)) |
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
954 |
val props = |
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
955 |
List( |
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
956 |
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
|
957 |
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
|
958 |
Build_Log.Prop.build_host.name -> hostname, |
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
959 |
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
|
960 |
|
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
961 |
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
|
962 |
val build_info = Build_Log.Build_Info(sessions.toMap) |
79089 | 963 |
val log_name = Build_Log.log_filename(engine = build_context.engine.name, date = start_date) |
78845
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
964 |
|
79062
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79042
diff
changeset
|
965 |
Build_Log.private_data.update_sessions( |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79042
diff
changeset
|
966 |
_log_database, _log_store.cache.compress, log_name.file_name, build_info) |
6977fb0153fb
clarified modules: Build_Log.private_data provides raw data access without transaction_lock;
wenzelm
parents:
79042
diff
changeset
|
967 |
Build_Log.private_data.update_meta_info(_log_database, log_name.file_name, meta_info) |
78845
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
968 |
} |
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
969 |
|
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
970 |
|
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
971 |
/* build process */ |
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
972 |
|
78969
1b05c2b10c9f
finalize current sessions before generating schedule;
Fabian Huch <huch@in.tum.de>
parents:
78968
diff
changeset
|
973 |
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
|
974 |
state.ancestor_results(session_name) match { |
1b05c2b10c9f
finalize current sessions before generating schedule;
Fabian Huch <huch@in.tum.de>
parents:
78968
diff
changeset
|
975 |
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
|
976 |
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
|
977 |
|
1b05c2b10c9f
finalize current sessions before generating schedule;
Fabian Huch <huch@in.tum.de>
parents:
78968
diff
changeset
|
978 |
val input_shasum = |
1b05c2b10c9f
finalize current sessions before generating schedule;
Fabian Huch <huch@in.tum.de>
parents:
78968
diff
changeset
|
979 |
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
|
980 |
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
|
981 |
|
1b05c2b10c9f
finalize current sessions before generating schedule;
Fabian Huch <huch@in.tum.de>
parents:
78968
diff
changeset
|
982 |
val store_heap = |
1b05c2b10c9f
finalize current sessions before generating schedule;
Fabian Huch <huch@in.tum.de>
parents:
78968
diff
changeset
|
983 |
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
|
984 |
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
|
985 |
|
1b05c2b10c9f
finalize current sessions before generating schedule;
Fabian Huch <huch@in.tum.de>
parents:
78968
diff
changeset
|
986 |
store.check_output( |
1b05c2b10c9f
finalize current sessions before generating schedule;
Fabian Huch <huch@in.tum.de>
parents:
78968
diff
changeset
|
987 |
_database_server, session_name, |
1b05c2b10c9f
finalize current sessions before generating schedule;
Fabian Huch <huch@in.tum.de>
parents:
78968
diff
changeset
|
988 |
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
|
989 |
sources_shasum = sources_shasum, |
1b05c2b10c9f
finalize current sessions before generating schedule;
Fabian Huch <huch@in.tum.de>
parents:
78968
diff
changeset
|
990 |
input_shasum = input_shasum, |
1b05c2b10c9f
finalize current sessions before generating schedule;
Fabian Huch <huch@in.tum.de>
parents:
78968
diff
changeset
|
991 |
fresh_build = build_context.fresh_build, |
1b05c2b10c9f
finalize current sessions before generating schedule;
Fabian Huch <huch@in.tum.de>
parents:
78968
diff
changeset
|
992 |
store_heap = store_heap)._1 |
1b05c2b10c9f
finalize current sessions before generating schedule;
Fabian Huch <huch@in.tum.de>
parents:
78968
diff
changeset
|
993 |
case _ => false |
1b05c2b10c9f
finalize current sessions before generating schedule;
Fabian Huch <huch@in.tum.de>
parents:
78968
diff
changeset
|
994 |
} |
1b05c2b10c9f
finalize current sessions before generating schedule;
Fabian Huch <huch@in.tum.de>
parents:
78968
diff
changeset
|
995 |
|
79192
5db03f9276e2
clarified: build schedules may be outdated when empty, after some time, or due to build progress;
Fabian Huch <huch@in.tum.de>
parents:
79191
diff
changeset
|
996 |
override def next_jobs(state: Build_Process.State): List[String] = |
79290
9deadc9d8872
separate build processes for scheduler and scheduled;
Fabian Huch <huch@in.tum.de>
parents:
79289
diff
changeset
|
997 |
if (progress.stopped) state.next_ready.map(_.name) |
9deadc9d8872
separate build processes for scheduler and scheduled;
Fabian Huch <huch@in.tum.de>
parents:
79289
diff
changeset
|
998 |
else if (!_schedule.is_outdated(build_options, state)) _schedule.next(hostname, state) |
78845
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
999 |
else { |
79020
ef76705bf402
clarified ready vs. next ready;
Fabian Huch <huch@in.tum.de>
parents:
79019
diff
changeset
|
1000 |
val current = state.next_ready.filter(task => is_current(state, task.name)) |
79187 | 1001 |
if (current.nonEmpty) current.map(_.name) |
78969
1b05c2b10c9f
finalize current sessions before generating schedule;
Fabian Huch <huch@in.tum.de>
parents:
78968
diff
changeset
|
1002 |
else { |
1b05c2b10c9f
finalize current sessions before generating schedule;
Fabian Huch <huch@in.tum.de>
parents:
78968
diff
changeset
|
1003 |
val start = Time.now() |
79193
d1d6dbab2901
compare previous build schedule with new one, to prevent regressions;
Fabian Huch <huch@in.tum.de>
parents:
79192
diff
changeset
|
1004 |
|
79194
a0e8efbcf18d
consider schedule calculation time in estimation;
Fabian Huch <huch@in.tum.de>
parents:
79193
diff
changeset
|
1005 |
val new_schedule = scheduler.build_schedule(state).update(state) |
79193
d1d6dbab2901
compare previous build schedule with new one, to prevent regressions;
Fabian Huch <huch@in.tum.de>
parents:
79192
diff
changeset
|
1006 |
val schedule = |
79293 | 1007 |
if (_schedule.is_empty) new_schedule |
79193
d1d6dbab2901
compare previous build schedule with new one, to prevent regressions;
Fabian Huch <huch@in.tum.de>
parents:
79192
diff
changeset
|
1008 |
else List(_schedule.update(state), new_schedule).minBy(_.end)(Date.Ordering) |
d1d6dbab2901
compare previous build schedule with new one, to prevent regressions;
Fabian Huch <huch@in.tum.de>
parents:
79192
diff
changeset
|
1009 |
|
78969
1b05c2b10c9f
finalize current sessions before generating schedule;
Fabian Huch <huch@in.tum.de>
parents:
78968
diff
changeset
|
1010 |
val elapsed = Time.now() - start |
78884 | 1011 |
|
78976 | 1012 |
val timing_msg = if (elapsed.is_relevant) " (took " + elapsed.message + ")" else "" |
79192
5db03f9276e2
clarified: build schedules may be outdated when empty, after some time, or due to build progress;
Fabian Huch <huch@in.tum.de>
parents:
79191
diff
changeset
|
1013 |
progress.echo_if(_schedule.deviation(schedule).minutes > 1, schedule.message + timing_msg) |
78845
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
1014 |
|
79183
32d00ec387f4
use schedule directly instead of extra cache;
Fabian Huch <huch@in.tum.de>
parents:
79182
diff
changeset
|
1015 |
_schedule = schedule |
32d00ec387f4
use schedule directly instead of extra cache;
Fabian Huch <huch@in.tum.de>
parents:
79182
diff
changeset
|
1016 |
_schedule.next(hostname, state) |
78969
1b05c2b10c9f
finalize current sessions before generating schedule;
Fabian Huch <huch@in.tum.de>
parents:
78968
diff
changeset
|
1017 |
} |
78845
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
1018 |
} |
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
1019 |
|
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
1020 |
override def run(): Build.Results = { |
79527
f1f08ca40d96
make build process state protected to avoid copying in subclasses (e.g. for database connections);
Fabian Huch <huch@in.tum.de>
parents:
79502
diff
changeset
|
1021 |
Benchmark.benchmark_requirements(build_options) |
f1f08ca40d96
make build process state protected to avoid copying in subclasses (e.g. for database connections);
Fabian Huch <huch@in.tum.de>
parents:
79502
diff
changeset
|
1022 |
|
f1f08ca40d96
make build process state protected to avoid copying in subclasses (e.g. for database connections);
Fabian Huch <huch@in.tum.de>
parents:
79502
diff
changeset
|
1023 |
if (build_context.max_jobs > 0) { |
f1f08ca40d96
make build process state protected to avoid copying in subclasses (e.g. for database connections);
Fabian Huch <huch@in.tum.de>
parents:
79502
diff
changeset
|
1024 |
val benchmark_options = build_options.string("build_hostname") = hostname |
f1f08ca40d96
make build process state protected to avoid copying in subclasses (e.g. for database connections);
Fabian Huch <huch@in.tum.de>
parents:
79502
diff
changeset
|
1025 |
Benchmark.benchmark(benchmark_options, progress) |
f1f08ca40d96
make build process state protected to avoid copying in subclasses (e.g. for database connections);
Fabian Huch <huch@in.tum.de>
parents:
79502
diff
changeset
|
1026 |
} |
f1f08ca40d96
make build process state protected to avoid copying in subclasses (e.g. for database connections);
Fabian Huch <huch@in.tum.de>
parents:
79502
diff
changeset
|
1027 |
_build_cluster.benchmark() |
f1f08ca40d96
make build process state protected to avoid copying in subclasses (e.g. for database connections);
Fabian Huch <huch@in.tum.de>
parents:
79502
diff
changeset
|
1028 |
|
f1f08ca40d96
make build process state protected to avoid copying in subclasses (e.g. for database connections);
Fabian Huch <huch@in.tum.de>
parents:
79502
diff
changeset
|
1029 |
for (db <- _build_database) |
f1f08ca40d96
make build process state protected to avoid copying in subclasses (e.g. for database connections);
Fabian Huch <huch@in.tum.de>
parents:
79502
diff
changeset
|
1030 |
Build_Process.private_data.transaction_lock(db, label = "Scheduler_Build_Process.init") { |
f1f08ca40d96
make build process state protected to avoid copying in subclasses (e.g. for database connections);
Fabian Huch <huch@in.tum.de>
parents:
79502
diff
changeset
|
1031 |
Build_Process.private_data.clean_build(db) |
f1f08ca40d96
make build process state protected to avoid copying in subclasses (e.g. for database connections);
Fabian Huch <huch@in.tum.de>
parents:
79502
diff
changeset
|
1032 |
} |
f1f08ca40d96
make build process state protected to avoid copying in subclasses (e.g. for database connections);
Fabian Huch <huch@in.tum.de>
parents:
79502
diff
changeset
|
1033 |
|
78845
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
1034 |
val results = super.run() |
79290
9deadc9d8872
separate build processes for scheduler and scheduled;
Fabian Huch <huch@in.tum.de>
parents:
79289
diff
changeset
|
1035 |
write_build_log(results, snapshot().results) |
78845
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
1036 |
results |
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
1037 |
} |
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
1038 |
} |
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
1039 |
|
79186
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1040 |
|
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1041 |
/** SQL data model of build schedule, extending isabelle_build database */ |
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1042 |
|
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1043 |
object private_data extends SQL.Data("isabelle_build") { |
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1044 |
import Build_Process.private_data.{Base, Generic} |
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1045 |
|
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1046 |
|
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1047 |
/* schedule */ |
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1048 |
|
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1049 |
object Schedules { |
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1050 |
val build_uuid = Generic.build_uuid.make_primary_key |
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1051 |
val generator = SQL.Column.string("generator") |
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1052 |
val start = SQL.Column.date("start") |
79190
2039f3609884
add serial for build schedule to avoid unnecessary db read/writes;
Fabian Huch <huch@in.tum.de>
parents:
79189
diff
changeset
|
1053 |
val serial = SQL.Column.long("serial") |
79186
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1054 |
|
79190
2039f3609884
add serial for build schedule to avoid unnecessary db read/writes;
Fabian Huch <huch@in.tum.de>
parents:
79189
diff
changeset
|
1055 |
val table = make_table(List(build_uuid, generator, start, serial), name = "schedules") |
79186
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1056 |
} |
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1057 |
|
79190
2039f3609884
add serial for build schedule to avoid unnecessary db read/writes;
Fabian Huch <huch@in.tum.de>
parents:
79189
diff
changeset
|
1058 |
def read_serial(db: SQL.Database, build_uuid: String = ""): Long = |
2039f3609884
add serial for build schedule to avoid unnecessary db read/writes;
Fabian Huch <huch@in.tum.de>
parents:
79189
diff
changeset
|
1059 |
db.execute_query_statementO[Long]( |
2039f3609884
add serial for build schedule to avoid unnecessary db read/writes;
Fabian Huch <huch@in.tum.de>
parents:
79189
diff
changeset
|
1060 |
Schedules.table.select(List(Schedules.serial.max), sql = |
2039f3609884
add serial for build schedule to avoid unnecessary db read/writes;
Fabian Huch <huch@in.tum.de>
parents:
79189
diff
changeset
|
1061 |
SQL.where(if_proper(build_uuid, Schedules.build_uuid.equal(build_uuid)))), |
2039f3609884
add serial for build schedule to avoid unnecessary db read/writes;
Fabian Huch <huch@in.tum.de>
parents:
79189
diff
changeset
|
1062 |
_.long(Schedules.serial)).getOrElse(0L) |
2039f3609884
add serial for build schedule to avoid unnecessary db read/writes;
Fabian Huch <huch@in.tum.de>
parents:
79189
diff
changeset
|
1063 |
|
79186
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1064 |
def read_scheduled_builds_domain(db: SQL.Database): List[String] = |
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1065 |
db.execute_query_statement( |
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1066 |
Schedules.table.select(List(Schedules.build_uuid)), |
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1067 |
List.from[String], res => res.string(Schedules.build_uuid)) |
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1068 |
|
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1069 |
def read_schedules(db: SQL.Database, build_uuid: String = ""): List[Schedule] = { |
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1070 |
val schedules = |
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1071 |
db.execute_query_statement(Schedules.table.select(sql = |
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1072 |
SQL.where(if_proper(build_uuid, Schedules.build_uuid.equal(build_uuid)))), |
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1073 |
List.from[Schedule], |
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1074 |
{ res => |
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1075 |
val build_uuid = res.string(Schedules.build_uuid) |
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1076 |
val generator = res.string(Schedules.generator) |
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1077 |
val start = res.date(Schedules.start) |
79287
b88b6ed06334
read serial for schedules (amending 2039f360);
Fabian Huch <huch@in.tum.de>
parents:
79236
diff
changeset
|
1078 |
val serial = res.long(Schedules.serial) |
b88b6ed06334
read serial for schedules (amending 2039f360);
Fabian Huch <huch@in.tum.de>
parents:
79236
diff
changeset
|
1079 |
Schedule(build_uuid, generator, start, Graph.empty, serial) |
79186
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1080 |
}) |
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1081 |
|
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1082 |
for (schedule <- schedules.sortBy(_.start)(Date.Ordering)) yield { |
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1083 |
val nodes = private_data.read_nodes(db, build_uuid = schedule.build_uuid) |
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1084 |
schedule.copy(graph = Graph.make(nodes)) |
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1085 |
} |
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1086 |
} |
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1087 |
|
79190
2039f3609884
add serial for build schedule to avoid unnecessary db read/writes;
Fabian Huch <huch@in.tum.de>
parents:
79189
diff
changeset
|
1088 |
def write_schedule(db: SQL.Database, schedule: Schedule): Unit = { |
79186
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1089 |
db.execute_statement( |
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1090 |
Schedules.table.delete(Schedules.build_uuid.where_equal(schedule.build_uuid))) |
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1091 |
db.execute_statement(Schedules.table.insert(), { stmt => |
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1092 |
stmt.string(1) = schedule.build_uuid |
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1093 |
stmt.string(2) = schedule.generator |
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1094 |
stmt.date(3) = schedule.start |
79190
2039f3609884
add serial for build schedule to avoid unnecessary db read/writes;
Fabian Huch <huch@in.tum.de>
parents:
79189
diff
changeset
|
1095 |
stmt.long(4) = schedule.serial |
79186
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1096 |
}) |
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1097 |
update_nodes(db, schedule.build_uuid, schedule.graph.dest) |
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1098 |
} |
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1099 |
|
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1100 |
|
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1101 |
/* nodes */ |
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1102 |
|
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1103 |
object Nodes { |
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1104 |
val build_uuid = Generic.build_uuid.make_primary_key |
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1105 |
val name = Generic.name.make_primary_key |
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1106 |
val succs = SQL.Column.string("succs") |
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1107 |
val hostname = SQL.Column.string("hostname") |
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1108 |
val numa_node = SQL.Column.int("numa_node") |
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1109 |
val rel_cpus = SQL.Column.string("rel_cpus") |
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1110 |
val start = SQL.Column.date("start") |
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1111 |
val duration = SQL.Column.long("duration") |
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1112 |
|
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1113 |
val table = |
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1114 |
make_table( |
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1115 |
List(build_uuid, name, succs, hostname, numa_node, rel_cpus, start, duration), |
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1116 |
name = "schedule_nodes") |
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1117 |
} |
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1118 |
|
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1119 |
type Nodes = List[((String, Schedule.Node), List[String])] |
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1120 |
|
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1121 |
def read_nodes(db: SQL.Database, build_uuid: String = ""): Nodes = { |
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1122 |
db.execute_query_statement( |
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1123 |
Nodes.table.select(sql = |
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1124 |
SQL.where(if_proper(build_uuid, Nodes.build_uuid.equal(build_uuid)))), |
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1125 |
List.from[((String, Schedule.Node), List[String])], |
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1126 |
{ res => |
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1127 |
val name = res.string(Nodes.name) |
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1128 |
val succs = split_lines(res.string(Nodes.succs)) |
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1129 |
val hostname = res.string(Nodes.hostname) |
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1130 |
val numa_node = res.get_int(Nodes.numa_node) |
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1131 |
val rel_cpus = res.string(Nodes.rel_cpus) |
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1132 |
val start = res.date(Nodes.start) |
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1133 |
val duration = Time.ms(res.long(Nodes.duration)) |
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1134 |
|
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1135 |
val node_info = Node_Info(hostname, numa_node, isabelle.Host.Range.from(rel_cpus)) |
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1136 |
((name, Schedule.Node(name, node_info, start, duration)), succs) |
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1137 |
} |
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1138 |
) |
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1139 |
} |
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1140 |
|
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1141 |
def update_nodes(db: SQL.Database, build_uuid: String, nodes: Nodes): Unit = { |
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1142 |
db.execute_statement(Nodes.table.delete(Nodes.build_uuid.where_equal(build_uuid))) |
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1143 |
db.execute_batch_statement(Nodes.table.insert(), batch = |
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1144 |
for (((name, node), succs) <- nodes) yield { (stmt: SQL.Statement) => |
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1145 |
stmt.string(1) = build_uuid |
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1146 |
stmt.string(2) = name |
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1147 |
stmt.string(3) = cat_lines(succs) |
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1148 |
stmt.string(4) = node.node_info.hostname |
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1149 |
stmt.int(5) = node.node_info.numa_node |
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1150 |
stmt.string(6) = isabelle.Host.Range(node.node_info.rel_cpus) |
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1151 |
stmt.date(7) = node.start |
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1152 |
stmt.long(8) = node.duration.ms |
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1153 |
}) |
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1154 |
} |
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1155 |
|
79190
2039f3609884
add serial for build schedule to avoid unnecessary db read/writes;
Fabian Huch <huch@in.tum.de>
parents:
79189
diff
changeset
|
1156 |
def pull_schedule(db: SQL.Database, old_schedule: Schedule): Build_Schedule.Schedule = { |
2039f3609884
add serial for build schedule to avoid unnecessary db read/writes;
Fabian Huch <huch@in.tum.de>
parents:
79189
diff
changeset
|
1157 |
val serial_db = read_serial(db) |
2039f3609884
add serial for build schedule to avoid unnecessary db read/writes;
Fabian Huch <huch@in.tum.de>
parents:
79189
diff
changeset
|
1158 |
if (serial_db == old_schedule.serial) old_schedule |
2039f3609884
add serial for build schedule to avoid unnecessary db read/writes;
Fabian Huch <huch@in.tum.de>
parents:
79189
diff
changeset
|
1159 |
else { |
2039f3609884
add serial for build schedule to avoid unnecessary db read/writes;
Fabian Huch <huch@in.tum.de>
parents:
79189
diff
changeset
|
1160 |
read_schedules(db, old_schedule.build_uuid) match { |
2039f3609884
add serial for build schedule to avoid unnecessary db read/writes;
Fabian Huch <huch@in.tum.de>
parents:
79189
diff
changeset
|
1161 |
case Nil => old_schedule |
2039f3609884
add serial for build schedule to avoid unnecessary db read/writes;
Fabian Huch <huch@in.tum.de>
parents:
79189
diff
changeset
|
1162 |
case schedules => Library.the_single(schedules) |
2039f3609884
add serial for build schedule to avoid unnecessary db read/writes;
Fabian Huch <huch@in.tum.de>
parents:
79189
diff
changeset
|
1163 |
} |
79186
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1164 |
} |
79190
2039f3609884
add serial for build schedule to avoid unnecessary db read/writes;
Fabian Huch <huch@in.tum.de>
parents:
79189
diff
changeset
|
1165 |
} |
2039f3609884
add serial for build schedule to avoid unnecessary db read/writes;
Fabian Huch <huch@in.tum.de>
parents:
79189
diff
changeset
|
1166 |
|
2039f3609884
add serial for build schedule to avoid unnecessary db read/writes;
Fabian Huch <huch@in.tum.de>
parents:
79189
diff
changeset
|
1167 |
def update_schedule(db: SQL.Database, schedule: Schedule, old_schedule: Schedule): Schedule = { |
2039f3609884
add serial for build schedule to avoid unnecessary db read/writes;
Fabian Huch <huch@in.tum.de>
parents:
79189
diff
changeset
|
1168 |
val changed = |
2039f3609884
add serial for build schedule to avoid unnecessary db read/writes;
Fabian Huch <huch@in.tum.de>
parents:
79189
diff
changeset
|
1169 |
schedule.generator != old_schedule.generator || |
2039f3609884
add serial for build schedule to avoid unnecessary db read/writes;
Fabian Huch <huch@in.tum.de>
parents:
79189
diff
changeset
|
1170 |
schedule.start != old_schedule.start || |
2039f3609884
add serial for build schedule to avoid unnecessary db read/writes;
Fabian Huch <huch@in.tum.de>
parents:
79189
diff
changeset
|
1171 |
schedule.graph != old_schedule.graph |
2039f3609884
add serial for build schedule to avoid unnecessary db read/writes;
Fabian Huch <huch@in.tum.de>
parents:
79189
diff
changeset
|
1172 |
|
2039f3609884
add serial for build schedule to avoid unnecessary db read/writes;
Fabian Huch <huch@in.tum.de>
parents:
79189
diff
changeset
|
1173 |
val schedule1 = |
2039f3609884
add serial for build schedule to avoid unnecessary db read/writes;
Fabian Huch <huch@in.tum.de>
parents:
79189
diff
changeset
|
1174 |
if (changed) schedule.copy(serial = old_schedule.serial).inc_serial else schedule |
2039f3609884
add serial for build schedule to avoid unnecessary db read/writes;
Fabian Huch <huch@in.tum.de>
parents:
79189
diff
changeset
|
1175 |
if (schedule1.serial != schedule.serial) write_schedule(db, schedule1) |
2039f3609884
add serial for build schedule to avoid unnecessary db read/writes;
Fabian Huch <huch@in.tum.de>
parents:
79189
diff
changeset
|
1176 |
|
2039f3609884
add serial for build schedule to avoid unnecessary db read/writes;
Fabian Huch <huch@in.tum.de>
parents:
79189
diff
changeset
|
1177 |
schedule1 |
2039f3609884
add serial for build schedule to avoid unnecessary db read/writes;
Fabian Huch <huch@in.tum.de>
parents:
79189
diff
changeset
|
1178 |
} |
79186
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1179 |
|
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1180 |
def remove_schedules(db: SQL.Database, remove: List[String]): Unit = |
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1181 |
if (remove.nonEmpty) { |
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1182 |
val sql = Generic.build_uuid.where_member(remove) |
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1183 |
db.execute_statement(SQL.MULTI(tables.map(_.delete(sql = sql)))) |
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1184 |
} |
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1185 |
|
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1186 |
def clean_build_schedules(db: SQL.Database): Unit = { |
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1187 |
val running_builds_domain = |
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1188 |
db.execute_query_statement( |
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1189 |
Base.table.select(List(Base.build_uuid), sql = SQL.where(Base.stop.undefined)), |
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1190 |
List.from[String], res => res.string(Base.build_uuid)) |
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1191 |
|
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1192 |
val (remove, _) = |
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1193 |
Library.symmetric_difference(read_scheduled_builds_domain(db), running_builds_domain) |
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1194 |
|
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1195 |
remove_schedules(db, remove) |
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1196 |
} |
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1197 |
|
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1198 |
override val tables = SQL.Tables(Schedules.table, Nodes.table) |
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1199 |
} |
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1200 |
|
a22440b9cb70
use build database to synchronize build schedule computed on master node (e.g., such that view on cluster is consistent);
Fabian Huch <huch@in.tum.de>
parents:
79185
diff
changeset
|
1201 |
|
79089 | 1202 |
class Engine extends Build.Engine("build_schedule") { |
1203 |
||
79108 | 1204 |
def scheduler(timing_data: Timing_Data, context: Build.Context): Scheduler = { |
1205 |
val sessions_structure = context.sessions_structure |
|
79110
ff68cbfa3550
clarified path time heuristic: configurable parameters for larger search space;
Fabian Huch <huch@in.tum.de>
parents:
79109
diff
changeset
|
1206 |
|
ff68cbfa3550
clarified path time heuristic: configurable parameters for larger search space;
Fabian Huch <huch@in.tum.de>
parents:
79109
diff
changeset
|
1207 |
val is_criticals = |
ff68cbfa3550
clarified path time heuristic: configurable parameters for larger search space;
Fabian Huch <huch@in.tum.de>
parents:
79109
diff
changeset
|
1208 |
List( |
ff68cbfa3550
clarified path time heuristic: configurable parameters for larger search space;
Fabian Huch <huch@in.tum.de>
parents:
79109
diff
changeset
|
1209 |
Path_Time_Heuristic.Absolute_Time(Time.minutes(5)), |
ff68cbfa3550
clarified path time heuristic: configurable parameters for larger search space;
Fabian Huch <huch@in.tum.de>
parents:
79109
diff
changeset
|
1210 |
Path_Time_Heuristic.Absolute_Time(Time.minutes(10)), |
ff68cbfa3550
clarified path time heuristic: configurable parameters for larger search space;
Fabian Huch <huch@in.tum.de>
parents:
79109
diff
changeset
|
1211 |
Path_Time_Heuristic.Absolute_Time(Time.minutes(20)), |
ff68cbfa3550
clarified path time heuristic: configurable parameters for larger search space;
Fabian Huch <huch@in.tum.de>
parents:
79109
diff
changeset
|
1212 |
Path_Time_Heuristic.Relative_Time(0.5)) |
ff68cbfa3550
clarified path time heuristic: configurable parameters for larger search space;
Fabian Huch <huch@in.tum.de>
parents:
79109
diff
changeset
|
1213 |
val parallel_threads = |
ff68cbfa3550
clarified path time heuristic: configurable parameters for larger search space;
Fabian Huch <huch@in.tum.de>
parents:
79109
diff
changeset
|
1214 |
List( |
ff68cbfa3550
clarified path time heuristic: configurable parameters for larger search space;
Fabian Huch <huch@in.tum.de>
parents:
79109
diff
changeset
|
1215 |
Path_Time_Heuristic.Fixed_Thread(1), |
ff68cbfa3550
clarified path time heuristic: configurable parameters for larger search space;
Fabian Huch <huch@in.tum.de>
parents:
79109
diff
changeset
|
1216 |
Path_Time_Heuristic.Time_Based_Threads({ |
ff68cbfa3550
clarified path time heuristic: configurable parameters for larger search space;
Fabian Huch <huch@in.tum.de>
parents:
79109
diff
changeset
|
1217 |
case time if time < Time.minutes(1) => 1 |
ff68cbfa3550
clarified path time heuristic: configurable parameters for larger search space;
Fabian Huch <huch@in.tum.de>
parents:
79109
diff
changeset
|
1218 |
case time if time < Time.minutes(5) => 4 |
ff68cbfa3550
clarified path time heuristic: configurable parameters for larger search space;
Fabian Huch <huch@in.tum.de>
parents:
79109
diff
changeset
|
1219 |
case _ => 8 |
ff68cbfa3550
clarified path time heuristic: configurable parameters for larger search space;
Fabian Huch <huch@in.tum.de>
parents:
79109
diff
changeset
|
1220 |
})) |
79180
229f49204603
clarified build heuristics parameters;
Fabian Huch <huch@in.tum.de>
parents:
79179
diff
changeset
|
1221 |
val machine_splits = |
229f49204603
clarified build heuristics parameters;
Fabian Huch <huch@in.tum.de>
parents:
79179
diff
changeset
|
1222 |
List( |
229f49204603
clarified build heuristics parameters;
Fabian Huch <huch@in.tum.de>
parents:
79179
diff
changeset
|
1223 |
Path_Time_Heuristic.Critical_Nodes, |
229f49204603
clarified build heuristics parameters;
Fabian Huch <huch@in.tum.de>
parents:
79179
diff
changeset
|
1224 |
Path_Time_Heuristic.Fixed_Fraction(0.3), |
229f49204603
clarified build heuristics parameters;
Fabian Huch <huch@in.tum.de>
parents:
79179
diff
changeset
|
1225 |
Path_Time_Heuristic.Host_Speed(0.9)) |
79110
ff68cbfa3550
clarified path time heuristic: configurable parameters for larger search space;
Fabian Huch <huch@in.tum.de>
parents:
79109
diff
changeset
|
1226 |
|
ff68cbfa3550
clarified path time heuristic: configurable parameters for larger search space;
Fabian Huch <huch@in.tum.de>
parents:
79109
diff
changeset
|
1227 |
val path_time_heuristics = |
ff68cbfa3550
clarified path time heuristic: configurable parameters for larger search space;
Fabian Huch <huch@in.tum.de>
parents:
79109
diff
changeset
|
1228 |
for { |
ff68cbfa3550
clarified path time heuristic: configurable parameters for larger search space;
Fabian Huch <huch@in.tum.de>
parents:
79109
diff
changeset
|
1229 |
is_critical <- is_criticals |
ff68cbfa3550
clarified path time heuristic: configurable parameters for larger search space;
Fabian Huch <huch@in.tum.de>
parents:
79109
diff
changeset
|
1230 |
parallel <- parallel_threads |
79180
229f49204603
clarified build heuristics parameters;
Fabian Huch <huch@in.tum.de>
parents:
79179
diff
changeset
|
1231 |
machine_split <- machine_splits |
229f49204603
clarified build heuristics parameters;
Fabian Huch <huch@in.tum.de>
parents:
79179
diff
changeset
|
1232 |
} yield |
79185 | 1233 |
Path_Time_Heuristic(is_critical, parallel, machine_split, timing_data, sessions_structure, |
1234 |
context.build_uuid) |
|
1235 |
val default_heuristic = |
|
1236 |
Default_Heuristic(timing_data, context.build_options, context.build_uuid) |
|
1237 |
new Meta_Heuristic(default_heuristic :: path_time_heuristics) |
|
79089 | 1238 |
} |
1239 |
||
78845
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
1240 |
override def open_build_process( |
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
1241 |
context: Build.Context, |
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
1242 |
progress: Progress, |
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
1243 |
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
|
1244 |
): Build_Process = |
79290
9deadc9d8872
separate build processes for scheduler and scheduled;
Fabian Huch <huch@in.tum.de>
parents:
79289
diff
changeset
|
1245 |
if (!context.master) new Scheduled_Build_Process(context, progress, server) |
9deadc9d8872
separate build processes for scheduler and scheduled;
Fabian Huch <huch@in.tum.de>
parents:
79289
diff
changeset
|
1246 |
else new Scheduler_Build_Process(context, progress, server) { |
79108 | 1247 |
def init_scheduler(timing_data: Timing_Data): Scheduler = scheduler(timing_data, context) |
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
|
1248 |
} |
78845
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
1249 |
} |
79091
06f380099b2e
added method to generate build schedules directly;
Fabian Huch <huch@in.tum.de>
parents:
79090
diff
changeset
|
1250 |
|
06f380099b2e
added method to generate build schedules directly;
Fabian Huch <huch@in.tum.de>
parents:
79090
diff
changeset
|
1251 |
|
06f380099b2e
added method to generate build schedules directly;
Fabian Huch <huch@in.tum.de>
parents:
79090
diff
changeset
|
1252 |
/* build schedule */ |
06f380099b2e
added method to generate build schedules directly;
Fabian Huch <huch@in.tum.de>
parents:
79090
diff
changeset
|
1253 |
|
06f380099b2e
added method to generate build schedules directly;
Fabian Huch <huch@in.tum.de>
parents:
79090
diff
changeset
|
1254 |
def build_schedule( |
06f380099b2e
added method to generate build schedules directly;
Fabian Huch <huch@in.tum.de>
parents:
79090
diff
changeset
|
1255 |
options: Options, |
06f380099b2e
added method to generate build schedules directly;
Fabian Huch <huch@in.tum.de>
parents:
79090
diff
changeset
|
1256 |
build_hosts: List[Build_Cluster.Host] = Nil, |
06f380099b2e
added method to generate build schedules directly;
Fabian Huch <huch@in.tum.de>
parents:
79090
diff
changeset
|
1257 |
selection: Sessions.Selection = Sessions.Selection.empty, |
06f380099b2e
added method to generate build schedules directly;
Fabian Huch <huch@in.tum.de>
parents:
79090
diff
changeset
|
1258 |
progress: Progress = new Progress, |
06f380099b2e
added method to generate build schedules directly;
Fabian Huch <huch@in.tum.de>
parents:
79090
diff
changeset
|
1259 |
afp_root: Option[Path] = None, |
06f380099b2e
added method to generate build schedules directly;
Fabian Huch <huch@in.tum.de>
parents:
79090
diff
changeset
|
1260 |
dirs: List[Path] = Nil, |
06f380099b2e
added method to generate build schedules directly;
Fabian Huch <huch@in.tum.de>
parents:
79090
diff
changeset
|
1261 |
select_dirs: List[Path] = Nil, |
06f380099b2e
added method to generate build schedules directly;
Fabian Huch <huch@in.tum.de>
parents:
79090
diff
changeset
|
1262 |
infos: List[Sessions.Info] = Nil, |
06f380099b2e
added method to generate build schedules directly;
Fabian Huch <huch@in.tum.de>
parents:
79090
diff
changeset
|
1263 |
numa_shuffling: Boolean = false, |
06f380099b2e
added method to generate build schedules directly;
Fabian Huch <huch@in.tum.de>
parents:
79090
diff
changeset
|
1264 |
augment_options: String => List[Options.Spec] = _ => Nil, |
06f380099b2e
added method to generate build schedules directly;
Fabian Huch <huch@in.tum.de>
parents:
79090
diff
changeset
|
1265 |
session_setup: (String, Session) => Unit = (_, _) => (), |
06f380099b2e
added method to generate build schedules directly;
Fabian Huch <huch@in.tum.de>
parents:
79090
diff
changeset
|
1266 |
cache: Term.Cache = Term.Cache.make() |
06f380099b2e
added method to generate build schedules directly;
Fabian Huch <huch@in.tum.de>
parents:
79090
diff
changeset
|
1267 |
): Schedule = { |
06f380099b2e
added method to generate build schedules directly;
Fabian Huch <huch@in.tum.de>
parents:
79090
diff
changeset
|
1268 |
val build_engine = new Engine |
06f380099b2e
added method to generate build schedules directly;
Fabian Huch <huch@in.tum.de>
parents:
79090
diff
changeset
|
1269 |
|
06f380099b2e
added method to generate build schedules directly;
Fabian Huch <huch@in.tum.de>
parents:
79090
diff
changeset
|
1270 |
val store = build_engine.build_store(options, build_hosts = build_hosts, cache = cache) |
06f380099b2e
added method to generate build schedules directly;
Fabian Huch <huch@in.tum.de>
parents:
79090
diff
changeset
|
1271 |
val log_store = Build_Log.store(options, cache = cache) |
06f380099b2e
added method to generate build schedules directly;
Fabian Huch <huch@in.tum.de>
parents:
79090
diff
changeset
|
1272 |
val build_options = store.options |
06f380099b2e
added method to generate build schedules directly;
Fabian Huch <huch@in.tum.de>
parents:
79090
diff
changeset
|
1273 |
|
06f380099b2e
added method to generate build schedules directly;
Fabian Huch <huch@in.tum.de>
parents:
79090
diff
changeset
|
1274 |
def build_schedule( |
06f380099b2e
added method to generate build schedules directly;
Fabian Huch <huch@in.tum.de>
parents:
79090
diff
changeset
|
1275 |
server: SSH.Server, |
06f380099b2e
added method to generate build schedules directly;
Fabian Huch <huch@in.tum.de>
parents:
79090
diff
changeset
|
1276 |
database_server: Option[SQL.Database], |
06f380099b2e
added method to generate build schedules directly;
Fabian Huch <huch@in.tum.de>
parents:
79090
diff
changeset
|
1277 |
log_database: PostgreSQL.Database, |
06f380099b2e
added method to generate build schedules directly;
Fabian Huch <huch@in.tum.de>
parents:
79090
diff
changeset
|
1278 |
host_database: SQL.Database |
06f380099b2e
added method to generate build schedules directly;
Fabian Huch <huch@in.tum.de>
parents:
79090
diff
changeset
|
1279 |
): Schedule = { |
06f380099b2e
added method to generate build schedules directly;
Fabian Huch <huch@in.tum.de>
parents:
79090
diff
changeset
|
1280 |
val full_sessions = |
06f380099b2e
added method to generate build schedules directly;
Fabian Huch <huch@in.tum.de>
parents:
79090
diff
changeset
|
1281 |
Sessions.load_structure(build_options, dirs = AFP.make_dirs(afp_root) ::: dirs, |
06f380099b2e
added method to generate build schedules directly;
Fabian Huch <huch@in.tum.de>
parents:
79090
diff
changeset
|
1282 |
select_dirs = select_dirs, infos = infos, augment_options = augment_options) |
06f380099b2e
added method to generate build schedules directly;
Fabian Huch <huch@in.tum.de>
parents:
79090
diff
changeset
|
1283 |
val full_sessions_selection = full_sessions.imports_selection(selection) |
06f380099b2e
added method to generate build schedules directly;
Fabian Huch <huch@in.tum.de>
parents:
79090
diff
changeset
|
1284 |
|
06f380099b2e
added method to generate build schedules directly;
Fabian Huch <huch@in.tum.de>
parents:
79090
diff
changeset
|
1285 |
val build_deps = |
06f380099b2e
added method to generate build schedules directly;
Fabian Huch <huch@in.tum.de>
parents:
79090
diff
changeset
|
1286 |
Sessions.deps(full_sessions.selection(selection), progress = progress, |
06f380099b2e
added method to generate build schedules directly;
Fabian Huch <huch@in.tum.de>
parents:
79090
diff
changeset
|
1287 |
inlined_files = true).check_errors |
06f380099b2e
added method to generate build schedules directly;
Fabian Huch <huch@in.tum.de>
parents:
79090
diff
changeset
|
1288 |
|
06f380099b2e
added method to generate build schedules directly;
Fabian Huch <huch@in.tum.de>
parents:
79090
diff
changeset
|
1289 |
val build_context = |
06f380099b2e
added method to generate build schedules directly;
Fabian Huch <huch@in.tum.de>
parents:
79090
diff
changeset
|
1290 |
Build.Context(store, build_engine, build_deps, afp_root = afp_root, |
06f380099b2e
added method to generate build schedules directly;
Fabian Huch <huch@in.tum.de>
parents:
79090
diff
changeset
|
1291 |
build_hosts = build_hosts, hostname = Build.hostname(build_options), |
06f380099b2e
added method to generate build schedules directly;
Fabian Huch <huch@in.tum.de>
parents:
79090
diff
changeset
|
1292 |
numa_shuffling = numa_shuffling, max_jobs = 0, session_setup = session_setup, |
06f380099b2e
added method to generate build schedules directly;
Fabian Huch <huch@in.tum.de>
parents:
79090
diff
changeset
|
1293 |
master = true) |
06f380099b2e
added method to generate build schedules directly;
Fabian Huch <huch@in.tum.de>
parents:
79090
diff
changeset
|
1294 |
|
06f380099b2e
added method to generate build schedules directly;
Fabian Huch <huch@in.tum.de>
parents:
79090
diff
changeset
|
1295 |
val cluster_hosts = build_context.build_hosts |
06f380099b2e
added method to generate build schedules directly;
Fabian Huch <huch@in.tum.de>
parents:
79090
diff
changeset
|
1296 |
|
06f380099b2e
added method to generate build schedules directly;
Fabian Huch <huch@in.tum.de>
parents:
79090
diff
changeset
|
1297 |
val hosts_current = |
06f380099b2e
added method to generate build schedules directly;
Fabian Huch <huch@in.tum.de>
parents:
79090
diff
changeset
|
1298 |
cluster_hosts.forall(host => isabelle.Host.read_info(host_database, host.name).isDefined) |
06f380099b2e
added method to generate build schedules directly;
Fabian Huch <huch@in.tum.de>
parents:
79090
diff
changeset
|
1299 |
if (!hosts_current) { |
06f380099b2e
added method to generate build schedules directly;
Fabian Huch <huch@in.tum.de>
parents:
79090
diff
changeset
|
1300 |
val build_cluster = Build_Cluster.make(build_context, progress = progress) |
06f380099b2e
added method to generate build schedules directly;
Fabian Huch <huch@in.tum.de>
parents:
79090
diff
changeset
|
1301 |
build_cluster.open() |
06f380099b2e
added method to generate build schedules directly;
Fabian Huch <huch@in.tum.de>
parents:
79090
diff
changeset
|
1302 |
build_cluster.init() |
06f380099b2e
added method to generate build schedules directly;
Fabian Huch <huch@in.tum.de>
parents:
79090
diff
changeset
|
1303 |
build_cluster.benchmark() |
06f380099b2e
added method to generate build schedules directly;
Fabian Huch <huch@in.tum.de>
parents:
79090
diff
changeset
|
1304 |
build_cluster.close() |
06f380099b2e
added method to generate build schedules directly;
Fabian Huch <huch@in.tum.de>
parents:
79090
diff
changeset
|
1305 |
} |
06f380099b2e
added method to generate build schedules directly;
Fabian Huch <huch@in.tum.de>
parents:
79090
diff
changeset
|
1306 |
|
06f380099b2e
added method to generate build schedules directly;
Fabian Huch <huch@in.tum.de>
parents:
79090
diff
changeset
|
1307 |
val host_infos = Host_Infos.load(cluster_hosts, host_database) |
06f380099b2e
added method to generate build schedules directly;
Fabian Huch <huch@in.tum.de>
parents:
79090
diff
changeset
|
1308 |
val timing_data = Timing_Data.load(host_infos, log_database) |
06f380099b2e
added method to generate build schedules directly;
Fabian Huch <huch@in.tum.de>
parents:
79090
diff
changeset
|
1309 |
|
06f380099b2e
added method to generate build schedules directly;
Fabian Huch <huch@in.tum.de>
parents:
79090
diff
changeset
|
1310 |
val sessions = Build_Process.Sessions.empty.init(build_context, database_server, progress) |
06f380099b2e
added method to generate build schedules directly;
Fabian Huch <huch@in.tum.de>
parents:
79090
diff
changeset
|
1311 |
def task(session: Build_Job.Session_Context): Build_Process.Task = |
06f380099b2e
added method to generate build schedules directly;
Fabian Huch <huch@in.tum.de>
parents:
79090
diff
changeset
|
1312 |
Build_Process.Task(session.name, session.deps, JSON.Object.empty, build_context.build_uuid) |
06f380099b2e
added method to generate build schedules directly;
Fabian Huch <huch@in.tum.de>
parents:
79090
diff
changeset
|
1313 |
|
06f380099b2e
added method to generate build schedules directly;
Fabian Huch <huch@in.tum.de>
parents:
79090
diff
changeset
|
1314 |
val build_state = |
06f380099b2e
added method to generate build schedules directly;
Fabian Huch <huch@in.tum.de>
parents:
79090
diff
changeset
|
1315 |
Build_Process.State(sessions = sessions, pending = sessions.iterator.map(task).toList) |
06f380099b2e
added method to generate build schedules directly;
Fabian Huch <huch@in.tum.de>
parents:
79090
diff
changeset
|
1316 |
|
79108 | 1317 |
val scheduler = build_engine.scheduler(timing_data, build_context) |
79105 | 1318 |
def schedule_msg(res: Exn.Result[Schedule]): String = |
1319 |
res match { case Exn.Res(schedule) => schedule.message case _ => "" } |
|
1320 |
||
1321 |
Timing.timeit(scheduler.build_schedule(build_state), schedule_msg, output = progress.echo(_)) |
|
79091
06f380099b2e
added method to generate build schedules directly;
Fabian Huch <huch@in.tum.de>
parents:
79090
diff
changeset
|
1322 |
} |
06f380099b2e
added method to generate build schedules directly;
Fabian Huch <huch@in.tum.de>
parents:
79090
diff
changeset
|
1323 |
|
06f380099b2e
added method to generate build schedules directly;
Fabian Huch <huch@in.tum.de>
parents:
79090
diff
changeset
|
1324 |
using(store.open_server()) { server => |
06f380099b2e
added method to generate build schedules directly;
Fabian Huch <huch@in.tum.de>
parents:
79090
diff
changeset
|
1325 |
using_optional(store.maybe_open_database_server(server = server)) { database_server => |
06f380099b2e
added method to generate build schedules directly;
Fabian Huch <huch@in.tum.de>
parents:
79090
diff
changeset
|
1326 |
using(log_store.open_database(server = server)) { log_database => |
06f380099b2e
added method to generate build schedules directly;
Fabian Huch <huch@in.tum.de>
parents:
79090
diff
changeset
|
1327 |
using(store.open_build_database( |
06f380099b2e
added method to generate build schedules directly;
Fabian Huch <huch@in.tum.de>
parents:
79090
diff
changeset
|
1328 |
path = isabelle.Host.private_data.database, server = server)) { host_database => |
06f380099b2e
added method to generate build schedules directly;
Fabian Huch <huch@in.tum.de>
parents:
79090
diff
changeset
|
1329 |
build_schedule(server, database_server, log_database, host_database) |
06f380099b2e
added method to generate build schedules directly;
Fabian Huch <huch@in.tum.de>
parents:
79090
diff
changeset
|
1330 |
} |
06f380099b2e
added method to generate build schedules directly;
Fabian Huch <huch@in.tum.de>
parents:
79090
diff
changeset
|
1331 |
} |
06f380099b2e
added method to generate build schedules directly;
Fabian Huch <huch@in.tum.de>
parents:
79090
diff
changeset
|
1332 |
} |
06f380099b2e
added method to generate build schedules directly;
Fabian Huch <huch@in.tum.de>
parents:
79090
diff
changeset
|
1333 |
} |
06f380099b2e
added method to generate build schedules directly;
Fabian Huch <huch@in.tum.de>
parents:
79090
diff
changeset
|
1334 |
} |
79181
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1335 |
|
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1336 |
def write_schedule_graphic(schedule: Schedule, output: Path): Unit = { |
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1337 |
import java.awt.geom.{GeneralPath, Rectangle2D} |
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1338 |
import java.awt.{BasicStroke, Color, Graphics2D} |
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1339 |
|
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1340 |
val line_height = isabelle.graphview.Metrics.default.height |
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1341 |
val char_width = isabelle.graphview.Metrics.default.char_width |
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1342 |
val padding = isabelle.graphview.Metrics.default.space_width |
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1343 |
val gap = isabelle.graphview.Metrics.default.gap |
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1344 |
|
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1345 |
val graph = schedule.graph |
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1346 |
|
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1347 |
def text_width(text: String): Double = text.length * char_width |
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1348 |
|
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1349 |
val generator_height = line_height + padding |
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1350 |
val hostname_height = generator_height + line_height + padding |
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1351 |
def time_height(time: Time): Double = time.seconds |
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1352 |
def date_height(date: Date): Double = time_height(date.time - schedule.start.time) |
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1353 |
|
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1354 |
val hosts = graph.iterator.map(_._2._1).toList.groupBy(_.node_info.hostname) |
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1355 |
|
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1356 |
def node_width(node: Schedule.Node): Double = 2 * padding + text_width(node.job_name) |
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1357 |
|
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1358 |
case class Range(start: Double, stop: Double) { |
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1359 |
def proper: List[Range] = if (start < stop) List(this) else Nil |
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1360 |
def width: Double = stop - start |
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1361 |
} |
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1362 |
|
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1363 |
val rel_node_ranges = |
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1364 |
hosts.toList.flatMap { (hostname, nodes) => |
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1365 |
val sorted = nodes.sortBy(node => (node.start.time.ms, node.end.time.ms, node.job_name)) |
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1366 |
sorted.foldLeft((List.empty[Schedule.Node], Map.empty[Schedule.Node, Range])) { |
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1367 |
case ((nodes, allocated), node) => |
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1368 |
val width = node_width(node) + padding |
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1369 |
val parallel = nodes.filter(_.end.time > node.start.time) |
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1370 |
val (last, slots) = |
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1371 |
parallel.sortBy(allocated(_).start).foldLeft((0D, List.empty[Range])) { |
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1372 |
case ((start, ranges), node1) => |
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1373 |
val node_range = allocated(node1) |
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1374 |
(node_range.stop, ranges ::: Range(start, node_range.start).proper) |
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1375 |
} |
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1376 |
val start = |
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1377 |
(Range(last, Double.MaxValue) :: slots.filter(_.width >= width)).minBy(_.width).start |
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1378 |
(node :: parallel, allocated + (node -> Range(start, start + width))) |
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1379 |
}._2 |
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1380 |
}.toMap |
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1381 |
|
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1382 |
def host_width(hostname: String) = |
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1383 |
2 * padding + (hosts(hostname).map(rel_node_ranges(_).stop).max max text_width(hostname)) |
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1384 |
|
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1385 |
def graph_height(graph: Graph[String, Schedule.Node]): Double = |
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1386 |
date_height(graph.maximals.map(graph.get_node(_).end).maxBy(_.unix_epoch)) |
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1387 |
|
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1388 |
val height = (hostname_height + 2 * padding + graph_height(graph)).ceil.toInt |
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1389 |
val (last, host_starts) = |
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1390 |
hosts.keys.foldLeft((0D, Map.empty[String, Double])) { |
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1391 |
case ((previous, starts), hostname) => |
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1392 |
(previous + gap + host_width(hostname), starts + (hostname -> previous)) |
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1393 |
} |
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1394 |
val width = (last - gap).ceil.toInt |
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1395 |
|
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1396 |
def node_start(node: Schedule.Node): Double = |
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1397 |
host_starts(node.node_info.hostname) + padding + rel_node_ranges(node).start |
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1398 |
|
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1399 |
def paint(gfx: Graphics2D): Unit = { |
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1400 |
gfx.setColor(Color.LIGHT_GRAY) |
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1401 |
gfx.fillRect(0, 0, width, height) |
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1402 |
gfx.setRenderingHints(isabelle.graphview.Metrics.rendering_hints) |
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1403 |
gfx.setFont(isabelle.graphview.Metrics.default.font) |
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1404 |
gfx.setStroke(new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND)) |
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1405 |
|
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1406 |
draw_string(schedule.generator + ", build time: " + schedule.duration.message_hms, padding, 0) |
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1407 |
|
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1408 |
def draw_host(x: Double, hostname: String): Double = { |
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1409 |
val nodes = hosts(hostname).map(_.job_name).toSet |
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1410 |
val width = host_width(hostname) |
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1411 |
val height = 2 * padding + graph_height(graph.restrict(nodes.contains)) |
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1412 |
val padding1 = ((width - text_width(hostname)) / 2) max 0 |
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1413 |
val rect = new Rectangle2D.Double(x, hostname_height, width, height) |
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1414 |
gfx.setColor(Color.BLACK) |
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1415 |
gfx.draw(rect) |
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1416 |
gfx.setColor(Color.GRAY) |
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1417 |
gfx.fill(rect) |
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1418 |
draw_string(hostname, x + padding1, generator_height) |
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1419 |
x + gap + width |
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1420 |
} |
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1421 |
|
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1422 |
def draw_string(str: String, x: Double, y: Double): Unit = { |
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1423 |
gfx.setColor(Color.BLACK) |
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1424 |
gfx.drawString(str, x.toInt, (y + line_height).toInt) |
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1425 |
} |
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1426 |
|
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1427 |
def node_rect(node: Schedule.Node): Rectangle2D.Double = { |
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1428 |
val x = node_start(node) |
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1429 |
val y = hostname_height + padding + date_height(node.start) |
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1430 |
val width = node_width(node) |
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1431 |
val height = time_height(node.duration) |
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1432 |
new Rectangle2D.Double(x, y, width, height) |
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1433 |
} |
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1434 |
|
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1435 |
def draw_node(node: Schedule.Node): Rectangle2D.Double = { |
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1436 |
val rect = node_rect(node) |
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1437 |
gfx.setColor(Color.BLACK) |
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1438 |
gfx.draw(rect) |
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1439 |
gfx.setColor(Color.WHITE) |
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1440 |
gfx.fill(rect) |
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1441 |
|
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1442 |
def add_text(y: Double, text: String): Double = |
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1443 |
if (line_height > rect.height - y || text_width(text) + 2 * padding > rect.width) y |
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1444 |
else { |
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1445 |
val padding1 = padding min ((rect.height - (y + line_height)) / 2) |
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1446 |
draw_string(text, rect.x + padding, rect.y + y + padding1) |
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1447 |
y + padding1 + line_height |
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1448 |
} |
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1449 |
|
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1450 |
val node_info = node.node_info |
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1451 |
|
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1452 |
val duration_str = "(" + node.duration.message_hms + ")" |
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1453 |
val node_str = |
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1454 |
"on " + proper_string(node_info.toString.stripPrefix(node_info.hostname)).getOrElse("all") |
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1455 |
val start_str = "Start: " + (node.start.time - schedule.start.time).message_hms |
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1456 |
|
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1457 |
List(node.job_name, duration_str, node_str, start_str).foldLeft(0D)(add_text) |
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1458 |
|
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1459 |
rect |
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1460 |
} |
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1461 |
|
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1462 |
def draw_arrow(from: Schedule.Node, to: Rectangle2D.Double, curve: Double = 10): Unit = { |
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1463 |
val from_rect = node_rect(from) |
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1464 |
|
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1465 |
val path = new GeneralPath() |
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1466 |
path.moveTo(from_rect.getCenterX, from_rect.getMaxY) |
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1467 |
path.lineTo(to.getCenterX, to.getMinY) |
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1468 |
|
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1469 |
gfx.setColor(Color.BLUE) |
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1470 |
gfx.draw(path) |
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1471 |
} |
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1472 |
|
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1473 |
hosts.keys.foldLeft(0D)(draw_host) |
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1474 |
|
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1475 |
graph.topological_order.foreach { job_name => |
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1476 |
val node = graph.get_node(job_name) |
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1477 |
val rect = draw_node(node) |
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1478 |
|
79235
d9f0eb441d74
improve graphical clarity by omitting intra-host dependencies (following ee405c40db72);
Fabian Huch <huch@in.tum.de>
parents:
79194
diff
changeset
|
1479 |
for { |
d9f0eb441d74
improve graphical clarity by omitting intra-host dependencies (following ee405c40db72);
Fabian Huch <huch@in.tum.de>
parents:
79194
diff
changeset
|
1480 |
pred <- graph.imm_preds(job_name).iterator |
d9f0eb441d74
improve graphical clarity by omitting intra-host dependencies (following ee405c40db72);
Fabian Huch <huch@in.tum.de>
parents:
79194
diff
changeset
|
1481 |
pred_node = graph.get_node(pred) |
d9f0eb441d74
improve graphical clarity by omitting intra-host dependencies (following ee405c40db72);
Fabian Huch <huch@in.tum.de>
parents:
79194
diff
changeset
|
1482 |
if node.node_info.hostname != pred_node.node_info.hostname |
d9f0eb441d74
improve graphical clarity by omitting intra-host dependencies (following ee405c40db72);
Fabian Huch <huch@in.tum.de>
parents:
79194
diff
changeset
|
1483 |
} draw_arrow(pred_node, rect) |
79181
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1484 |
} |
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1485 |
} |
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1486 |
|
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1487 |
val name = output.file_name |
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1488 |
if (File.is_png(name)) Graphics_File.write_png(output.file, paint, width, height) |
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1489 |
else if (File.is_pdf(name)) Graphics_File.write_pdf(output.file, paint, width, height) |
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1490 |
else error("Bad type of file: " + quote(name) + " (.png or .pdf expected)") |
9d6d559c9fde
added graphical representation of build schedules;
Fabian Huch <huch@in.tum.de>
parents:
79180
diff
changeset
|
1491 |
} |
79182
6202d0ff36b4
added build schedule command-line wrapper;
Fabian Huch <huch@in.tum.de>
parents:
79181
diff
changeset
|
1492 |
|
6202d0ff36b4
added build schedule command-line wrapper;
Fabian Huch <huch@in.tum.de>
parents:
79181
diff
changeset
|
1493 |
|
6202d0ff36b4
added build schedule command-line wrapper;
Fabian Huch <huch@in.tum.de>
parents:
79181
diff
changeset
|
1494 |
/* command-line wrapper */ |
6202d0ff36b4
added build schedule command-line wrapper;
Fabian Huch <huch@in.tum.de>
parents:
79181
diff
changeset
|
1495 |
|
6202d0ff36b4
added build schedule command-line wrapper;
Fabian Huch <huch@in.tum.de>
parents:
79181
diff
changeset
|
1496 |
val isabelle_tool = Isabelle_Tool("build_schedule", "generate build schedule", Scala_Project.here, |
6202d0ff36b4
added build schedule command-line wrapper;
Fabian Huch <huch@in.tum.de>
parents:
79181
diff
changeset
|
1497 |
{ args => |
6202d0ff36b4
added build schedule command-line wrapper;
Fabian Huch <huch@in.tum.de>
parents:
79181
diff
changeset
|
1498 |
var afp_root: Option[Path] = None |
6202d0ff36b4
added build schedule command-line wrapper;
Fabian Huch <huch@in.tum.de>
parents:
79181
diff
changeset
|
1499 |
val base_sessions = new mutable.ListBuffer[String] |
6202d0ff36b4
added build schedule command-line wrapper;
Fabian Huch <huch@in.tum.de>
parents:
79181
diff
changeset
|
1500 |
val select_dirs = new mutable.ListBuffer[Path] |
6202d0ff36b4
added build schedule command-line wrapper;
Fabian Huch <huch@in.tum.de>
parents:
79181
diff
changeset
|
1501 |
val build_hosts = new mutable.ListBuffer[Build_Cluster.Host] |
6202d0ff36b4
added build schedule command-line wrapper;
Fabian Huch <huch@in.tum.de>
parents:
79181
diff
changeset
|
1502 |
var numa_shuffling = false |
6202d0ff36b4
added build schedule command-line wrapper;
Fabian Huch <huch@in.tum.de>
parents:
79181
diff
changeset
|
1503 |
var output_file: Option[Path] = None |
6202d0ff36b4
added build schedule command-line wrapper;
Fabian Huch <huch@in.tum.de>
parents:
79181
diff
changeset
|
1504 |
var requirements = false |
6202d0ff36b4
added build schedule command-line wrapper;
Fabian Huch <huch@in.tum.de>
parents:
79181
diff
changeset
|
1505 |
val exclude_session_groups = new mutable.ListBuffer[String] |
6202d0ff36b4
added build schedule command-line wrapper;
Fabian Huch <huch@in.tum.de>
parents:
79181
diff
changeset
|
1506 |
var all_sessions = false |
6202d0ff36b4
added build schedule command-line wrapper;
Fabian Huch <huch@in.tum.de>
parents:
79181
diff
changeset
|
1507 |
val dirs = new mutable.ListBuffer[Path] |
6202d0ff36b4
added build schedule command-line wrapper;
Fabian Huch <huch@in.tum.de>
parents:
79181
diff
changeset
|
1508 |
val session_groups = new mutable.ListBuffer[String] |
6202d0ff36b4
added build schedule command-line wrapper;
Fabian Huch <huch@in.tum.de>
parents:
79181
diff
changeset
|
1509 |
var options = Options.init(specs = Options.Spec.ISABELLE_BUILD_OPTIONS) |
6202d0ff36b4
added build schedule command-line wrapper;
Fabian Huch <huch@in.tum.de>
parents:
79181
diff
changeset
|
1510 |
var verbose = false |
6202d0ff36b4
added build schedule command-line wrapper;
Fabian Huch <huch@in.tum.de>
parents:
79181
diff
changeset
|
1511 |
val exclude_sessions = new mutable.ListBuffer[String] |
6202d0ff36b4
added build schedule command-line wrapper;
Fabian Huch <huch@in.tum.de>
parents:
79181
diff
changeset
|
1512 |
|
6202d0ff36b4
added build schedule command-line wrapper;
Fabian Huch <huch@in.tum.de>
parents:
79181
diff
changeset
|
1513 |
val getopts = Getopts(""" |
6202d0ff36b4
added build schedule command-line wrapper;
Fabian Huch <huch@in.tum.de>
parents:
79181
diff
changeset
|
1514 |
Usage: isabelle build_schedule [OPTIONS] [SESSIONS ...] |
6202d0ff36b4
added build schedule command-line wrapper;
Fabian Huch <huch@in.tum.de>
parents:
79181
diff
changeset
|
1515 |
|
6202d0ff36b4
added build schedule command-line wrapper;
Fabian Huch <huch@in.tum.de>
parents:
79181
diff
changeset
|
1516 |
Options are: |
6202d0ff36b4
added build schedule command-line wrapper;
Fabian Huch <huch@in.tum.de>
parents:
79181
diff
changeset
|
1517 |
-A ROOT include AFP with given root directory (":" for """ + AFP.BASE.implode + """) |
6202d0ff36b4
added build schedule command-line wrapper;
Fabian Huch <huch@in.tum.de>
parents:
79181
diff
changeset
|
1518 |
-B NAME include session NAME and all descendants |
6202d0ff36b4
added build schedule command-line wrapper;
Fabian Huch <huch@in.tum.de>
parents:
79181
diff
changeset
|
1519 |
-D DIR include session directory and select its sessions |
6202d0ff36b4
added build schedule command-line wrapper;
Fabian Huch <huch@in.tum.de>
parents:
79181
diff
changeset
|
1520 |
-H HOSTS additional build cluster host specifications, of the form |
6202d0ff36b4
added build schedule command-line wrapper;
Fabian Huch <huch@in.tum.de>
parents:
79181
diff
changeset
|
1521 |
"NAMES:PARAMETERS" (separated by commas) |
6202d0ff36b4
added build schedule command-line wrapper;
Fabian Huch <huch@in.tum.de>
parents:
79181
diff
changeset
|
1522 |
-N cyclic shuffling of NUMA CPU nodes (performance tuning) |
6202d0ff36b4
added build schedule command-line wrapper;
Fabian Huch <huch@in.tum.de>
parents:
79181
diff
changeset
|
1523 |
-O FILE output file |
6202d0ff36b4
added build schedule command-line wrapper;
Fabian Huch <huch@in.tum.de>
parents:
79181
diff
changeset
|
1524 |
-R refer to requirements of selected sessions |
6202d0ff36b4
added build schedule command-line wrapper;
Fabian Huch <huch@in.tum.de>
parents:
79181
diff
changeset
|
1525 |
-X NAME exclude sessions from group NAME and all descendants |
6202d0ff36b4
added build schedule command-line wrapper;
Fabian Huch <huch@in.tum.de>
parents:
79181
diff
changeset
|
1526 |
-a select all sessions |
6202d0ff36b4
added build schedule command-line wrapper;
Fabian Huch <huch@in.tum.de>
parents:
79181
diff
changeset
|
1527 |
-d DIR include session directory |
6202d0ff36b4
added build schedule command-line wrapper;
Fabian Huch <huch@in.tum.de>
parents:
79181
diff
changeset
|
1528 |
-g NAME select session group NAME |
6202d0ff36b4
added build schedule command-line wrapper;
Fabian Huch <huch@in.tum.de>
parents:
79181
diff
changeset
|
1529 |
-o OPTION override Isabelle system OPTION (via NAME=VAL or NAME) |
6202d0ff36b4
added build schedule command-line wrapper;
Fabian Huch <huch@in.tum.de>
parents:
79181
diff
changeset
|
1530 |
-v verbose |
6202d0ff36b4
added build schedule command-line wrapper;
Fabian Huch <huch@in.tum.de>
parents:
79181
diff
changeset
|
1531 |
-x NAME exclude session NAME and all descendants |
6202d0ff36b4
added build schedule command-line wrapper;
Fabian Huch <huch@in.tum.de>
parents:
79181
diff
changeset
|
1532 |
|
6202d0ff36b4
added build schedule command-line wrapper;
Fabian Huch <huch@in.tum.de>
parents:
79181
diff
changeset
|
1533 |
Generate build graph. |
6202d0ff36b4
added build schedule command-line wrapper;
Fabian Huch <huch@in.tum.de>
parents:
79181
diff
changeset
|
1534 |
""", |
6202d0ff36b4
added build schedule command-line wrapper;
Fabian Huch <huch@in.tum.de>
parents:
79181
diff
changeset
|
1535 |
"A:" -> (arg => afp_root = Some(if (arg == ":") AFP.BASE else Path.explode(arg))), |
6202d0ff36b4
added build schedule command-line wrapper;
Fabian Huch <huch@in.tum.de>
parents:
79181
diff
changeset
|
1536 |
"B:" -> (arg => base_sessions += arg), |
6202d0ff36b4
added build schedule command-line wrapper;
Fabian Huch <huch@in.tum.de>
parents:
79181
diff
changeset
|
1537 |
"D:" -> (arg => select_dirs += Path.explode(arg)), |
6202d0ff36b4
added build schedule command-line wrapper;
Fabian Huch <huch@in.tum.de>
parents:
79181
diff
changeset
|
1538 |
"H:" -> (arg => build_hosts ++= Build_Cluster.Host.parse(Registry.global, arg)), |
6202d0ff36b4
added build schedule command-line wrapper;
Fabian Huch <huch@in.tum.de>
parents:
79181
diff
changeset
|
1539 |
"N" -> (_ => numa_shuffling = true), |
6202d0ff36b4
added build schedule command-line wrapper;
Fabian Huch <huch@in.tum.de>
parents:
79181
diff
changeset
|
1540 |
"O:" -> (arg => output_file = Some(Path.explode(arg))), |
6202d0ff36b4
added build schedule command-line wrapper;
Fabian Huch <huch@in.tum.de>
parents:
79181
diff
changeset
|
1541 |
"R" -> (_ => requirements = true), |
6202d0ff36b4
added build schedule command-line wrapper;
Fabian Huch <huch@in.tum.de>
parents:
79181
diff
changeset
|
1542 |
"X:" -> (arg => exclude_session_groups += arg), |
6202d0ff36b4
added build schedule command-line wrapper;
Fabian Huch <huch@in.tum.de>
parents:
79181
diff
changeset
|
1543 |
"a" -> (_ => all_sessions = true), |
6202d0ff36b4
added build schedule command-line wrapper;
Fabian Huch <huch@in.tum.de>
parents:
79181
diff
changeset
|
1544 |
"d:" -> (arg => dirs += Path.explode(arg)), |
6202d0ff36b4
added build schedule command-line wrapper;
Fabian Huch <huch@in.tum.de>
parents:
79181
diff
changeset
|
1545 |
"g:" -> (arg => session_groups += arg), |
6202d0ff36b4
added build schedule command-line wrapper;
Fabian Huch <huch@in.tum.de>
parents:
79181
diff
changeset
|
1546 |
"o:" -> (arg => options = options + arg), |
6202d0ff36b4
added build schedule command-line wrapper;
Fabian Huch <huch@in.tum.de>
parents:
79181
diff
changeset
|
1547 |
"v" -> (_ => verbose = true), |
6202d0ff36b4
added build schedule command-line wrapper;
Fabian Huch <huch@in.tum.de>
parents:
79181
diff
changeset
|
1548 |
"x:" -> (arg => exclude_sessions += arg)) |
6202d0ff36b4
added build schedule command-line wrapper;
Fabian Huch <huch@in.tum.de>
parents:
79181
diff
changeset
|
1549 |
|
6202d0ff36b4
added build schedule command-line wrapper;
Fabian Huch <huch@in.tum.de>
parents:
79181
diff
changeset
|
1550 |
val sessions = getopts(args) |
6202d0ff36b4
added build schedule command-line wrapper;
Fabian Huch <huch@in.tum.de>
parents:
79181
diff
changeset
|
1551 |
|
6202d0ff36b4
added build schedule command-line wrapper;
Fabian Huch <huch@in.tum.de>
parents:
79181
diff
changeset
|
1552 |
val progress = new Console_Progress(verbose = verbose) |
6202d0ff36b4
added build schedule command-line wrapper;
Fabian Huch <huch@in.tum.de>
parents:
79181
diff
changeset
|
1553 |
|
6202d0ff36b4
added build schedule command-line wrapper;
Fabian Huch <huch@in.tum.de>
parents:
79181
diff
changeset
|
1554 |
val schedule = |
6202d0ff36b4
added build schedule command-line wrapper;
Fabian Huch <huch@in.tum.de>
parents:
79181
diff
changeset
|
1555 |
build_schedule(options, |
6202d0ff36b4
added build schedule command-line wrapper;
Fabian Huch <huch@in.tum.de>
parents:
79181
diff
changeset
|
1556 |
selection = Sessions.Selection( |
6202d0ff36b4
added build schedule command-line wrapper;
Fabian Huch <huch@in.tum.de>
parents:
79181
diff
changeset
|
1557 |
requirements = requirements, |
6202d0ff36b4
added build schedule command-line wrapper;
Fabian Huch <huch@in.tum.de>
parents:
79181
diff
changeset
|
1558 |
all_sessions = all_sessions, |
6202d0ff36b4
added build schedule command-line wrapper;
Fabian Huch <huch@in.tum.de>
parents:
79181
diff
changeset
|
1559 |
base_sessions = base_sessions.toList, |
6202d0ff36b4
added build schedule command-line wrapper;
Fabian Huch <huch@in.tum.de>
parents:
79181
diff
changeset
|
1560 |
exclude_session_groups = exclude_session_groups.toList, |
6202d0ff36b4
added build schedule command-line wrapper;
Fabian Huch <huch@in.tum.de>
parents:
79181
diff
changeset
|
1561 |
exclude_sessions = exclude_sessions.toList, |
6202d0ff36b4
added build schedule command-line wrapper;
Fabian Huch <huch@in.tum.de>
parents:
79181
diff
changeset
|
1562 |
session_groups = session_groups.toList, |
6202d0ff36b4
added build schedule command-line wrapper;
Fabian Huch <huch@in.tum.de>
parents:
79181
diff
changeset
|
1563 |
sessions = sessions), |
6202d0ff36b4
added build schedule command-line wrapper;
Fabian Huch <huch@in.tum.de>
parents:
79181
diff
changeset
|
1564 |
progress = progress, |
6202d0ff36b4
added build schedule command-line wrapper;
Fabian Huch <huch@in.tum.de>
parents:
79181
diff
changeset
|
1565 |
afp_root = afp_root, |
6202d0ff36b4
added build schedule command-line wrapper;
Fabian Huch <huch@in.tum.de>
parents:
79181
diff
changeset
|
1566 |
dirs = dirs.toList, |
6202d0ff36b4
added build schedule command-line wrapper;
Fabian Huch <huch@in.tum.de>
parents:
79181
diff
changeset
|
1567 |
select_dirs = select_dirs.toList, |
6202d0ff36b4
added build schedule command-line wrapper;
Fabian Huch <huch@in.tum.de>
parents:
79181
diff
changeset
|
1568 |
numa_shuffling = isabelle.Host.numa_check(progress, numa_shuffling), |
6202d0ff36b4
added build schedule command-line wrapper;
Fabian Huch <huch@in.tum.de>
parents:
79181
diff
changeset
|
1569 |
build_hosts = build_hosts.toList) |
6202d0ff36b4
added build schedule command-line wrapper;
Fabian Huch <huch@in.tum.de>
parents:
79181
diff
changeset
|
1570 |
|
79293 | 1571 |
if (!schedule.is_empty && output_file.nonEmpty) |
79182
6202d0ff36b4
added build schedule command-line wrapper;
Fabian Huch <huch@in.tum.de>
parents:
79181
diff
changeset
|
1572 |
write_schedule_graphic(schedule, output_file.get) |
6202d0ff36b4
added build schedule command-line wrapper;
Fabian Huch <huch@in.tum.de>
parents:
79181
diff
changeset
|
1573 |
}) |
78845
ff96d94957cb
add module for faster scheduled builds;
Fabian Huch <huch@in.tum.de>
parents:
diff
changeset
|
1574 |
} |