@@ -37,44 +37,30 @@ async fn create_benchmark_request_master_commits(
37
37
Ok ( ( ) )
38
38
}
39
39
40
- /// For getting the priority of the request type;
41
- /// - Release
42
- /// - Master
43
- /// - Try
44
- fn benchmark_request_commit_type_rank ( commit_type : & BenchmarkRequestType ) -> u8 {
45
- match commit_type {
46
- BenchmarkRequestType :: Release { .. } => 0 ,
47
- BenchmarkRequestType :: Master { .. } => 1 ,
48
- BenchmarkRequestType :: Try { .. } => 2 ,
49
- }
50
- }
51
-
52
- /// Sorts the priority order of the queue. It assumes that the only status
53
- /// is `ArtifactsReady`
54
- fn sort_benchmark_requests < ' a > (
55
- done : & mut HashSet < String > ,
56
- unordered_queue : & ' a mut [ BenchmarkRequest ] ,
57
- ) -> & ' a [ BenchmarkRequest ] {
40
+ /// Sorts try and master requests that are in the `ArtifactsReady` status.
41
+ /// Doesn't consider in-progress requests or release artifacts.
42
+ fn sort_benchmark_requests < ' a > ( done : & HashSet < String > , request_queue : & ' a mut [ BenchmarkRequest ] ) {
58
43
// A topological sort, where each "level" is additionally altered such that
59
44
// try commits come first, and then sorted by PR # (as a rough heuristic for
60
45
// earlier requests).
46
+ let mut done: HashSet < & str > = done. iter ( ) . map ( |x| x. as_str ( ) ) . collect ( ) ;
61
47
62
48
// Ensure all the items are ready to be sorted, if they are not this is
63
49
// undefined behaviour
64
- assert ! ( unordered_queue
65
- . iter ( )
66
- . all ( |bmr| bmr . status == BenchmarkRequestStatus :: ArtifactsReady ) ) ;
67
-
68
- // Ensure the queue is ordered by status and the `commit_type`
69
- unordered_queue
70
- . sort_unstable_by_key ( |bmr| ( benchmark_request_commit_type_rank ( & bmr . commit_type ) ) ) ;
50
+ assert ! ( request_queue . iter ( ) . all ( |bmr| {
51
+ bmr . status == BenchmarkRequestStatus :: ArtifactsReady
52
+ && matches! (
53
+ bmr . commit_type ,
54
+ BenchmarkRequestType :: Master { .. } | BenchmarkRequestType :: Try { .. }
55
+ )
56
+ } ) ) ;
71
57
72
58
let mut finished = 0 ;
73
- while finished < unordered_queue . len ( ) {
59
+ while finished < request_queue . len ( ) {
74
60
// The next level is those elements in the unordered queue which
75
61
// are ready to be benchmarked (i.e., those with parent in done or no
76
62
// parent).
77
- let level_len = partition_in_place ( unordered_queue [ finished..] . iter_mut ( ) , |bmr| {
63
+ let level_len = partition_in_place ( request_queue [ finished..] . iter_mut ( ) , |bmr| {
78
64
bmr. parent_sha ( ) . is_none_or ( |parent| done. contains ( parent) )
79
65
} ) ;
80
66
@@ -83,33 +69,43 @@ fn sort_benchmark_requests<'a>(
83
69
// let the commits be benchmarked in the current order that we have, these benchmark runs
84
70
// just won't have a parent result available.
85
71
if level_len == 0 {
86
- return unordered_queue;
72
+ log:: warn!( "No commit is ready for benchmarking" ) ;
73
+ #[ cfg( test) ]
74
+ {
75
+ panic ! ( "No commit is ready for benchmarking" ) ;
76
+ }
77
+ return ;
87
78
}
88
79
89
- let level = & mut unordered_queue[ finished..] [ ..level_len] ;
80
+ // Everything in level has the same topological order, then we sort based on heuristics
81
+ let level = & mut request_queue[ finished..] [ ..level_len] ;
90
82
level. sort_unstable_by_key ( |bmr| {
91
83
(
92
- bmr. parent_sha ( ) . is_some ( ) ,
84
+ // Order master commits before try commits
85
+ match bmr. commit_type {
86
+ BenchmarkRequestType :: Try { .. } => 1 ,
87
+ BenchmarkRequestType :: Master { .. } => 0 ,
88
+ BenchmarkRequestType :: Release { .. } => unreachable ! ( ) ,
89
+ } ,
93
90
* bmr. pr ( ) . unwrap_or ( & 0 ) ,
94
91
bmr. created_at ,
95
- bmr. tag ( ) . to_string ( ) ,
96
92
)
97
93
} ) ;
98
94
for c in level {
99
- done. insert ( c. tag ( ) . to_string ( ) ) ;
95
+ done. insert ( c. tag ( ) ) ;
100
96
}
101
97
finished += level_len;
102
98
}
103
- unordered_queue
104
99
}
105
100
106
101
/// Given some pending requests and a list of completed requests determine if
107
102
/// we have another request the we can process
108
103
fn get_next_benchmark_request < ' a > (
109
104
pending : & ' a mut [ BenchmarkRequest ] ,
110
- completed_set : & mut HashSet < String > ,
105
+ completed_set : & HashSet < String > ,
111
106
) -> Option < & ' a BenchmarkRequest > {
112
- sort_benchmark_requests ( completed_set, pending) . first ( )
107
+ sort_benchmark_requests ( completed_set, pending) ;
108
+ pending. first ( )
113
109
}
114
110
115
111
/// Enqueue the job into the job_queue
0 commit comments