diff options
| author | David Lönnhager <david.l@mullvad.net> | 2020-08-28 17:31:33 +0200 |
|---|---|---|
| committer | David Lönnhager <david.l@mullvad.net> | 2020-09-01 14:17:21 +0200 |
| commit | c625b14ca68256111bc363e5883fa4819c54d5c7 (patch) | |
| tree | 2b896225707dde429873ad9731032a50ed668864 | |
| parent | 10eae3e1cfe0be553e1268865662d05578142326 (diff) | |
| download | mullvadvpn-c625b14ca68256111bc363e5883fa4819c54d5c7.tar.xz mullvadvpn-c625b14ca68256111bc363e5883fa4819c54d5c7.zip | |
Reduce excessive thread count
| -rw-r--r-- | mullvad-daemon/src/lib.rs | 1 | ||||
| -rw-r--r-- | mullvad-daemon/src/main.rs | 16 | ||||
| -rw-r--r-- | mullvad-daemon/src/runtime.rs | 11 | ||||
| -rw-r--r-- | mullvad-daemon/src/system_service.rs | 13 | ||||
| -rw-r--r-- | mullvad-jni/src/lib.rs | 8 | ||||
| -rw-r--r-- | mullvad-problem-report/src/lib.rs | 2 | ||||
| -rw-r--r-- | talpid-core/src/routing/unix.rs | 12 | ||||
| -rw-r--r-- | talpid-core/src/tunnel/openvpn.rs | 1 | ||||
| -rw-r--r-- | talpid-openvpn-plugin/src/processing.rs | 1 |
9 files changed, 42 insertions, 23 deletions
diff --git a/mullvad-daemon/src/lib.rs b/mullvad-daemon/src/lib.rs index 412147c2b5..cd2d506c2b 100644 --- a/mullvad-daemon/src/lib.rs +++ b/mullvad-daemon/src/lib.rs @@ -14,6 +14,7 @@ pub mod management_interface; mod relays; #[cfg(not(target_os = "android"))] pub mod rpc_uniqueness_check; +pub mod runtime; mod settings; pub mod version; mod version_check; diff --git a/mullvad-daemon/src/main.rs b/mullvad-daemon/src/main.rs index b7e96d682c..4e055183b9 100644 --- a/mullvad-daemon/src/main.rs +++ b/mullvad-daemon/src/main.rs @@ -4,7 +4,9 @@ use log::{debug, error, info, warn}; use mullvad_daemon::{ logging, management_interface::{ManagementInterfaceEventBroadcaster, ManagementInterfaceServer}, - rpc_uniqueness_check, version, Daemon, DaemonCommandChannel, DaemonCommandSender, + rpc_uniqueness_check, + runtime::new_runtime_builder, + version, Daemon, DaemonCommandChannel, DaemonCommandSender, }; use std::{path::PathBuf, thread, time::Duration}; use talpid_types::ErrorExt; @@ -24,14 +26,10 @@ fn main() { std::process::exit(1) }); - let mut runtime = tokio::runtime::Builder::new() - .threaded_scheduler() - .enable_all() - .build() - .unwrap_or_else(|error| { - eprintln!("{}", error.display_chain()); - std::process::exit(1); - }); + let mut runtime = new_runtime_builder().build().unwrap_or_else(|error| { + eprintln!("{}", error.display_chain()); + std::process::exit(1); + }); let exit_code = match runtime.block_on(run_platform(config, log_dir)) { Ok(_) => 0, diff --git a/mullvad-daemon/src/runtime.rs b/mullvad-daemon/src/runtime.rs new file mode 100644 index 0000000000..3c60b133e8 --- /dev/null +++ b/mullvad-daemon/src/runtime.rs @@ -0,0 +1,11 @@ +use tokio::runtime; + +pub fn new_runtime_builder() -> runtime::Builder { + let mut builder = runtime::Builder::new(); + builder + .threaded_scheduler() + .core_threads(4) + .max_threads(8) + .enable_all(); + builder +} diff --git a/mullvad-daemon/src/system_service.rs b/mullvad-daemon/src/system_service.rs index ef44af49a1..cb27a443e8 100644 --- a/mullvad-daemon/src/system_service.rs +++ b/mullvad-daemon/src/system_service.rs @@ -1,5 +1,5 @@ use crate::cli; -use mullvad_daemon::DaemonShutdownHandle; +use mullvad_daemon::{runtime::new_runtime_builder, DaemonShutdownHandle}; use std::{ env, ffi::OsString, @@ -103,10 +103,7 @@ fn run_service() -> Result<(), String> { let log_dir = crate::get_log_dir(cli::get_config()).expect("Log dir should be available here"); - let runtime = tokio::runtime::Builder::new() - .threaded_scheduler() - .enable_all() - .build(); + let runtime = new_runtime_builder().build(); let mut runtime = match runtime { Err(error) => { persistent_service_status @@ -118,7 +115,7 @@ fn run_service() -> Result<(), String> { }; let result = runtime.block_on(crate::create_daemon(log_dir)); - if let Ok(daemon) = result { + let result = if let Ok(daemon) = result { let shutdown_handle = daemon.shutdown_handle(); // Register monitor that translates `ServiceControl` to Daemon events @@ -134,7 +131,9 @@ fn run_service() -> Result<(), String> { runtime .block_on(daemon.run()) .map_err(|e| e.display_chain()) - } + } else { + result.map(|_| ()) + }; let exit_code = match result { Ok(()) => { diff --git a/mullvad-jni/src/lib.rs b/mullvad-jni/src/lib.rs index 027ea16a4a..1abd4d093d 100644 --- a/mullvad-jni/src/lib.rs +++ b/mullvad-jni/src/lib.rs @@ -17,7 +17,9 @@ use jnix::{ }, FromJava, IntoJava, JnixEnv, }; -use mullvad_daemon::{exception_logging, logging, version, Daemon, DaemonCommandChannel}; +use mullvad_daemon::{ + exception_logging, logging, runtime::new_runtime_builder, version, Daemon, DaemonCommandChannel, +}; use mullvad_rpc::{rest::Error as RestError, StatusCode}; use mullvad_types::account::{AccountData, VoucherSubmission}; use std::{ @@ -206,9 +208,7 @@ fn spawn_daemon( .map_err(Error::CreateGlobalReference)?; let (tx, rx) = mpsc::channel(); - let mut runtime = tokio::runtime::Builder::new() - .threaded_scheduler() - .enable_all() + let mut runtime = new_runtime_builder() .build() .map_err(Error::InitializeTokioRuntime)?; diff --git a/mullvad-problem-report/src/lib.rs b/mullvad-problem-report/src/lib.rs index e89bd13aea..4265d70268 100644 --- a/mullvad-problem-report/src/lib.rs +++ b/mullvad-problem-report/src/lib.rs @@ -267,7 +267,7 @@ pub fn send_problem_report( ProblemReport::parse_metadata(&report_content).unwrap_or_else(|| metadata::collect()); let runtime = tokio::runtime::Builder::new() - .threaded_scheduler() + .basic_scheduler() .enable_all() .build() .map_err(Error::CreateRuntime)?; diff --git a/talpid-core/src/routing/unix.rs b/talpid-core/src/routing/unix.rs index b84e5850b7..a59ee6ed27 100644 --- a/talpid-core/src/routing/unix.rs +++ b/talpid-core/src/routing/unix.rs @@ -7,7 +7,7 @@ use futures::channel::{ mpsc::{self, UnboundedSender}, oneshot, }; -use std::collections::HashSet; +use std::{collections::HashSet, io}; use talpid_types::ErrorExt; #[cfg(target_os = "linux")] @@ -39,6 +39,9 @@ pub enum Error { /// Failed to spawn route manager future #[error(display = "Failed to spawn route manager on the provided executor")] FailedToSpawnManager, + /// Failed to spawn route manager runtime + #[error(display = "Failed to spawn route manager runtime")] + FailedToSpawnRuntime(#[error(source)] io::Error), /// Attempt to use route manager that has been dropped #[error(display = "Cannot send message to route manager since it is down")] RouteManagerDown, @@ -78,7 +81,12 @@ impl RouteManager { /// routes. pub fn new(required_routes: HashSet<RequiredRoute>) -> Result<Self, Error> { let (manage_tx, manage_rx) = mpsc::unbounded(); - let mut runtime = tokio::runtime::Runtime::new().expect("Failed to spawn runtime"); + let mut runtime = tokio::runtime::Builder::new() + .threaded_scheduler() + .core_threads(1) + .max_threads(1) + .enable_all() + .build()?; let manager = runtime.block_on(imp::RouteManagerImpl::new(required_routes))?; runtime.handle().spawn(manager.run(manage_rx)); diff --git a/talpid-core/src/tunnel/openvpn.rs b/talpid-core/src/tunnel/openvpn.rs index da3b507bb1..02ff92f4e7 100644 --- a/talpid-core/src/tunnel/openvpn.rs +++ b/talpid-core/src/tunnel/openvpn.rs @@ -242,6 +242,7 @@ impl<C: OpenVpnBuilder + 'static> OpenVpnMonitor<C> { let mut runtime = tokio::runtime::Builder::new() .threaded_scheduler() .core_threads(1) + .max_threads(1) .enable_all() .build() .map_err(Error::RuntimeError)?; diff --git a/talpid-openvpn-plugin/src/processing.rs b/talpid-openvpn-plugin/src/processing.rs index f03442e2fb..291ad41092 100644 --- a/talpid-openvpn-plugin/src/processing.rs +++ b/talpid-openvpn-plugin/src/processing.rs @@ -28,6 +28,7 @@ impl EventProcessor { let mut runtime = runtime::Builder::new() .basic_scheduler() .core_threads(1) + .max_threads(1) .enable_all() .build() .map_err(Error::CreateRuntime)?; |
