diff --git a/node/src/Worker.ts b/node/src/Worker.ts index e86206d98b..2d5ab30bc2 100644 --- a/node/src/Worker.ts +++ b/node/src/Worker.ts @@ -83,6 +83,11 @@ export type WorkerSettings = { */ libwebrtcFieldTrials?: string; + /** + * Disable liburing (io_uring) despite it's supported in current host. + */ + disableLiburing?: boolean; + /** * Custom application data. */ @@ -287,6 +292,7 @@ export class Worker< dtlsCertificateFile, dtlsPrivateKeyFile, libwebrtcFieldTrials, + disableLiburing, appData, }: WorkerSettings) { super(); @@ -338,6 +344,10 @@ export class Worker< spawnArgs.push(`--libwebrtcFieldTrials=${libwebrtcFieldTrials}`); } + if (disableLiburing) { + spawnArgs.push(`--disableLiburing`); + } + logger.debug( 'spawning worker process: %s %s', spawnBin, diff --git a/rust/src/worker.rs b/rust/src/worker.rs index 60a08b67f0..68a9ecbadd 100644 --- a/rust/src/worker.rs +++ b/rust/src/worker.rs @@ -192,6 +192,8 @@ pub struct WorkerSettings { /// "WebRTC-Bwe-AlrLimitedBackoff/Enabled/". #[doc(hidden)] pub libwebrtc_field_trials: Option, + /// Disable liburing (io_uring) despite it's supported in current host. + pub disable_liburing: Option, /// Function that will be called under worker thread before worker starts, can be used for /// pinning worker threads to CPU cores. pub thread_initializer: Option>, @@ -221,6 +223,7 @@ impl Default for WorkerSettings { rtc_port_range: 10000..=59999, dtls_files: None, libwebrtc_field_trials: None, + disable_liburing: None, thread_initializer: None, app_data: AppData::default(), } @@ -235,6 +238,7 @@ impl fmt::Debug for WorkerSettings { rtc_port_range, dtls_files, libwebrtc_field_trials, + disable_liburing, thread_initializer, app_data, } = self; @@ -245,6 +249,7 @@ impl fmt::Debug for WorkerSettings { .field("rtc_port_range", &rtc_port_range) .field("dtls_files", &dtls_files) .field("libwebrtc_field_trials", &libwebrtc_field_trials) + .field("disable_liburing", &disable_liburing) .field( "thread_initializer", &thread_initializer.as_ref().map(|_| "ThreadInitializer"), @@ -356,6 +361,7 @@ impl Inner { rtc_port_range, dtls_files, libwebrtc_field_trials, + disable_liburing, thread_initializer, app_data, }: WorkerSettings, @@ -404,6 +410,10 @@ impl Inner { )); } + if let Some(disable_liburing) = disable_liburing { + spawn_args.push(format!("--disable_liburing")); + } + let id = WorkerId::new(); debug!( "spawning worker with arguments [id:{}]: {}", diff --git a/worker/include/Settings.hpp b/worker/include/Settings.hpp index 06a66f4bf6..1025260e3d 100644 --- a/worker/include/Settings.hpp +++ b/worker/include/Settings.hpp @@ -39,6 +39,7 @@ class Settings std::string dtlsCertificateFile; std::string dtlsPrivateKeyFile; std::string libwebrtcFieldTrials{ "WebRTC-Bwe-AlrLimitedBackoff/Enabled/" }; + bool liburingDisabled{ false }; }; public: diff --git a/worker/src/DepLibUring.cpp b/worker/src/DepLibUring.cpp index c5e8aed778..8ad9bc8555 100644 --- a/worker/src/DepLibUring.cpp +++ b/worker/src/DepLibUring.cpp @@ -4,6 +4,7 @@ #include "DepLibUring.hpp" #include "Logger.hpp" #include "MediaSoupErrors.hpp" +#include "Settings.hpp" #include "Utils.hpp" #include #include @@ -11,9 +12,9 @@ /* Static variables. */ bool DepLibUring::enabled{ false }; -/* liburing instance per thread. */ +// liburing instance per thread. thread_local DepLibUring::LibUring* DepLibUring::liburing{ nullptr }; -/* Completion queue entry array used to retrieve processes tasks. */ +// Completion queue entry array used to retrieve processes tasks. thread_local struct io_uring_cqe* cqes[DepLibUring::QueueDepth]; /* Static methods for UV callbacks. */ @@ -121,6 +122,13 @@ void DepLibUring::ClassInit() MS_DEBUG_TAG(info, "liburing version: \"%i.%i\"", mayor, minor); + if (Settings::configuration.liburingDisabled) + { + MS_DEBUG_TAG(info, "liburing disabled by user settings"); + + return; + } + // This must be called first. DepLibUring::CheckRuntimeSupport(); diff --git a/worker/src/Settings.cpp b/worker/src/Settings.cpp index a989bc44e5..029083a13a 100644 --- a/worker/src/Settings.cpp +++ b/worker/src/Settings.cpp @@ -60,7 +60,8 @@ void Settings::SetConfiguration(int argc, char* argv[]) { "dtlsCertificateFile", optional_argument, nullptr, 'c' }, { "dtlsPrivateKeyFile", optional_argument, nullptr, 'p' }, { "libwebrtcFieldTrials", optional_argument, nullptr, 'W' }, - { nullptr, 0, nullptr, 0 } + { "disableLiburing", no_argument, nullptr, 'd' }, + { nullptr, 0, nullptr, 0 } }; // clang-format on std::string stringValue; @@ -73,13 +74,9 @@ void Settings::SetConfiguration(int argc, char* argv[]) optind = 1; // Set explicitly, otherwise subsequent runs will fail. opterr = 0; // Don't allow getopt to print error messages. + while ((c = getopt_long_only(argc, argv, "", options, &optionIdx)) != -1) { - if (!optarg) - { - MS_THROW_TYPE_ERROR("unknown configuration parameter: %s", optarg); - } - switch (c) { case 'l': @@ -158,6 +155,13 @@ void Settings::SetConfiguration(int argc, char* argv[]) break; } + case 'd': + { + Settings::configuration.liburingDisabled = true; + + break; + } + // Invalid option. case '?': {