Skip to content

Commit 151004c

Browse files
committed
fix: make major worker tasks managed separately from the user worker
(cherry picked from commit a80bf00)
1 parent c531f86 commit 151004c

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

crates/base/src/rt_worker/rt.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,13 @@ pub static SUPERVISOR_RT: Lazy<tokio::runtime::Runtime> = Lazy::new(|| {
88
.unwrap()
99
});
1010

11-
pub static WORKER_RT: Lazy<tokio_util::task::LocalPoolHandle> = Lazy::new(|| {
11+
// NOTE: This pool is for the main and event workers. The reason why they should
12+
// separate from the user worker pool is they can starve them if user workers
13+
// are saturated.
14+
pub static PRIMARY_WORKER_RT: Lazy<tokio_util::task::LocalPoolHandle> =
15+
Lazy::new(|| tokio_util::task::LocalPoolHandle::new(2));
16+
17+
pub static USER_WORKER_RT: Lazy<tokio_util::task::LocalPoolHandle> = Lazy::new(|| {
1218
let maybe_pool_size = std::env::var("EDGE_RUNTIME_WORKER_POOL_SIZE")
1319
.ok()
1420
.and_then(|it| it.parse::<usize>().ok());

crates/base/src/rt_worker/worker.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,13 @@ impl Worker {
9898
let is_user_worker = opts.conf.is_user_worker();
9999

100100
let cancel = self.cancel.clone();
101+
let rt = if is_user_worker {
102+
&rt::USER_WORKER_RT
103+
} else {
104+
&rt::PRIMARY_WORKER_RT
105+
};
101106

102-
let _worker_handle = rt::WORKER_RT.spawn_pinned(move || {
107+
let _worker_handle = rt.spawn_pinned(move || {
103108
tokio::task::spawn_local(async move {
104109
let (maybe_cpu_usage_metrics_tx, maybe_cpu_usage_metrics_rx) = is_user_worker
105110
.then(unbounded_channel::<CPUUsageMetrics>)

0 commit comments

Comments
 (0)