Skip to content

Commit

Permalink
rsc: Add config var for min runtime to cache (#1628)
Browse files Browse the repository at this point in the history
* rsc: Add config var for min runtime to cache

* fix tests
  • Loading branch information
V-FEXrt authored Aug 13, 2024
1 parent e697f56 commit 14c93d0
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 3 deletions.
3 changes: 2 additions & 1 deletion rust/rsc/.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
},
"load_shed": {
"tick_rate": 30,
"target": 16.0
"target": 16.0,
"min_runtime": 0.1
}
}
2 changes: 2 additions & 0 deletions rust/rsc/src/bin/rsc/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ pub struct RSCLoadShedConfig {
pub tick_rate: u64,
// Load value after which load should be statistically shed
pub target: f64,
// The minimum amount of time a job must take to complete in order to be cached
pub min_runtime: f64,
}

#[derive(Debug, Deserialize, Serialize)]
Expand Down
4 changes: 3 additions & 1 deletion rust/rsc/src/bin/rsc/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,8 @@ fn create_router(
post({
let conn = conn.clone();
let target = config.load_shed.target.clone();
move |body| read_job::allow_job(body, conn, target, system_load)
let min_runtime = config.load_shed.min_runtime.clone();
move |body| read_job::allow_job(body, conn, target, system_load, min_runtime)
})
.layer(DefaultBodyLimit::disable()),
)
Expand Down Expand Up @@ -497,6 +498,7 @@ mod tests {
load_shed: config::RSCLoadShedConfig {
tick_rate: 10,
target: 10.0,
min_runtime: 0.5,
},
}
}
Expand Down
3 changes: 2 additions & 1 deletion rust/rsc/src/bin/rsc/read_job.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,10 @@ pub async fn allow_job(
conn: Arc<DatabaseConnection>,
target_load: f64,
system_load: Arc<RwLock<f64>>,
min_runtime: f64,
) -> StatusCode {
// Reject a subset of jobs that are never worth caching
if payload.runtime < 0.1 {
if payload.runtime < min_runtime {
return StatusCode::NOT_ACCEPTABLE;
}

Expand Down

0 comments on commit 14c93d0

Please sign in to comment.