Skip to content

mavros: make UAS executor threads configurable#2189

Open
jacog2 wants to merge 1 commit into
mavlink:ros2from
jacog2:codex-configurable-uas-executor-threads
Open

mavros: make UAS executor threads configurable#2189
jacog2 wants to merge 1 commit into
mavlink:ros2from
jacog2:codex-configurable-uas-executor-threads

Conversation

@jacog2
Copy link
Copy Markdown

@jacog2 jacog2 commented May 11, 2026

Summary

Adds a MAVROS_UAS_EXECUTOR_THREADS environment override for the UAS plugin executor worker count.

This gives ROS 2 users a low-risk mitigation path for high CPU usage by allowing deployments to run the UAS executor with 2 worker threads, while preserving the current hardware-concurrency-based default when the variable is unset.

Closes #2031.

Validation

  • git diff --check

I could not run colcon test locally in this Windows environment because ROS 2/colcon and a C++ compiler are not installed here.

{
constexpr size_t kMinExecutorThreads = 2;
constexpr size_t kMaxExecutorThreads = 16;
constexpr std::string_view kExecutorThreadsEnv = "MAVROS_UAS_EXECUTOR_THREADS";
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer old C-convention for the constants.
Also i don't think it really needs string view.

const auto result = std::from_chars(input.data(), input.data() + input.size(), threads);
if (result.ec != std::errc{} || result.ptr != input.data() + input.size() || threads == 0) {
return 0;
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

std::stoi() seems much more compact...

return 0;
}

return std::clamp(threads, kMinExecutorThreads, kMaxExecutorThreads);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If user sets amount of threads we should only limit minimum to be 2+.

@vooon vooon added the ros2 label May 11, 2026
@vooon vooon added this to the Version 2.15 milestone May 11, 2026
@apples-kksk
Copy link
Copy Markdown
Contributor

Hi @jacog2, I prepared a small local patch for the three review points here: switch the env parsing to std::stoi(), use C-style constant names without string_view, and only clamp user-provided thread counts to the minimum of 2. I also adjusted the README wording to remove the old 2-16 limit.

Would you like me to send that patch somehow, or would you prefer to update the PR yourself?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CPU usage 4x higher in ROS 2 than ROS 1

3 participants