Skip to content

Commit

Permalink
Feat/set cpu limit (#529)
Browse files Browse the repository at this point in the history
* feat: remove redundant actix worker limit

* feat: remove redundant build job limit

* feat: set cpu limit for deployer container

* fix: limit actix worker and build jobs to 4
  • Loading branch information
oddgrd authored Dec 14, 2022
1 parent 8e93e87 commit 5c9487d
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
4 changes: 2 additions & 2 deletions deployer/src/deployment/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,8 +318,8 @@ async fn run_pre_deploy_tests(
// recompiled in debug mode for the tests, reducing memory usage during deployment.
compile_opts.build_config.requested_profile = InternedString::new("release");

// Build tests with a maximum of 8 workers.
compile_opts.build_config.jobs = 8;
// Build tests with a maximum of 4 workers.
compile_opts.build_config.jobs = 4;

let opts = TestOptions {
compile_opts,
Expand Down
4 changes: 4 additions & 0 deletions gateway/src/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -535,8 +535,12 @@ impl ProjectCreating {
"Source": format!("{prefix}{project_name}_vol"),
"Type": "volume"
}],
// https://docs.docker.com/config/containers/resource_constraints/#memory
"Memory": 6442450000i64, // 6 GiB hard limit
"MemoryReservation": 4295000000i64, // 4 GiB soft limit, applied if host is low on memory
// https://docs.docker.com/config/containers/resource_constraints/#cpu
"CpuPeriod": 100000i64,
"CpuQuota": 400000i64
});

debug!(
Expand Down
4 changes: 2 additions & 2 deletions service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -560,8 +560,8 @@ where
F: FnOnce(&mut actix_web::web::ServiceConfig) + Sync + Send + Clone + 'static,
{
async fn bind(mut self: Box<Self>, addr: SocketAddr) -> Result<(), Error> {
// Start a worker for each cpu, but no more than 8.
let worker_count = num_cpus::get().max(8);
// Start a worker for each cpu, but no more than 4.
let worker_count = num_cpus::get().max(4);

let srv = actix_web::HttpServer::new(move || actix_web::App::new().configure(self.clone()))
.workers(worker_count)
Expand Down
4 changes: 2 additions & 2 deletions service/src/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,10 +223,10 @@ fn get_compile_options(config: &Config, release_mode: bool) -> anyhow::Result<Co
InternedString::new("dev")
};

// This sets the max workers for cargo build to 8 for release mode (aka deployment),
// This sets the max workers for cargo build to 4 for release mode (aka deployment),
// but leaves it as default (num cpus) for local runs
if release_mode {
opts.build_config.jobs = 8
opts.build_config.jobs = 4
};

Ok(opts)
Expand Down

0 comments on commit 5c9487d

Please sign in to comment.