Git Product home page Git Product logo

Comments (7)

jacquelinekay avatar jacquelinekay commented on September 28, 2024 1

I think the use case for the multi-threaded executor is to take advantage of multiple core systems to execute as many jobs in parallel as possible. Though I also don't recall seeing it mentioned in the design documents. If you take a look at multi_threaded_executor.hpp, it uses std::thread::hardware_concurrency to determine the number of threads to spawn:

https://github.com/ros2/rclcpp/blob/master/rclcpp/include/rclcpp/executors/multi_threaded_executor.hpp#L47

http://en.cppreference.com/w/cpp/thread/thread/hardware_concurrency

This call is supposed to return the number of cores of the CPU executing the code, though it might not be implemented on all platforms/architectures.

It's up to the user to avoid data races in the MultiThreadedExecutor. It provides a mutex to ensure that only one thread accesses the get_next_executable function, but there isn't more synchronization than that.

from rclcpp.

jacquelinekay avatar jacquelinekay commented on September 28, 2024

Yes, the multi-threaded executor that is currently implemented will not tie work coming from a particular node to a particular thread.

from rclcpp.

wjwwood avatar wjwwood commented on September 28, 2024

The executor could be more sophisticated and have some notion of affinity. We don't currently have this, but it would be interesting to try it out to see if our abstractions provide enough information to achieve it.

from rclcpp.

jacquelinekay avatar jacquelinekay commented on September 28, 2024

Agreed. I'm not sure what @BobDean had in mind when he opened this question, but one use case I see for thread affinity is prioritizing work from a certain node by scheduling it in a high-priority/realtime thread.

It should be fairly easy to implement a "ThreadAffinityExecutor" (or whatever we want to call it), since the AnyExecutable struct has a shared pointer to the parent node of the executable.

from rclcpp.

BobDean avatar BobDean commented on September 28, 2024

I am wondering about its applicability to tightly timed nodes, and the ability to debug multi-threaded behavior when the worker is moving between threads between executions. what is the use case for the multithreaded executor? did i miss it on the design docs?

from rclcpp.

wjwwood avatar wjwwood commented on September 28, 2024

but there isn't more synchronization than that.

Well, there is also the callback groups, which can prevent certain user provided code from being run in parallel or in a reentrant fashion. This might let the user avoid having their own synchronization patterns and can allow the system to avoid things like locking the worker threads. See my roscon talk:

http://roscon.ros.org/2014/wp-content/uploads/2014/07/ROSCON-2014-Why-you-want-to-use-ROS-2.pdf (see page 17)

from rclcpp.

wjwwood avatar wjwwood commented on September 28, 2024

@BobDean I'm going to close this issue too. I think my most recent comment addresses some of the "why multithreaded executor?". Another thing I'll add is that the multi-threaded executor allows you to utilize as much of the system as possible when your CPU bound (basically a thread-pool as you said). The difference is that allows uncoordinated and uncoupled pieces of code (separate nodes, a.k.a. nodelets) to shared the thread pool, which is a bit above and beyond what a normal thread-pool does for you.

Feel free to continue the discussion or move it to the mailing list.

from rclcpp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.