Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add events-executor and timers-manager in rclcpp #2155

Merged
merged 9 commits into from
Apr 17, 2023

Conversation

alsora
Copy link
Collaborator

@alsora alsora commented Apr 4, 2023

This PR introduces the events-executor based on the design here ros2/design#305 and the already-existing open-source implementation in https://github.com/irobot-ros/events-executor.

FYI @clalancette @wjwwood @mjcarroll @mauropasse @bpwilcox

This PR currently targets Michael's branch as it depends on it.
Will target the main branch after this PR is merged.
#2143

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think that most (all?) of the tests here can probably moved to the test_executors.cpp file as they are valid tests for all executors.

private:
// The underlying queue implementation
std::queue<rclcpp::experimental::executors::ExecutorEvent> event_queue_;
// Mutex to protect the insertion/extraction of events in the queue
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is not just insertion/extraction, is also checking size and if empty:

Suggested change
// Mutex to protect the insertion/extraction of events in the queue
// Mutex to protect concurrent actions over the queue

// The second argument of the callback should identify which guard condition
// triggered the event.
// We could indicate which of the guard conditions was triggered, but the executor
// is already going to check that.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Actually the executor doesn't check which guard condition was triggered, it just knows the waitable to whom it belongs.

If the executor knows which gc was triggered, it could more efficiently do work on the node or entity having this gc.
For example right know, a single gc triggered due addition of an entity to a node, will result on re-setting the callbacks to all nodes entities registered in the executor. We could use this info to get only the node having this gc and setting the callbacks to it. This is just a peformance improvement, but we already have the notify_waitable_event_pushed_ which is mitigating this issue.
Also if we manage to add apis to not notify the executor for every entity added, until manually done later, this will be less a problem

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Few comments here:

  1. Yes, the executor doesn't check which guard condition triggered, but we could easily do that (maybe I should change the should into could in the comment)
  2. This new implementation does not re-set the callbacks to all the nodes. It performs a loop on all the entities to understand which ones have been added/removed and then it does only the necessary work. By taking into account the possible improvement mentioned in (1) we could speed up the loop (i.e. loop only on one node, rather than on all nodes), but the set/unset would remain equivalent.

IMO, the fact that we don't reset everything, plus the presence of the notify_waitable_event_pushed_ flag, should already improve the resource usage during startup.

Controlling the notification to the executor would still be important to reduce the amount of time we loop over the entities.

Copy link
Member

Choose a reason for hiding this comment

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

Also if we manage to add apis to not notify the executor for every entity added, until manually done later, this will be less a problem

While we can't get this for Iron, I would like to get it in sooner rather than later in rolling while we all still have context.

@mjcarroll
Copy link
Member

  • Linux Build Status
  • Linux-aarch64 Build Status
  • Windows Build Status

@alsora alsora force-pushed the asoragna/events-executor branch 2 times, most recently from 0816eaf to be41ece Compare April 14, 2023 12:39
@alsora
Copy link
Collaborator Author

alsora commented Apr 14, 2023

Rebased with latest "exectuor_structures" branch;

  • fixed uncrustify and comments a642e4e
  • fixed some small issues if not using events-executor be41ece
  • Linux Build Status
  • Linux-aarch64 Build Status
  • Windows Build Status

@delete-merged-branch delete-merged-branch bot deleted the branch rolling April 14, 2023 18:56
@alsora alsora changed the base branch from mjcarroll/executor_structures to rolling April 14, 2023 19:01
@alsora
Copy link
Collaborator Author

alsora commented Apr 14, 2023

New CI

  • Linux Build Status
  • Linux-aarch64 Build Status
  • Windows Build Status

fix check for execute_timers_separate_thread; ignore on_ready_callback if asked to execute a timer;  reduce usage of void pointers

Signed-off-by: Alberto Soragna <[email protected]>
Copy link
Member

@wjwwood wjwwood left a comment

Choose a reason for hiding this comment

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

lgtm

Copy link
Contributor

@clalancette clalancette left a comment

Choose a reason for hiding this comment

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

This looks good to me. I'm going to run CI on this again since there have been host of changes since the last one. I'll also run Windows Debug and RHEL.

@clalancette
Copy link
Contributor

clalancette commented Apr 17, 2023

CI:

  • Linux Build Status
  • Linux-aarch64 Build Status
  • Windows Build Status
  • Windows Debug Build Status
  • RHEL Build Status

