ROS2 Middleware Change Proposal

Hi! In the last meeting of the middleware working group, it has been discussed how the new approach speeds up the execution of events having a dedicated thread waiting for events to arrive to the queue, and improving the speed search for the right executable.

The benefits are not only those (fast search and execute), so to have a better appreciation I wanted to add more information about the current maintenance of the waitset (not needed in the new proposal).

The current approach relies on setting to NULL the pointers of entities with no work to do (done both for rmw and rcl waitsets). This means that after each execution, the wait set needs to be rebuilt from scratch to start a fresh run with all valid pointers.

More specifically, this is what it has to be done for each run (in our case, at a high frequency)

Analysis of the most performant executor, the StaticSingleThreadedExecutor:

Clear wait set
 1. Check arguments for NULL
 2. memset to zero and zero init indexes of the rcl waitset: subscriptions, guard conditions, clients, services, events, timers
 3. memset to zero  and zero init indexes of the rmw waitset: subscriptions, guard conditions, clients, services, events

Add each entity to the rcl wait set
  1. Check arguments for NULL
  2. Init rcl wait set indexes: subscriptions, guard conditions, clients, services, events, timers.
  3. Assign the rcl waitset pointers: subscriptions, guard conditions, clients, services, events, timers

Add each entity to the rmw wait set
  1. Check arguments for NULL
  2. Init rmw wait set indexes: subscriptions, guard conditions, clients, services, events
  3. Assign the rcl waitset pointers: subscriptions, guard conditions, clients, services, events

rcl wait
  1. Check waitset is valid
  2. Check if wait set elements are not empty: subscriptions, guard conditions, clients, services, events, timers
  3. Manage timers (won't discuss that here, but has a big overhead)

rmw wait
  1. Check waitset is valid
  2. Assign waitset condition variable and mutex. Check if they are valid.
  3. Attach condition variable and mutex to:  subscriptions, guard conditions, clients, services, events
  4. Check wait set entities for new data: subscriptions, guard_conditions, services, clients, events (until finds first entity with data)
  5. Detach condition variable and mutex, and set to NULL the rmw pointers with no data: subscriptions, guard_conditions, services, clients, events

rcl wait
  1. Check timers
  2. Set to NULL the rcl pointers with no data, based on rmw NULL pointers: subscriptions, guard_conditions, services, clients, events

excute executables (rclcpp)
  1. Get number of entities: subscriptions, timers, services, clients, waitables
  2. Iterate through entities to find not NULL: subscriptions, timers, services, clients, waitables
  3. Execute not null entities.

The results we are showing in the graphs above are only removing subscriptions, clients and services from the wait set maintenance. Still rest of entities have to be cleared and re-assigned for every executor run (timers, events, waitables, guard conditions). We are working to handle these entities also with the event queue.
Sorry if this message got too long, but it could be useful for someone not familiarized with the current executor approach. Thanks for your time considering this proposal!

4 Likes