aboutsummaryrefslogtreecommitdiffstats
path: root/components/net/async_runtime.rs
diff options
context:
space:
mode:
authorJonathan Schwender <55576758+jschwe@users.noreply.github.com>2024-12-07 06:25:17 +0100
committerGitHub <noreply@github.com>2024-12-07 05:25:17 +0000
commit68a27946bf0c2a1398df03930c163e40468d016d (patch)
tree908e06c0961b7a248afd0d9b7bfd4a1fe0057c1c /components/net/async_runtime.rs
parent4242ff9626048942d72f0352c7f8a8edecdd6a08 (diff)
downloadservo-68a27946bf0c2a1398df03930c163e40468d016d.tar.gz
servo-68a27946bf0c2a1398df03930c163e40468d016d.zip
Add prefs to limit threadpool sizes (#34478)
* Add prefs to limit threadpool sizes Add preferences to control the size of threadpools, so that we can easily reduce the amount of runtime threads and test which pools benefit from more threads. Signed-off-by: Jonathan Schwender <schwenderjonathan@gmail.com> * Add pref for Webrender threadpool Add a preference to limit the size of the webrender threadpool. Note: WebRender by default calls hooks which register the threads with a profiler instance that the embedder can register with webrender. Servo currently doesn't register such a profiler with webrender, but in the future we might also want to profile the webrender threadpool. Signed-off-by: Jonathan Schwender <schwenderjonathan@gmail.com> --------- Signed-off-by: Jonathan Schwender <schwenderjonathan@gmail.com>
Diffstat (limited to 'components/net/async_runtime.rs')
-rw-r--r--components/net/async_runtime.rs30
1 files changed, 26 insertions, 4 deletions
diff --git a/components/net/async_runtime.rs b/components/net/async_runtime.rs
index 144f4262835..7d1fb9daeaa 100644
--- a/components/net/async_runtime.rs
+++ b/components/net/async_runtime.rs
@@ -1,10 +1,32 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
-
+use std::cmp::Ord;
+use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::{LazyLock, Mutex};
+use std::thread;
-use tokio::runtime::Runtime;
+use tokio::runtime::{Builder, Runtime};
-pub static HANDLE: LazyLock<Mutex<Option<Runtime>>> =
- LazyLock::new(|| Mutex::new(Some(Runtime::new().unwrap())));
+pub static HANDLE: LazyLock<Mutex<Option<Runtime>>> = LazyLock::new(|| {
+ Mutex::new(Some(
+ Builder::new_multi_thread()
+ .thread_name_fn(|| {
+ static ATOMIC_ID: AtomicUsize = AtomicUsize::new(0);
+ let id = ATOMIC_ID.fetch_add(1, Ordering::Relaxed);
+ format!("tokio-runtime-{}", id)
+ })
+ .worker_threads(
+ thread::available_parallelism()
+ .map(|i| i.get())
+ .unwrap_or(servo_config::pref!(threadpools.fallback_worker_num) as usize)
+ .min(
+ servo_config::pref!(threadpools.async_runtime_workers.max).max(1) as usize,
+ ),
+ )
+ .enable_io()
+ .enable_time()
+ .build()
+ .unwrap(),
+ ))
+});