Skip to content

Commit cb83551

Browse files
committed
PR Feedback; remove create_queued
1 parent ffdf54f commit cb83551

File tree

3 files changed

+48
-131
lines changed

3 files changed

+48
-131
lines changed

database/src/lib.rs

Lines changed: 6 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,6 +1092,12 @@ impl fmt::Display for BenchmarkJobStatus {
10921092
#[derive(Debug, Clone, PartialEq)]
10931093
pub struct BenchmarkSet(u32);
10941094

1095+
/// A single unit of work generated from a benchmark request. Split by profiles
1096+
/// and backends
1097+
///
1098+
/// Each request is split into several `BenchmarkJob`s. Collectors poll the
1099+
/// queue and claim a job only when its `benchmark_set` matches one of the sets
1100+
/// they are responsible for.
10951101
#[derive(Debug, Clone, PartialEq)]
10961102
pub struct BenchmarkJob {
10971103
target: Target,
@@ -1103,48 +1109,3 @@ pub struct BenchmarkJob {
11031109
status: BenchmarkJobStatus,
11041110
retry: u32,
11051111
}
1106-
1107-
impl BenchmarkJob {
1108-
pub fn create_queued(
1109-
target: Target,
1110-
backend: CodegenBackend,
1111-
profile: Profile,
1112-
request_tag: &str,
1113-
benchmark_set: u32,
1114-
) -> Self {
1115-
BenchmarkJob {
1116-
target,
1117-
backend,
1118-
profile,
1119-
created_at: Utc::now(),
1120-
request_tag: request_tag.to_string(),
1121-
benchmark_set: BenchmarkSet(benchmark_set),
1122-
status: BenchmarkJobStatus::Queued,
1123-
retry: 0,
1124-
}
1125-
}
1126-
1127-
pub fn request_tag(&self) -> &str {
1128-
&self.request_tag
1129-
}
1130-
1131-
pub fn target(&self) -> Target {
1132-
self.target
1133-
}
1134-
1135-
pub fn backend(&self) -> CodegenBackend {
1136-
self.backend
1137-
}
1138-
1139-
pub fn profile(&self) -> Profile {
1140-
self.profile
1141-
}
1142-
1143-
pub fn benchmark_set(&self) -> u32 {
1144-
self.benchmark_set.0
1145-
}
1146-
1147-
pub fn status(&self) -> &BenchmarkJobStatus {
1148-
&self.status
1149-
}
1150-
}

database/src/pool.rs

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ mod tests {
345345
use super::*;
346346
use crate::{
347347
tests::{run_db_test, run_postgres_test},
348-
BenchmarkJob, BenchmarkRequestStatus, BenchmarkRequestType, Commit, CommitType, Date,
348+
BenchmarkRequestStatus, BenchmarkRequestType, Commit, CommitType, Date,
349349
};
350350

351351
/// Create a Commit
@@ -604,14 +604,6 @@ mod tests {
604604
let benchmark_request =
605605
BenchmarkRequest::create_master("sha-1", "parent-sha-1", 42, time);
606606

607-
let benchmark_job = BenchmarkJob::create_queued(
608-
Target::X86_64UnknownLinuxGnu,
609-
CodegenBackend::Llvm,
610-
Profile::Opt,
611-
benchmark_request.tag().unwrap(),
612-
2,
613-
);
614-
615607
// Insert the request so we don't violate the foreign key
616608
db.insert_benchmark_request(&benchmark_request)
617609
.await
@@ -620,10 +612,10 @@ mod tests {
620612
// Now we can insert the job
621613
let result = db
622614
.enqueue_benchmark_job(
623-
benchmark_job.request_tag(),
624-
&benchmark_job.target(),
625-
&benchmark_job.backend(),
626-
&benchmark_job.profile(),
615+
benchmark_request.tag().unwrap(),
616+
&Target::X86_64UnknownLinuxGnu,
617+
&CodegenBackend::Llvm,
618+
&Profile::Opt,
627619
0u32,
628620
)
629621
.await;

site/src/job_queue/mod.rs

Lines changed: 37 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ use crate::job_queue::utils::{parse_release_string, ExtractIf};
66
use crate::load::{partition_in_place, SiteCtxt};
77
use chrono::Utc;
88
use collector::benchmark_set::benchmark_set_count;
9-
use database::{
10-
BenchmarkJob, BenchmarkRequest, BenchmarkRequestIndex, BenchmarkRequestStatus, Target,
11-
};
9+
use database::{BenchmarkRequest, BenchmarkRequestIndex, BenchmarkRequestStatus, Target};
1210
use hashbrown::HashSet;
1311
use parking_lot::RwLock;
1412
use tokio::time::{self, Duration};
@@ -178,17 +176,19 @@ pub async fn build_queue(
178176
}
179177

180178
/// From a benchmark_request create all the required jobs
181-
pub fn create_benchmark_jobs(
179+
pub async fn create_benchmark_jobs(
180+
conn: &mut dyn database::pool::Connection,
182181
benchmark_request: &BenchmarkRequest,
183-
) -> anyhow::Result<Vec<BenchmarkJob>> {
182+
) -> anyhow::Result<()> {
183+
let mut tx = conn.transaction().await;
184184
anyhow::ensure!(
185185
benchmark_request.tag().is_some(),
186186
"Benchmark request has no tag"
187187
);
188188

189189
let backends = benchmark_request.backends()?;
190190
let profiles = benchmark_request.profiles()?;
191-
let mut jobs = vec![];
191+
let request_tag = benchmark_request.tag().unwrap();
192192

193193
// Target x benchmark_set x backend x profile -> BenchmarkJob
194194
for target in Target::all() {
@@ -197,20 +197,40 @@ pub fn create_benchmark_jobs(
197197
) {
198198
for backend in backends.iter() {
199199
for profile in profiles.iter() {
200-
let job = BenchmarkJob::create_queued(
201-
target,
202-
*backend,
203-
*profile,
204-
benchmark_request.tag().unwrap(),
205-
benchmark_set as u32,
206-
);
207-
jobs.push(job);
200+
tx.conn()
201+
.enqueue_benchmark_job(
202+
request_tag,
203+
&target,
204+
backend,
205+
profile,
206+
benchmark_set as u32,
207+
)
208+
.await?;
209+
// If there is a parent, we create a job for it to. The
210+
// database will ignore it if there is already a job there.
211+
// If the parent job has been deleted from the database
212+
// but was already benchmarked then the collector will ignore
213+
// it as it will see it already has results.
214+
if let Some(parent_sha) = benchmark_request.parent_sha() {
215+
tx.conn()
216+
.enqueue_benchmark_job(
217+
parent_sha,
218+
&target,
219+
backend,
220+
profile,
221+
benchmark_set as u32,
222+
)
223+
.await?;
224+
}
208225
}
209226
}
210227
}
211228
}
212229

213-
Ok(jobs)
230+
tx.conn()
231+
.update_benchmark_request_status(request_tag, BenchmarkRequestStatus::InProgress)
232+
.await?;
233+
Ok(())
214234
}
215235

216236
/// Enqueue the job into the job_queue
@@ -219,30 +239,12 @@ async fn enqueue_next_job(
219239
index: &mut BenchmarkRequestIndex,
220240
) -> anyhow::Result<()> {
221241
let queue = build_queue(conn, index).await?;
222-
let mut tx = conn.transaction().await;
223242
for request in queue {
224243
if request.status() != BenchmarkRequestStatus::InProgress {
225-
for benchmark_job in create_benchmark_jobs(&request)? {
226-
tx.conn()
227-
.enqueue_benchmark_job(
228-
benchmark_job.request_tag(),
229-
&benchmark_job.target(),
230-
&benchmark_job.backend(),
231-
&benchmark_job.profile(),
232-
benchmark_job.benchmark_set(),
233-
)
234-
.await?;
235-
}
236-
tx.conn()
237-
.update_benchmark_request_status(
238-
request.tag().unwrap(),
239-
BenchmarkRequestStatus::InProgress,
240-
)
241-
.await?;
244+
create_benchmark_jobs(conn, &request).await?;
242245
break;
243246
}
244247
}
245-
tx.commit().await?;
246248
Ok(())
247249
}
248250

@@ -282,7 +284,7 @@ pub async fn cron_main(site_ctxt: Arc<RwLock<Option<Arc<SiteCtxt>>>>, seconds: u
282284
mod tests {
283285
use super::*;
284286
use chrono::{Datelike, Duration, TimeZone, Utc};
285-
use database::{tests::run_postgres_test, CodegenBackend, Profile};
287+
use database::tests::run_postgres_test;
286288

287289
fn days_ago(day_str: &str) -> chrono::DateTime<Utc> {
288290
// Walk backwards until the first non-digit, then slice
@@ -346,18 +348,6 @@ mod tests {
346348
assert_eq!(queue_shas, expected)
347349
}
348350

349-
fn benchmark_jobs_match(jobs: &[BenchmarkJob], expected_jobs: &[BenchmarkJob]) {
350-
assert_eq!(jobs.len(), expected_jobs.len());
351-
for (job, expected) in std::iter::zip(jobs, expected_jobs) {
352-
assert_eq!(job.target(), expected.target());
353-
assert_eq!(job.backend(), expected.backend());
354-
assert_eq!(job.profile(), expected.profile());
355-
assert_eq!(job.benchmark_set(), expected.benchmark_set());
356-
assert_eq!(job.request_tag(), expected.request_tag());
357-
assert_eq!(job.status(), expected.status());
358-
}
359-
}
360-
361351
#[tokio::test]
362352
async fn queue_ordering() {
363353
run_postgres_test(|ctx| async {
@@ -456,30 +446,4 @@ mod tests {
456446
})
457447
.await;
458448
}
459-
460-
#[test]
461-
fn create_benchmark_jobs_default() {
462-
let request = create_master("bar", "parent1", 10, "days2");
463-
let jobs = create_benchmark_jobs(&request).unwrap();
464-
465-
let create_job = |profile: Profile| -> BenchmarkJob {
466-
BenchmarkJob::create_queued(
467-
Target::X86_64UnknownLinuxGnu,
468-
CodegenBackend::Llvm,
469-
profile,
470-
request.tag().unwrap(),
471-
0u32,
472-
)
473-
};
474-
475-
benchmark_jobs_match(
476-
&vec![
477-
create_job(Profile::Check),
478-
create_job(Profile::Debug),
479-
create_job(Profile::Doc),
480-
create_job(Profile::Opt),
481-
],
482-
&jobs,
483-
);
484-
}
485449
}

0 commit comments

Comments
 (0)