@clalancette
Copy link
Contributor

All right, everything is green here so going ahead and merging. Thanks everyone for the reviews and work.

@clalancette clalancette merged commit a7048e1 into rolling Apr 17, 2023
@delete-merged-branch delete-merged-branch bot deleted the asoragna/events-executor branch April 17, 2023 18:34
alsora added a commit to irobot-ros/rclcpp that referenced this pull request Apr 28, 2023
* add events-executor and timers-manager in rclcpp

fix check for execute_timers_separate_thread; ignore on_ready_callback if asked to execute a timer;  reduce usage of void pointers

* have the executor notify waitable fiddle with guard condition callbacks only if necessary

Signed-off-by: Alberto Soragna <[email protected]>
alsora added a commit to irobot-ros/rclcpp that referenced this pull request Apr 29, 2023
* add events-executor and timers-manager in rclcpp

fix check for execute_timers_separate_thread; ignore on_ready_callback if asked to execute a timer;  reduce usage of void pointers

* have the executor notify waitable fiddle with guard condition callbacks only if necessary

Signed-off-by: Alberto Soragna <[email protected]>
alsora added a commit to irobot-ros/rclcpp that referenced this pull request Apr 29, 2023
* add events-executor and timers-manager in rclcpp

fix check for execute_timers_separate_thread; ignore on_ready_callback if asked to execute a timer;  reduce usage of void pointers

* have the executor notify waitable fiddle with guard condition callbacks only if necessary

Signed-off-by: Alberto Soragna <[email protected]>
alsora added a commit to irobot-ros/rclcpp that referenced this pull request Apr 29, 2023
* add events-executor and timers-manager in rclcpp

fix check for execute_timers_separate_thread; ignore on_ready_callback if asked to execute a timer;  reduce usage of void pointers

* have the executor notify waitable fiddle with guard condition callbacks only if necessary

Signed-off-by: Alberto Soragna <[email protected]>
alsora added a commit to irobot-ros/rclcpp that referenced this pull request May 3, 2023
* add events-executor and timers-manager in rclcpp

fix check for execute_timers_separate_thread; ignore on_ready_callback if asked to execute a timer;  reduce usage of void pointers

* have the executor notify waitable fiddle with guard condition callbacks only if necessary

Signed-off-by: Alberto Soragna <[email protected]>
@tonynajjar
Copy link
Contributor

Any plans to backport this to Humble or is it too complex to do so?

@alsora
Copy link
Collaborator Author

alsora commented May 5, 2023

We don't currently have plans to do it.
As a reminder, there's this repository with the events-executor code that is compatible with Humble https://github.com/irobot-ros/events-executor
(although I don't remember if Humble contains all the needed features or if you still would need to build it from sources and apply some patches).

The implementation of the events-executor that got merged in this PR is slightly different from what is in the old repo.
In particular, it uses new entity collection classes that just got developed for ROS 2 Iron.

If all the prerequisites are there already, it should be possible to backport without touching existing files, and I would be more than happy to review the PRs.

@russkel
Copy link

russkel commented May 19, 2023

Would it be possible to get this into iron? Or is that something not done with non-LTS releases? Seems unfortunate to have to wait till next ROS2 release for this.

@clalancette
Copy link
Contributor

Would it be possible to get this into iron? Or is that something not done with non-LTS releases? Seems unfortunate to have to wait till next ROS2 release for this.

This is currently in Iron.

@russkel
Copy link

russkel commented May 21, 2023

Would it be possible to get this into iron? Or is that something not done with non-LTS releases? Seems unfortunate to have to wait till next ROS2 release for this.

This is currently in Iron.

Ah great. I must have missed it in the release notes.

@tonynajjar
Copy link
Contributor

tonynajjar commented May 21, 2023

I think it's not in the release notes, at least it wasn't 5 days ago when I looked. It would be useful to add! (+ How to make the switch)

@clalancette
Copy link
Contributor

@mjcarroll is adding it in ros2/ros2_documentation#3662

Barry-Xu-2018 pushed a commit to Barry-Xu-2018/rclcpp that referenced this pull request Jan 12, 2024
* add events-executor and timers-manager in rclcpp

fix check for execute_timers_separate_thread; ignore on_ready_callback if asked to execute a timer;  reduce usage of void pointers

* have the executor notify waitable fiddle with guard condition callbacks only if necessary

Signed-off-by: Alberto Soragna <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants