Skip to content

Commit 61d7619

Browse files
Discover experiments in need of reporting on reports thread
This avoids each new result needing to scan the results and experiment_crates tables in order to discover the number of in-progress results. Instead, that work will happen every ~10 minutes (by current setting) in the background. It's not clear that this is going to help with our performance problems (though it should not hurt!). Regardless, this is also a good step towards avoiding the need to retry report generation, since on server restarts we will automatically discover the need to generate a fresh report (rather than needing to manually move an experiment back to the needs-report state). Future commits will clean up some of the states that we no longer need as a result of this change.
1 parent c899b6f commit 61d7619

File tree

3 files changed

+16
-23
lines changed

3 files changed

+16
-23
lines changed

src/experiments.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -298,20 +298,20 @@ impl Experiment {
298298
}
299299
}
300300

301-
pub fn first_by_status(db: &Database, status: Status) -> Fallible<Option<Experiment>> {
302-
let record = db.get_row(
303-
"SELECT * FROM experiments \
304-
WHERE status = ?1 \
305-
ORDER BY priority DESC, created_at;",
306-
&[&status.to_str()],
307-
|r| ExperimentDBRecord::from_row(r),
308-
)?;
309-
310-
if let Some(record) = record {
311-
Ok(Some(record.into_experiment()?))
312-
} else {
313-
Ok(None)
301+
// Returns the first experiment which has all results ready (and so can
302+
// produce a complete report). However, the experiment should not be
303+
// *completed* yet. Note that this may return an experiment which has had
304+
// report generation already start.
305+
pub fn ready_for_report(db: &Database) -> Fallible<Option<Experiment>> {
306+
let unfinished = Self::unfinished(db)?;
307+
for ex in unfinished {
308+
let (completed, all) = ex.raw_progress(db)?;
309+
if completed == all {
310+
return Ok(Some(ex));
311+
}
314312
}
313+
314+
Ok(None)
315315
}
316316

317317
pub fn find_next(db: &Database, assignee: &Assignee) -> Fallible<Option<Experiment>> {

src/server/reports.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ fn reports_thread(data: &Data, github_data: Option<&GithubData>) -> Fallible<()>
3737
let results = DatabaseDB::new(&data.db);
3838

3939
loop {
40-
let mut ex = match Experiment::first_by_status(&data.db, Status::NeedsReport)? {
40+
let mut ex = match Experiment::ready_for_report(&data.db)? {
4141
Some(ex) => ex,
4242
None => {
4343
// This will sleep AUTOMATIC_THREAD_WAKEUP seconds *or* until a wake is received

src/server/routes/agent.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::agent::Capabilities;
2-
use crate::experiments::{Assignee, Experiment, Status};
2+
use crate::experiments::{Assignee, Experiment};
33
use crate::prelude::*;
44
use crate::results::{DatabaseDB, EncodingType, ProgressData};
55
use crate::server::api_types::{AgentConfig, ApiResponse};
@@ -160,7 +160,7 @@ fn endpoint_record_progress(
160160
auth: AuthDetails,
161161
) -> Fallible<Response<Body>> {
162162
let data = mutex.lock().unwrap();
163-
let mut ex = Experiment::get(&data.db, &result.experiment_name)?
163+
let ex = Experiment::get(&data.db, &result.experiment_name)?
164164
.ok_or_else(|| err_msg("no experiment run by this agent"))?;
165165

166166
data.metrics
@@ -169,13 +169,6 @@ fn endpoint_record_progress(
169169
let db = DatabaseDB::new(&data.db);
170170
db.store(&ex, &result.data, EncodingType::Gzip)?;
171171

172-
let (completed, all) = ex.raw_progress(&data.db)?;
173-
if completed == all {
174-
ex.set_status(&data.db, Status::NeedsReport)?;
175-
info!("experiment {} completed, marked as needs-report", ex.name);
176-
data.reports_worker.wake(); // Ensure the reports worker is awake
177-
}
178-
179172
Ok(ApiResponse::Success { result: true }.into_response()?)
180173
}
181174

0 commit comments

Comments
 (0)