Inferensys

Glossary

ROS 2 Executor

A ROS 2 Executor is the processing engine within a node that manages the execution of callbacks for subscriptions, services, timers, and actions.
Stylish WeWork-like workspace with hot desks and document wall, professional searching through enterprise knowledge base on a mounted ultrawide display, warm industrial pendants overhead.
ROBOT OPERATING SYSTEM (ROS)

What is a ROS 2 Executor?

A core processing engine within a ROS 2 node that manages the execution of callbacks from subscriptions, timers, services, and action servers.

A ROS 2 Executor is the processing engine within a ROS 2 node that manages the execution of callbacks from its subscriptions, timers, services, and action servers. It spins in a loop, waiting for work from these entities and invoking the appropriate user-defined callback functions. The executor is responsible for the fundamental task scheduling within a node, determining when and in what order callbacks are processed, which directly impacts system responsiveness and real-time performance.

Executors come in different types, primarily SingleThreadedExecutor and MultiThreadedExecutor, which define the concurrency model for callback execution. The executor's behavior is further refined by configurable callback groups, which allow developers to isolate callbacks for priority or mutual exclusion. This architecture provides fine-grained control over the node's computational resources, enabling the design of deterministic, low-latency control loops essential for real-time robotic control systems.

EXECUTION ENGINE

Key Features of a ROS 2 Executor

A ROS 2 Executor is the processing engine within a node that manages the execution of subscriptions, services, timers, and action servers. Its design directly impacts the determinism, performance, and resource utilization of a robotic system.

01

Callback Scheduling and Spin

The core function of an executor is to spin, which is the process of waiting for and then executing callbacks. It monitors all associated entities (e.g., subscriptions, timers) for readiness. When a timer fires or a message arrives on a subscription, the executor places the corresponding callback into a queue for execution. The spin() or spin_once() methods are called to process this queue, executing callbacks in a controlled, single-threaded loop. This centralizes the flow of control, preventing callback race conditions within a node.

02

Executor Types

ROS 2 provides several executor implementations, each with distinct concurrency models:

  • SingleThreadedExecutor: The default. Processes all callbacks sequentially in a single thread. Simple and deterministic but can lead to callback latency if one callback blocks.
  • MultiThreadedExecutor: Uses a thread pool to execute multiple ready callbacks concurrently. Increases throughput but introduces complexity from potential race conditions between callbacks.
  • StaticSingleThreadedExecutor: An optimized version of the single-threaded executor with lower overhead, as it discovers all entities once at configuration time. Ideal for performance-critical, static node graphs.
03

Integration with the DDS Layer

The executor works in tandem with the underlying Data Distribution Service (DDS) middleware. The DDS layer is responsible for the actual network communication: discovery, message queuing, and delivery based on Quality of Service (QoS) policies. The executor's role is to pull these delivered messages from the DDS's local queues and invoke the user-provided callback functions. This separation allows the executor to focus on application-level scheduling while DDS handles reliable, real-time data distribution.

04

Determinism and Real-Time Considerations

For real-time robotic control, executor behavior must be predictable. Key factors include:

  • Callback Priorities: Executors themselves do not implement priorities; priority is managed at the OS thread level using real-time scheduling policies (e.g., SCHED_FIFO).
  • Callback Duration: A long-running callback can starve other callbacks, breaking real-time guarantees. Callbacks must be designed to be non-blocking and short.
  • Spin Behavior: spin_once() allows explicit control over when callbacks are processed, enabling integration into custom, deterministic control loops.
05

Composition with Nodes and Components

An executor is not tied to a single node. A key architectural pattern is node composition, where one executor can spin multiple nodes. This is essential for ROS 2 Components, which are node-like objects compiled into shared libraries. A component container loads these libraries and spins them with an executor, allowing multiple functional units to run in a single process. This reduces inter-process communication overhead and is critical for high-performance, embedded systems.

06

Common Patterns and Best Practices

