Skip to content

Commit a6ce1f4

Browse files
committed
Allow to override number of actix workers with ACTIX_WORKERS
1 parent f2c1871 commit a6ce1f4

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/app.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ pub fn load_config<P: AsRef<Path>>(path: P) -> io::Result<Config> {
5959
config_data.base_url = format!("http://{}:{}", config_data.host, config_data.port)
6060
}
6161

62+
if let Ok(workers_str) = std::env::var("ACTIX_WORKERS") {
63+
if let Ok(workers) = workers_str.parse::<usize>() {
64+
config_data.workers = workers;
65+
}
66+
}
67+
6268
Ok(config_data)
6369
}
6470

@@ -219,6 +225,7 @@ pub fn create_app(
219225

220226
let bind_to = format!("{}:{}", config.host, config.port);
221227
let server = http_server
228+
.workers(config.workers)
222229
.bind(&bind_to)
223230
.unwrap()
224231
.disable_signals()

src/config.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@ fn default_numcpu() -> u32 {
108108
num_cpus::get() as u32
109109
}
110110

111+
fn default_workers() -> usize {
112+
num_cpus::get()
113+
}
114+
111115
#[derive(Deserialize, Debug, Clone)]
112116
#[serde(rename_all = "kebab-case", deny_unknown_fields)]
113117
pub struct Config {
@@ -136,6 +140,8 @@ pub struct Config {
136140
pub delay_update_secs: u64,
137141
#[serde(default = "default_numcpu")]
138142
pub local_delta_threads: u32,
143+
#[serde(default = "default_workers")]
144+
pub workers: usize,
139145
pub storefront_info_endpoint: Option<String>,
140146
}
141147

0 commit comments

Comments
 (0)