Skip to content

Commit 63870d3

Browse files
authored
Merge pull request #1654 from Kobzol/queue-estimation-comment
Add perf. run duration estimation to PR comment
2 parents 49cca0e + 3de3d06 commit 63870d3

File tree

6 files changed

+61
-21
lines changed

6 files changed

+61
-21
lines changed

database/src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -668,3 +668,9 @@ pub struct CompileBenchmark {
668668
pub name: String,
669669
pub category: String,
670670
}
671+
672+
#[derive(Debug)]
673+
pub struct ArtifactCollection {
674+
pub duration: Duration,
675+
pub end_time: DateTime<Utc>,
676+
}

database/src/pool.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::{ArtifactId, ArtifactIdNumber, CompileBenchmark};
1+
use crate::{ArtifactCollection, ArtifactId, ArtifactIdNumber, CompileBenchmark};
22
use crate::{CollectionId, Index, Profile, QueuedCommit, Scenario, Step};
33
use chrono::{DateTime, Utc};
44
use hashbrown::HashMap;
@@ -153,7 +153,7 @@ pub trait Connection: Send + Sync {
153153

154154
async fn in_progress_steps(&self, aid: &ArtifactId) -> Vec<Step>;
155155

156-
async fn last_end_time(&self) -> Option<DateTime<Utc>>;
156+
async fn last_artifact_collection(&self) -> Option<ArtifactCollection>;
157157

158158
/// Returns the sha of the parent commit, if available.
159159
///

database/src/pool/postgres.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::pool::{Connection, ConnectionManager, ManagedConnection, Transaction};
22
use crate::{
3-
ArtifactId, ArtifactIdNumber, Benchmark, CollectionId, Commit, CommitType, CompileBenchmark,
4-
Date, Index, Profile, QueuedCommit, Scenario,
3+
ArtifactCollection, ArtifactId, ArtifactIdNumber, Benchmark, CollectionId, Commit, CommitType,
4+
CompileBenchmark, Date, Index, Profile, QueuedCommit, Scenario,
55
};
66
use anyhow::Context as _;
77
use chrono::{DateTime, TimeZone, Utc};
@@ -1194,18 +1194,21 @@ where
11941194
})
11951195
.collect()
11961196
}
1197-
async fn last_end_time(&self) -> Option<DateTime<Utc>> {
1197+
async fn last_artifact_collection(&self) -> Option<ArtifactCollection> {
11981198
self.conn()
11991199
.query_opt(
1200-
"select date_recorded \
1200+
"select date_recorded, duration \
12011201
from artifact_collection_duration \
12021202
order by date_recorded desc \
12031203
limit 1;",
12041204
&[],
12051205
)
12061206
.await
12071207
.unwrap()
1208-
.map(|r| r.get(0))
1208+
.map(|r| ArtifactCollection {
1209+
end_time: r.get(0),
1210+
duration: Duration::from_secs(r.get::<_, i32>(1) as u64),
1211+
})
12091212
}
12101213
async fn parent_of(&self, sha: &str) -> Option<String> {
12111214
self.conn()

database/src/pool/sqlite.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::pool::{Connection, ConnectionManager, ManagedConnection, Transaction};
22
use crate::{
3-
ArtifactId, Benchmark, CollectionId, Commit, CommitType, CompileBenchmark, Date, Profile,
3+
ArtifactCollection, ArtifactId, Benchmark, CollectionId, Commit, CommitType, CompileBenchmark,
4+
Date, Profile,
45
};
56
use crate::{ArtifactIdNumber, Index, QueryDatum, QueuedCommit};
67
use chrono::{DateTime, NaiveDateTime, TimeZone, Utc};
@@ -1149,18 +1150,24 @@ impl Connection for SqliteConnection {
11491150
.collect()
11501151
}
11511152

1152-
async fn last_end_time(&self) -> Option<DateTime<Utc>> {
1153+
async fn last_artifact_collection(&self) -> Option<ArtifactCollection> {
11531154
self.raw_ref()
11541155
.query_row(
1155-
"select date_recorded + duration \
1156+
"select date_recorded, duration \
11561157
from artifact_collection_duration \
11571158
order by date_recorded desc \
11581159
limit 1;",
11591160
params![],
1160-
|r| Ok(Utc.timestamp_opt(r.get(0)?, 0).unwrap()),
1161+
|r| {
1162+
Ok((
1163+
Utc.timestamp_opt(r.get(0)?, 0).unwrap(),
1164+
Duration::from_secs(r.get(1)?),
1165+
))
1166+
},
11611167
)
11621168
.optional()
11631169
.unwrap()
1170+
.map(|(end_time, duration)| ArtifactCollection { end_time, duration })
11641171
}
11651172

11661173
async fn parent_of(&self, sha: &str) -> Option<String> {

site/src/github.rs

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ pub mod comparison_summary;
33

44
use crate::api::github::Commit;
55
use crate::load::{SiteCtxt, TryCommit};
6+
use std::time::Duration;
67

78
use serde::Deserialize;
89

@@ -257,22 +258,44 @@ pub async fn enqueue_shas(
257258
sha: commit_response.sha,
258259
parent_sha: commit_response.parents.remove(0).sha,
259260
};
260-
let queued = {
261-
let conn = ctxt.conn().await;
262-
conn.pr_attach_commit(
261+
let conn = ctxt.conn().await;
262+
let queued = conn
263+
.pr_attach_commit(
263264
pr_number,
264265
&try_commit.sha,
265266
&try_commit.parent_sha,
266267
Some(commit_response.commit.committer.date),
267268
)
268-
.await
269-
};
269+
.await;
270270
if queued {
271271
if !msg.is_empty() {
272272
msg.push('\n');
273273
}
274+
275+
let artifacts_in_queue = ctxt.missing_commits().await.len();
276+
let last_duration = conn
277+
.last_artifact_collection()
278+
.await
279+
.map(|collection| collection.duration)
280+
.unwrap_or(Duration::ZERO);
281+
282+
// "Guess" that the duration will take about an hour if we don't have data or it's
283+
// suspiciously fast.
284+
let last_duration = last_duration.max(Duration::from_secs(3600));
285+
286+
let expected_duration = (last_duration.as_secs() * artifacts_in_queue as u64) as f64;
287+
288+
// At this point, the queue should also contain the commit that we're mentioning below.
289+
let other_artifact_count = artifacts_in_queue.saturating_sub(1);
290+
let suffix = if other_artifact_count == 1 { "" } else { "s" };
291+
let queue_msg = format!(
292+
r#"There are currently {other_artifact_count} other artifact{suffix} in the [queue](https://perf.rust-lang.org/status.html).
293+
It will probably take at least ~{:.2} hours until the benchmark run finishes."#,
294+
(expected_duration / 3600.0)
295+
);
296+
274297
msg.push_str(&format!(
275-
"Queued {} with parent {}, future [comparison URL]({}).",
298+
"Queued {} with parent {}, future [comparison URL]({}).\n{queue_msg}",
276299
try_commit.sha,
277300
try_commit.parent_sha,
278301
try_commit.comparison_url(),

site/src/request_handlers/status_page.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,7 @@ pub async fn handle_status_page(ctxt: Arc<SiteCtxt>) -> status::Response {
3434
};
3535

3636
let errors = if let Some(last) = &last_commit {
37-
ctxt.conn()
38-
.await
39-
.get_error(ArtifactId::from(last.clone()).lookup(&idx).unwrap())
37+
conn.get_error(ArtifactId::from(last.clone()).lookup(&idx).unwrap())
4038
.await
4139
} else {
4240
Default::default()
@@ -54,7 +52,10 @@ pub async fn handle_status_page(ctxt: Arc<SiteCtxt>) -> status::Response {
5452
benchmarks: benchmark_state,
5553
missing,
5654
current,
57-
most_recent_end: conn.last_end_time().await.map(|d| d.timestamp()),
55+
most_recent_end: conn
56+
.last_artifact_collection()
57+
.await
58+
.map(|d| d.end_time.timestamp()),
5859
}
5960
}
6061

0 commit comments

Comments
 (0)