Effective use of executors follows established patterns:

  • One Executor Per Process: Typically, a main thread creates and spins one executor for all nodes in that process.
  • Separation of Concerns: Use separate executors (and often separate threads/processes) for distinct system parts: a high-frequency control loop on a real-time executor, and a slower planning node on a standard executor.
  • Avoiding Blocking Calls: Never call long-running or blocking functions (e.g., network I/O, long sleeps) inside a callback. Use asynchronous operations or delegate work to separate threads.
  • Using Timers for Periodic Work: For periodic tasks, use a ROS Timer callback instead of a while loop with sleep, as it integrates cleanly with the executor's scheduling.
CORE MECHANISM

How the ROS 2 Executor Works

The Executor is the processing engine at the heart of every ROS 2 node, responsible for scheduling and executing callbacks.

A ROS 2 Executor is a processing engine within a node that manages the execution of subscriptions, services, timers, and action servers by spinning callbacks in a single-threaded or multi-threaded manner. It continuously checks for ready work—like an incoming message on a topic or an expired timer—and dispatches the associated user-defined callback function. This abstraction decouples communication from computation, allowing developers to focus on task logic while the Executor handles concurrency and scheduling.

Executors are configurable, with the SingleThreadedExecutor processing all callbacks sequentially on one thread, and the MultiThreadedExecutor using a thread pool for parallel execution. The choice impacts determinism and performance. The Executor's core loop involves waiting on the underlying Data Distribution Service (DDS) middleware for notifications, then executing ready callbacks based on a scheduling policy like FIFO or priority. This design is central to building responsive, real-time robotic systems within the ROS 2 framework.

EXECUTOR ARCHITECTURE

ROS 2 Executor Types: Comparison

A comparison of the primary executor types available in ROS 2, detailing their threading models, use cases, and key behavioral characteristics for deterministic system design.

Feature / CharacteristicSingleThreadedExecutorMultiThreadedExecutorStaticSingleThreadedExecutor

Primary Threading Model

Single-threaded, sequential

Thread pool (default size = number of CPU cores)

Single-threaded, static

Callback Execution

Strictly sequential, FIFO order within priority levels

Concurrent across available threads

Strictly sequential, deterministic order

Determinism & Predictability

High (explicit execution order)

Low (subject to OS thread scheduling)

Highest (compile-time static schedule)

Use Case Archetype

Simple nodes, strict sequencing requirements

High-throughput nodes, independent callbacks

Hard real-time, safety-critical systems

Inter-Callback Data Sharing

Safe (no concurrent access)

Requires explicit synchronization (e.g., mutexes)

Safe (no concurrent access)

Default Availability

Core rclcpp & rclpy

Core rclcpp & rclpy

rclcpp only (as of Humble)

Runtime Overhead

< 1 ms

1-5 ms (thread management)

< 0.5 ms

Priority-Based Scheduling

Spin Behavior

Blocks until work is available

Blocks until work is available

Blocks until work is available

Integration with Component Nodes

Recommended for Real-Time Systems

Conditionally (with careful design)

ROS 2 EXECUTOR

Frequently Asked Questions

The ROS 2 Executor is the core processing engine that manages the execution of callbacks within a node. This FAQ addresses common questions about its architecture, configuration, and best practices for building responsive robotic systems.

A ROS 2 Executor is a processing engine within a ROS 2 node that manages the execution of subscriptions, services, timers, and action servers by spinning their associated callbacks in a single-threaded or multi-threaded manner. It works by continuously checking for ready-to-execute entities (e.g., a new message on a subscribed topic, a timer firing, or a service request arriving) from a collection assigned to it. When an entity is ready, the executor retrieves it from its wait set, acquires a lock, and invokes the corresponding user-defined callback function. The executor's primary loop (spin) blocks until work is available, executes it, and then repeats, forming the fundamental event-driven execution model of a ROS 2 application. Its behavior is critical for deterministic real-time robotic control systems.

Prasad Kumkar

About the author

Prasad Kumkar

CEO & MD, Inference Systems

Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.

His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.