configurable workers

This server will only see occasional traffic so it makes sense to spawn
only limited number of workers as opposed to spawning one worker/thread,
which is the default behavior.

I recommend at least two workers.
This commit is contained in:
Aravinth Manivannan 2021-10-30 15:30:38 +05:30
parent 48e5672e15
commit 8cd9f0030d
Signed by: realaravinth
GPG key ID: AD9F0F08E855ED88
5 changed files with 6 additions and 2 deletions

1
Cargo.lock generated
View file

@ -926,6 +926,7 @@ dependencies = [
"git2", "git2",
"lazy_static", "lazy_static",
"log", "log",
"num_cpus",
"pretty_env_logger", "pretty_env_logger",
"serde 1.0.130", "serde 1.0.130",
"serde_json", "serde_json",

View file

@ -32,3 +32,5 @@ lazy_static = "1.4"
url = "2.2" url = "2.2"
derive_more = "0.99" derive_more = "0.99"
num_cpus = "1.13"

View file

@ -15,3 +15,4 @@ ip= "0.0.0.0"
domain = "localhost" domain = "localhost"
allow_registration = true allow_registration = true
proxy_has_tls = false proxy_has_tls = false
#workers = 2

View file

@ -67,14 +67,13 @@ async fn main() -> std::io::Result<()> {
actix_middleware::DefaultHeaders::new() actix_middleware::DefaultHeaders::new()
.header("Permissions-Policy", "interest-cohort=()"), .header("Permissions-Policy", "interest-cohort=()"),
) )
// .wrap(get_survey_session())
// .wrap(get_identity_service())
.wrap(actix_middleware::NormalizePath::new( .wrap(actix_middleware::NormalizePath::new(
actix_middleware::TrailingSlash::Trim, actix_middleware::TrailingSlash::Trim,
)) ))
.configure(services) .configure(services)
// .app_data(data.clone()) // .app_data(data.clone())
}) })
.workers(SETTINGS.server.workers.unwrap_or(num_cpus::get()))
.bind(SETTINGS.server.get_ip()) .bind(SETTINGS.server.get_ip())
.unwrap() .unwrap()
.run() .run()

View file

@ -30,6 +30,7 @@ pub struct Server {
pub domain: String, pub domain: String,
pub ip: String, pub ip: String,
pub proxy_has_tls: bool, pub proxy_has_tls: bool,
pub workers: Option<usize>,
} }
impl Server { impl Server {