Skip to content

Commit aed30ed

Browse files
authored
actix: Force at least 2 workers, even with 1 core (#35)
1 parent 078d96b commit aed30ed

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

blade/main.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,17 @@ cfg_if! {
260260
let actix_state = state.clone();
261261
let cleanup_state = state.clone();
262262
tracing::info!("Starting blade server at: {}", addr.to_string());
263+
// NOTE: Ensure we have at least 2 workers so that a single long-running
264+
// request (e.g. expensive HTML render / large artifact fetch) on a
265+
// single-core or constrained container doesn't starve lightweight
266+
// endpoints like /healthz. In some deployment environments (k8s with
267+
// a cpuset of 1) Actix would otherwise create only 1 worker and all
268+
// other requests would queue behind the long task.
269+
let workers = std::thread::available_parallelism()
270+
.map(|n| n.get())
271+
.unwrap_or(1)
272+
.max(2);
273+
263274
let fut1 = HttpServer::new(move || {
264275
let leptos_options = conf.leptos_options.clone();
265276
let rt_state = actix_state.clone();
@@ -292,6 +303,7 @@ cfg_if! {
292303
.app_data(web::Data::new(conf.leptos_options.to_owned()))
293304
.wrap(TracingLogger::<BladeRootSpanBuilder>::new())
294305
})
306+
.workers(workers)
295307
.bind(&addr)?
296308
.run();
297309
let re_handle = Arc::new(Mutex::new(regex::Regex::new(&args.debug_message_pattern)?));

0 commit comments

Comments
 (0)