betaFeedback

WorksComputer Science

One Behavior, Out of Order: Deterministic Execution and Parallel Simulation of ROS 2 Applications

Abstract

System-level simulation is widely used to validate robotic applications before hardware deployment. However, Robot Operating System 2 (ROS 2), a popular middleware for such applications, uses asynchronous publish-subscribe communication, which can make application behavior depend on scheduling and the platform. The behavior can then vary across runs and machines even with the same inputs. This nondeterminism makes faults hard to reproduce and tests unreliable. In this paper, we first give ROS 2 applications a lightweight coordination scheme in which every component, including event-driven ones, reads its inputs and writes its outputs at predefined time instants. By decoupling computation and communication, the scheme makes an application deterministic, that is, it always has one behavior for given inputs. Tests are thus repeatable, but for large applications they still take a long time. To speed up these tests, we then present an out-of-order parallel simulation algorithm. From the predefined read and write instants, it knows before the run which activations of components depend on which. It starts each activation as soon as those it depends on have finished. Finally, we implement the algorithm in a simulator that runs existing ROS 2 applications without any change to them or to ROS 2. We evaluate the simulator on industrial use cases and synthetic graphs. On the industrial use cases, it is up to 2.6 times faster than synchronous parallel simulation and needs an order of magnitude less memory for messages than asynchronous parallel simulation.

Introduction

Robot Operating System 2 (ROS 2) [1] is widely used in research and industry to build robotic systems, from mobile robots to automated vehicles. System-level simulation plays a pivotal role in their development, since developers can validate a whole application across many scenarios without the costly target hardware. However, the components of a ROS 2 application execute asynchronously and communicate with each other. The behavior of the application therefore depends on the execution times of its components, the communication delays and the scheduling. Their variation makes simulation results differ across runs, even when the application code and inputs remain unchanged [2, 3]. In the example of Figure 1, Planner computes a command every 20 ms from the latest objects that Detector found in the camera images. In run 2, a variation in the execution time of Detector leads Planner to compute the command at 40 ms from image 2 instead of image 3. If the command computed from image 2 causes a fault, the fault may not appear when the test is repeated, which makes it hard to reproduce. Developers may therefore need to rerun the same test many times to reproduce and diagnose the fault. This additional debugging effort slows development.

Running example

Figure 1. Running example. Detector’s execution time changes the behavior.

AUTOSAR solves this problem for automotive software with a rule by which every component reads its inputs and writes its outputs at predefined time instants, no matter when the computations run in between [4]. This separates computation from communication [5, 6], and the behavior of an application becomes independent of the scheduling and the platform. Following the same principle, our first step gives ROS 2 a lightweight coordination scheme that fixes when each component reads and writes, including event-driven components. Whenever a time-triggered or event-driven component is activated, it reads its inputs at that instant and writes its outputs after a fixed computation delay, even if they are empty. Every output arrives after a fixed transport delay. Since time-triggered components run periodically and the delays are fixed, all reads and writes happen at predefined time instants, as in AUTOSAR. The application therefore becomes deterministic and exhibits one behavior. Tests become repeatable, and application behavior can be validated independently of the target hardware.

However, system-level simulation still becomes time-consuming as applications and scenarios grow, slowing design iteration [7]. Even with one behavior, a recent simulator for ROS 2 applications runs all activations on a single thread, which its authors note increases the run time of complex simulations [8]. To further reduce the validation time, we therefore aim to exploit parallelism within a single simulation while preserving the application’s deterministic behavior. Yet general parallel discrete-event simulation cannot assume that event dependencies are known in advance, so it must preserve causality during the run, either synchronously or asynchronously. Synchronous parallel simulation stops all workers at a global barrier after each time instant or window [9], forcing fast workers to wait for the slowest one. Asynchronous parallel simulation avoids global barriers, either through optimistic execution, which needs state saving and rollback [10], or through conservative execution with null messages [11]. When fast producers run far ahead of their consumers, it can accumulate large buffers of unconsumed messages.

Out-of-order simulation needs none of these mechanisms if the dependencies between events are known. Existing out-of-order simulators derive them from a static analysis of the model or track them during the run [12, 13, 14]. Our key observation is that the coordination scheme already makes these dependencies known in advance, without any such analysis or tracking. The predefined read and write instants determine which outputs each activation reads. An activation therefore need not wait for all earlier activations. Its computation depends only on the activations whose outputs it reads and on the previous activation of the same component, whose updated state it needs. This allows activations of different components to run out of order and in parallel while preserving the one behavior of the application. Building on this observation, we present an out-of-order parallel simulation algorithm for ROS 2 applications. It computes the dependencies on demand from the application graph and the timing parameters, without constructing the full dependency graph. Because a producer may run ahead of its consumers, several outputs may need to be retained at the same time. To bound output buffering, the algorithm uses cyclic storage and allows a slot to be reused only after all readers of its previous contents have finished.

Together, the coordination scheme and the simulator make simulation-based validation of ROS 2 applications both repeatable and fast, which shortens each design iteration. The main contributions of this paper are as follows.

  • A lightweight coordination scheme that makes ROS 2 applications deterministic, so that their behavior does not depend on the scheduling or the platform (§ 2).

  • An efficient out-of-order parallel simulation algorithm that still computes the one deterministic behavior of an application (Section III). We show how to integrate it into ROS 2 so that it simulates existing applications without changing their source code or the libraries of ROS 2 (§ 4).

  • We evaluate our simulator on industrial use cases and synthetic graphs. On 256 cores, it is up to 228× faster than sequential simulation, which is 91 % of the theoretical speedup bound. Compared with synchronous parallel simulation, it is up to 2.6× faster on the industrial use cases and about 2× faster on the synthetic graphs. Its message buffers stay much smaller than those of asynchronous parallel simulation (§ 5).

System Model and Execution Semantics

We model a ROS 2 application as a graph and define our coordination scheme for deterministic execution.

System Model

From a logical perspective, a ROS 2 application is a set of nodes that communicate using the publish-subscribe paradigm [1]. Nodes publish messages on named topics and subscribe to topics to receive messages. A node maintains state in member variables and may have timers and subscriptions, each associated with a callback, a function invoked in response to an event. Timer callbacks are time-triggered, activated periodically, whereas subscription callbacks are event-driven, activated by incoming messages. Callbacks may update node state and publish messages that activate other callbacks, forming a network of topics and callbacks.1 In Figure 1(a), capture and plan are time-triggered, and detect and store are event-driven.

We model an application as a finite directed graph G=(V,E)G = (V, E). Each vertex z∈Vz \in V is a callback, and each edge e∈E⊆V×Ve \in E \subseteq V \times V is a communication channel. An event-driven callback uu has one input topic, the topic of its subscription. Every callback zz has a fixed finite output set OzO_z, which contains the topics on which zz may publish. A pair e=(z,u)e = (z, u) is in EE if and only if uu is event-driven and its input topic is in OzO_z.

The callbacks of one node form a task. Each task τi\tau_i has a state sis_i with initial value si,0s_{i,0}, a list XiX_i of time-triggered callbacks and a list UiU_i of event-driven callbacks. The state models the member variables of the node, and only the callbacks of this task can read and update it. Each time-triggered callback x∈Xix \in X_i has a period Tx∈Z>0T_x \in\mathbb{Z}_{>0} and an offset ϕx∈Z≥0\phi_x \in\mathbb{Z}_{\geq0}, and it is activated at the instants ϕx+mTx\phi_x + mT_x for m∈Z≥0m \in\mathbb{Z}_{\geq0}. A callback zz of τi\tau_i computes a function fzf_z. Its inputs are the state sis_i, the current time and, if zz is event-driven, the incoming message. Its outputs are the new value of sis_i and the messages that zz publishes on the topics in OzO_z. We assume that fzf_z is deterministic, that is, its outputs depend only on its inputs.

Execution Semantics

To make the behavior of an application independent of the scheduling and the platform, we separate computation from communication by fixing the instants at which callbacks read their input messages and write their output messages. For this, every task τi\tau_i has a computation delay Di∈Z>0D_i \in\mathbb{Z}_{>0} and every channel ee has a transport delay δe∈Z≥0\delta_e \in\mathbb{Z}_{\geq0}, both predefined and fixed. Channels from callbacks of the same task to the same callback have the same transport delay.

Every callback releases a sequence of jobs. A job of a callback of τi\tau_i, which we also call a job of τi\tau_i, has a release instant and a write instant, which is DiD_i later. It reads its input messages at its release instant and writes its output messages at its write instant, no matter when it runs in between. It writes them in records, one on every topic in the output set of its callback. A record holds the messages that the job publishes on its topic, in the order in which it publishes them. It is empty if the job publishes nothing on the topic, for example because its callback publishes only for some inputs.

A time-triggered callback releases a job at every instant at which it is activated. A record that a job of zz writes on the input topic of uu enters the channel e=(z,u)e = (z,u) when it is written and arrives at uu at its arrival instant, which is δe\delta_e later. At this instant it releases a job of uu, and only this job consumes its contents, that is, removes it from the channel and reads its messages. Since δe\delta_e is fixed, every channel is a first-in first-out queue of records. An empty record releases a job like any other record, so whether a job is released does not depend on what the callbacks compute.

In ROS 2, the executor decides in which order the ready callbacks of a node run, and the default executor runs timer callbacks first [16, 17]. We fix this order by a rule of our own. All jobs of τi\tau_i form one sequence in the order of their release instants, and Ji,kJ_{i,k} denotes the kk-th of them. For jobs with the same release instant, jobs of time-triggered callbacks come first, in the order of XiX_i, and jobs of event-driven callbacks follow, in the order of UiU_i. Jobs of the same event-driven callback are ordered by the jobs that wrote their records, first by the index of the task and then by the index of the job.

The jobs of τi\tau_i run one after the other in this sequence. Each job starts from the state that the previous job left, even if it is released before the previous job writes, and the first job starts from si,0s_{i,0}. Whenever a job reads the current time, it gets its release instant. A job of a time-triggered callback xx calls fxf_x once. A job of an event-driven callback uu calls fuf_u once for each message of the record that it consumes, in the order of the messages. If this record is empty, the job is skipped, that is, it calls nothing, keeps the state and writes only empty records. So, an empty record comes from a job that publishes nothing on a topic or from a skipped job.

Example 1. Figure 2(a) shows the graph of the application of Figure 1(a), with x1x_1, u2u_2, u3u_3 and x3x_3 for capture, detect, store and plan. The output sets are Ox1={/img}O_{x_1} = \{\text{/img}\}, Ou2={/obj}O_{u_2} = \{\text{/obj}\}, Ox3={/cmd}O_{x_3} = \{\text{/cmd}\} and Ou3=∅O_{u_3} = \varnothing. The input topics of u2u_2 and u3u_3 are /img and /obj, so EE has only e1=(x1,u2)e_1 = (x_1,u_2) and e2=(u2,u3)e_2 = (u_2,u_3). The state s3s_3 holds latest, which u3u_3 writes and x3x_3 reads. ◇

Graph model, execution timeline and job dependencies

Figure 2. Graph model, execution timeline and job dependencies of the running example. (a) Circles are callbacks, with a double line if they are time-triggered. Arrows are channels, boxes are tasks, and the grey box is the state of τ3\tau_3. (b) A light bar spans from the release instant to the write instant of a job, and an arrow goes from the write of a record to its arrival. Darker boxes show when the jobs run in one run. The dashed record is empty and releases the skipped job J3,6J_{3,6}. (c) Grey arrows are state dependencies and black arrows are record dependencies.

Example 2. Figure 2(b) shows the jobs of the running example with the parameters of Figure 2(a). Job J2,2J_{2,2}, released at 30 ms, runs in two pieces but still writes its record on /obj at $30 + D_2 = 55$ ms. This record arrives at 55+δe2=5955 + \delta_{e_2} = 59 ms and releases J3,4J_{3,4}, which stores the detection in s3s_3. The next job J3,5J_{3,5} of τ3\tau_3 is released at 60 ms, so it computes its command from this detection in every run. Job $J_{2,3} finds no object, so its record is empty and the job J3,6J_{3,6} that it releases is skipped. ⋄

Determinism

Theorem 1. The jobs, their release and write instants, their order in each task and which record each job reads depend only on the application graph model, the tasks, the periods, the offsets and the delays. The states and the records depend in addition only on the initial states and the functions fzf_z. So the behavior of the application, that is, its non-empty records with their write instants, depends neither on the scheduling nor on the platform.

Proof. Jobs are released only at predefined instants, so we use induction on the release instant tt. Since Di>0D_i > 0, a job released at tt is released by a time-triggered callback or by a record of a job released before tt, and this record is written whether it is empty or not. So the jobs released at tt, their order and the records that they read do not depend on what the callbacks compute. We take the jobs of each task in the order of its sequence. Their inputs then depend only on the initial states and on the outputs of jobs that come before them, and so do their outputs, since every fzf_z is deterministic. □

Discussion

The main benefit of empty records is that the jobs and their dependencies are known before the run, as Theorem 1 states. Without them, a callback that publishes only for some inputs would release jobs of other callbacks only for these inputs, so the jobs would depend on the computed values. With them, every job depends only on the previous job of its task and on the job that wrote the record that it consumes, and both come before it. So the dependencies form a directed acyclic graph, even if the application graph model has cycles. Figure 2(c) shows this graph for the running example. Section III shows how to run jobs out of order and in parallel by computing their dependencies from the parameters, without building the graph.

Out-of-Order Parallel Simulation

As discussed in Section II-D, the dependencies between jobs form a directed acyclic graph. A simulation that runs the jobs in a topological order of this graph is correct, that is, every job writes the same records as in the semantics of Section II-B. So a simulator can run jobs out of the order of their release instants and in parallel, as long as every job starts only after the jobs that it depends on have finished.

Example 3. In Figure 2(c), J3,5J_{3,5} depends, directly or through other jobs, only on J1,1J_{1,1}, J1,2J_{1,2}, J2,1J_{2,1}, J2,2J_{2,2} and J3,1,…,J3,4J_{3,1}, \ldots, J_{3,4}. So the simulator can run J3,5J_{3,5} in parallel with J1,3J_{1,3}, or even finish it before J1,3J_{1,3} starts, although J3,5J_{3,5} is released at 60 ms and J1,3J_{1,3} at 30 ms. ⋄

Activation Streams

To execute jobs in a topological order, the simulator needs to identify their dependencies. We can compute these dependencies on demand using only the application graph model parameters, without constructing or storing the full job dependency graph. To this end, we group the jobs into periodic sequences, in which the record and state dependencies of a job (Fig. 2(c)}) follow from its position.

A time-triggered callback releases a job in every period. Each of these jobs writes a record on every topic in its output set, empty or not, and after fixed delays each record releases one job of every callback that receives it. These jobs are periodic as well, with the same period and a later offset, and so are the jobs that their records release. We call such a periodic sequence of jobs an activation stream. A stream σ\sigma has a period TσT_\sigma and an offset ϕσ\phi_\sigma, and its mm-th job J(σ,m)J(\sigma,m), with m∈Z≥0m \in\mathbb{Z}_{\ge0}, is released at rσ(m)=ϕσ+mTσr_\sigma(m) = \phi_\sigma+ mT_\sigma. Every time-triggered callback xx has a root stream with period TxT_x and offset ϕx\phi_x. For each channel e=(z,u)e = (z,u), every stream σ\sigma of callback zz in task τi\tau_i has a child stream ν\nu of callback uu. The child stream has period Tν=TσT_\nu= T_\sigma and offset ϕν=ϕσ+Dj+δe\phi_\nu= \phi_\sigma+ D_j + \delta_e. We call σ\sigma the parent of ν\nu. Job J(ν,m)J(\nu,m) consumes the record written by J(σ,m)J(\sigma,m), so J(σ,m)J(\sigma,m) is its record dependency.

Assume that we simulate the jobs released in the interval [0,H)[0,H), for a given H∈Z>0H \in\mathbb{Z}_{>0}. Since Dj>0D_j > 0, a child stream has a later offset than its parent, so only finitely many streams have an offset before HH. Such a stream σ\sigma has Mσ=⌈(H−ϕσ)/Tσ⌉M_\sigma= \lceil(H - \phi_\sigma)/T_\sigma\rceil jobs in [0,H)[0,H).

The state dependency of a job is the previous job in the sequence of its task. This sequence merges the jobs of all streams of the task and orders them by release instant, which rσ(m)r_\sigma(m) gives. Jobs of a task with the same release instant belong to different streams. To order them, we give every stream σ\sigma of τi\tau_i with an offset before HH a rank qσq_\sigma, its position in the following order, which follows the rule of Section II-B. Root streams come first, in the order of XiX_i. Child streams follow, ordered by the position of their callback in UiU_i, then by the index of the task of their parent, and then by the rank of their parent. This is not circular, since a parent has an earlier offset than its child. The key of J(σ,m)J(\sigma,m) is kσ(m)=(rσ(m),qσ)k_\sigma(m) = (r_\sigma(m), q_\sigma), compared first by release instant and then by rank. By the following lemma, the keys give the sequence of the task, so the state dependency of a job is the job of the same task with the next smaller key.

Lemma 1. Every job released in [0,H)[0,H) is the job J(σ,m)J(\sigma,m) of one stream σ\sigma and one m<Mσm < M_\sigma. In the order of their keys, the jobs of τi\tau_i released in [0,H)[0,H) are the first jobs Ji,1,Ji,2,…J_{i,1}, J_{i,2}, \ldots of its sequence.

Proof. By induction on the release instant, every job is in one stream, since it is released by a time-triggered callback or by the record of one earlier job. The ranks follow the rule of Section II-B, with the parents of two streams in place of the jobs that wrote the records. When these jobs are in the same task, their channels have the same transport delay, so they have the same release instant, and by induction their order is the order of the ranks of the parents.

Example 4. With H=70H = 70 ms, the running example has four streams. The root stream σ1\sigma_1 of x1x_1 has period and offset 10 ms, and its child σ2\sigma_2 is a stream of u2u_2 with offset 20 ms. The child σ3\sigma_3 of σ2\sigma_2 is a stream of u3u_3 with offset 20+D2+δe2=4920 + D_2 + \delta_{e_2} = 49 ms. The root stream σ4\sigma_4 of x3x_3 has period and offset 20 ms. In τ3\tau_3, σ4\sigma_4 has rank 1 and σ3\sigma_3 has rank 2, so the keys (20,1)(20, 1), (40,1)(40, 1), (49,2)(49, 2), (59,2)(59, 2), (60,1)(60, 1), (69,2)(69, 2) give J3,1,…,J3,6J_{3,1}, \ldots, J_{3,6}. ◇

Bounded Record Storage

With the dependencies of Section III-A, the simulator can run jobs out of order. The remaining issue is storage. A stream can then run far ahead of its children, that is, many of its jobs finish before the jobs that consume their records start. The simulator must store these records in the meantime, and their number is bounded only by the number of jobs of the stream, which grows with HH. To bound it, every stream keeps its records in a ring with a fixed number of slots, which its jobs reuse in turn. A job that reuses a slot must then wait until the records in it have been consumed. This adds a third kind of dependency. If the dependencies had a cycle, the jobs on it would wait for each other, and none of them could start. So we first define the rings and then choose their size such that the dependencies still form a directed acyclic graph.

Let the ring of a stream σ\sigma have KσK_\sigma slots. Each slot holds the records of one job. Job J(σ,m)J(\sigma,m) writes its records into slot m mod Kσm \bmod K_\sigma. For m≥Kσm \ge K_\sigma, it replaces the records of J(σ,m−Kσ)J(\sigma,m-K_\sigma). These records are consumed by the jobs J(ν,m−Kσ)J(\nu,m-K_\sigma) of the children ν\nu of σ\sigma, which we call the slot dependencies of J(σ,m)J(\sigma,m). So J(σ,m)J(\sigma,m) can start only after its slot dependencies have finished.

The dependencies stay acyclic if every slot dependency of a job is released before the job. Let σ\sigma be a stream of a callback of τj\tau_j, and let δσ\delta_\sigma be the largest transport delay of the channels to its children, or 0 if it has no children. The records of J(σ,m−Kσ)J(\sigma,m-K_\sigma) arrive at most Dj+δσD_j+\delta_\sigma after its release, and they release the slot dependencies of J(σ,m)J(\sigma,m) when they arrive. Job J(σ,m)J(\sigma,m) is released KσTσK_\sigma T_\sigma after J(σ,m−Kσ)J(\sigma,m-K_\sigma), so we need KσTσ>Dj+δσK_\sigma T_\sigma> D_j+\delta_\sigma and choose

Kσ=max⁡(2,⌊Dj+δσTσ⌋+1).(1)K_\sigma= \max\left(2,\left\lfloor\frac{D_j+\delta_\sigma}{T_\sigma}\right\rfloor+1\right). \tag*{(1)}

The second term is the smallest such number, and the term 2 lets a stream run at least one job ahead of its children.

Lemma 2. Every slot dependency of a job is released before the job.

Proof. The slot dependency J(ν,m−Kσ)J(\nu,m-K_\sigma) of J(σ,m)J(\sigma,m), with ν\nu on a channel ee, is released at rσ(m)−KσTσ+Dj+δer_\sigma(m)-K_\sigma T_\sigma+D_j+\delta_e, which is before rσ(m)r_\sigma(m) by (1). □

So every dependency of a job is released before it or comes before it in its task, and the dependencies still form a directed acyclic graph.

Example 5. In Example 4, Kσ1=max⁡(2,⌊10/10⌋+1)=2K_{\sigma_1}=\max(2,\lfloor10/10\rfloor+1)=2 and Kσ2=max⁡(2,⌊(25+4)/10⌋+1)=3K_{\sigma_2}=\max(2,\lfloor(25+4)/10\rfloor+1)=3. So J(σ2,3)J(\sigma_2,3), released at 50 ms, reuses the slot of J(σ2,0)J(\sigma_2,0), and its slot dependency is J(σ3,0)J(\sigma_3,0), released at 49 ms. Job J(σ1,4)J(\sigma_1,4), also released at 50 ms, waits for no job of τ3\tau_3, directly or through other jobs, so it can run before J(σ4,0)J(\sigma_4,0), which is released at 20 ms. ◇

The Simulation Algorithm

By Sections III-A and III-B, a job can start when its state, record and slot dependencies have finished. Algorithm 1 runs the jobs in this way on a pool of worker threads. It has to find the jobs that can start and to make sure that each of them runs only once. It does both without a list of jobs.

Every child stream has one parent, so the streams form trees whose roots are the root streams. Before the run, the simulator searches these trees breadth first and keeps the streams with an offset before HH. It skips the children of all other streams, so the search always ends. The simulator then computes the ranks and the ring sizes. To find the next job of each task efficiently during the run, each task keeps the next job of each of its streams in a heap ordered by key. By Lemma 1, the first job in the heap is the next job of the task. The heap has at most one entry per stream, so no list of jobs is stored.

Each task τi\tau_i also has three values. Workers read and write them and the next job of the task atomically, in total order. The completion count cic_i is the number of its finished jobs, and the completion key λi\lambda_i is the key of its last finished job. The jobs of a task finish in the order of their keys, so a job of τi\tau_i has finished if and only if its key is at most λi\lambda_i. One can compare completion keys to tell whether a dependency has finished. To run every job only once, a worker must claim a job before it runs it, and the claim count aia_i is the number of claimed jobs of τi\tau_i. TRYENQUEUE(τi)(\tau_i) looks only at the next job J(σ,m)J(\sigma,m) of τi\tau_i, since the jobs of a task run in the order of its sequence. If ai=cia_i=c_i, no job of τi\tau_i is claimed and unfinished, so the state dependency of J(σ,m)J(\sigma,m) has finished (line 3). Lines 5 and 6 check its record dependency J(π,m)J(\pi,m) and its slot dependencies J(ν,m−Kσ)J(\nu,m-K_\sigma). If all have finished, the worker claims J(σ,m)J(\sigma,m) by a compare-and-swap (CAS) that changes aia_i from cic_i to ci+1c_i+1 and fails if another worker has claimed a job of τi\tau_i in the meantime (line 7). It then pushes the job onto its local double-ended queue (deque).

Each worker takes the jobs from its local deque one at a time. When its deque is empty, it steals a job from the deque of another worker, which balances the load among the workers (work stealing [18]). It runs a job J(σ,m)J(\sigma,m) of τi\tau_i in the semantics, with its release instant as the current time, and writes its records into slot m mod Kσm \bmod K_\sigma. It then replaces J(σ,m)J(\sigma,m) in the heap by J(σ,m+1)J(\sigma,m+1) if m+1<Mσm+1 < M_\sigma, sets the next job of τi\tau_i, sets λi\lambda_i to κσ(m)\kappa_\sigma(m) and increases cic_i, in this order, so that a worker that reads the new cic_i also reads the new next job. After that, the next job of τi\tau_i, a job that consumes a record of J(σ,m)J(\sigma,m), or a job that reuses a slot whose records J(σ,m)J(\sigma,m) consumed start and to make sure that each of them runs only once. It does both without a list of jobs.

Algorithm 1: Out-of-order parallel simulation.

  1. procedure TRYENQUEUE(τi)(\tau_i)

  2. k←cik \leftarrow c_i

  3. if ai≠ka_i \ne k or τi\tau_i has no next job then return

  4. J(σ,m)←J(\sigma,m) \leftarrow the next job of τi\tau_i

  5. if σ\sigma has a parent π\pi in τi\tau_i and κπ(m)>λi\kappa_\pi(m) > \lambda_i then return

  6. if m≥Kσm \ge K_\sigma and σ\sigma has a child ν\nu in τl\tau_l with κν(m−Kσ)>λl\kappa_\nu(m-K_\sigma) > \lambda_l then return

  7. if CAS(ai,k,k+1)(a_i,k,k+1) then push J(σ,m)J(\sigma,m) onto the local deque

  8. procedure WORKER()

  9. while some task has a next job do

  10. J(σ,m)←J(\sigma,m) \leftarrow a job from the local deque or a stolen job

  11. if there is no such job then continue

  12. run J(σ,m)J(\sigma,m) of τi\tau_i and write its records into slot m mod Kσm \bmod K_\sigma

  13. replace J(σ,m)J(\sigma,m) in the heap of τi\tau_i by J(σ,m+1)J(\sigma,m+1), or remove it if m+1=Mσm+1=M_\sigma

  14. set the next job of τi\tau_i to the first job in its heap, if any

  15. if λi<κσ(m)\lambda_i < \kappa_\sigma(m), then ci←ci+1c_i \leftarrow c_i+1

  16. for τj=τi\tau_j=\tau_i and every τj\tau_j with a parent or a child of a stream of τi\tau_i do TRYENQUEUE(τj)(\tau_j)

  17. initialize ci=ai=0c_i=a_i=0, λi=−∞\lambda_i=-\infty, the heaps and the next jobs

  18. call TRYENQUEUE(τi)(\tau_i) for every task τi\tau_i

  19. run WORKER on every worker in parallel

may be able to start. So the worker calls TRYENQUEUE for τi\tau_i and for every task that has a child or a parent of a stream of τi\tau_i. Because of the total order, the worker that finishes the last dependency of a job sees that all of them have finished, so no job is missed. The dependencies form a directed acyclic graph, so every job then runs once, and the simulation cannot deadlock.

Complexity. Let nin_i be the number of streams of τi\tau_i, and let dd be the largest number of channels that enter or leave the callbacks of one task. After a job of τi\tau_i has run, the worker performs one heap operation in O(log⁡ni)O(\log n_i) time and calls TRYENQUEUE for at most d+1d+1 tasks. Each call compares one pair of keys per dependency of the next job, in O(1+d)O(1+d) time.

ROS 2 Integration

We implemented the simulator of Section III as a lightweight layer for ROS 2 Jazzy.2

ROS 2 is organized in layers [1]. Figure 3 shows them together with our simulator. The nodes are written with a client library, which is rclcpp for C++ [17]. It provides the timers, the subscriptions, the publishers and the ROS clock of a node, and its executors decide when the callbacks run [16]. Below it, the C library rcl passes a published message through the interface rmw to the middleware, which delivers it to the subscriptions of the topic [19]. The middleware is usually an implementation of the Data Distribution Service (DDS) [20].

Our simulator with ROS 2

Figure 3. Our simulator with ROS 2.

Our simulator is directly below rclcpp. To simulate the application as in the semantics of § 2-B, it runs the callbacks, carries the messages and gives the time itself. To run a job, a worker of Algorithm 1 calls its callback through the timer, or through the subscription once for every message of the consumed record, so no executor is started. To take the published messages and to give the time, the simulator defines its own versions of the functions of rcl that publish a message and that read the ROS clock. They are part of the executable that loads the nodes, so rclcpp calls them in place of the ones in rcl, which stays unchanged. A published message is then stored in serialized form in the slot of the running job, and the ROS clock returns the release instant of this job. The simulator also turns off the direct delivery of messages inside one process, so that every message goes through a record. The rest of ROS 2 is used as it is, without any change.

Using the simulator takes little effort. The user does not write the application graph model of § 2-A, because the simulator reads it from the nodes themselves. It finds the timers and subscriptions of every node and connects publishers and subscriptions by topic name and message type. It loads the nodes from their existing shared libraries, so they need no recompilation, or it creates them by the functions that construct them. Besides the application, the simulator only needs the delays, which the user gives in files.

Evaluation

Setup

Workloads and simulators. We evaluate our simulator on three industrial use cases, the Autoware reference system (RS) [21], fleets of vehicles built from RS (Fleet-NN), and a stereo vision pipeline (Stereo) [22, 23]. RS is a ROS 2 benchmark modeled on the autonomous driving software Autoware. Fleet-NN runs NN copies of RS as vehicles that exchange detected objects, with different timer offsets. Stereo runs the stereo vision nodes of image pipeline on recorded camera frames. We also evaluate 1385 synthetic graphs, including randomly generated ROS 2 graphs and those derived from automotive benchmarks [6, 24].

We compare our simulator with sequential simulation, with the synchronous parallel simulations Sync-I and Sync-W, and with the asynchronous parallel simulation Async. Sequential simulation runs one job at a time. Sync-I and Sync-W run the jobs released in a time window in parallel and wait at a global barrier at its end [9]. Sync-I runs in parallel only the jobs released at the same instant, and waits at a barrier before the next instant. Sync-W has windows as long as the smallest computation delay, so that the jobs of different tasks in a window do not depend on each other. Async is a conservative simulation with null messages and without global barriers [11, 25]. In Async, a task runs its next job as soon as it knows all records that the job reads, and an optional lead bounds how far a task may run ahead of its readers.

Parameters and measurements. We ran all simulators on ROS 2 Jazzy on a machine with two AMD EPYC 9755 processors and 256 cores, with each worker pinned to one core. The computation delay of a node is its smallest timer period, or, if it has no timers, the smallest computation delay of the nodes that publish to it.

We measure how fast each simulator is and how many messages it holds. The speedup of a simulator is the time of sequential simulation divided by its time. To see how much of the parallelism of a workload a simulator uses, we compare its speedup with a bound that depends only on the workload. Let WW be the total computation time of all jobs and SS that of the longest chain of jobs in which each job needs the state or a record of the job before it, both measured in sequential simulation. The jobs of such a chain run one after another, so any simulator takes at least SS, and pp workers take at least W/pW/p. The speedup on pp workers is therefore at most min⁡(p,W/S)\min(p,W/S), which we call the bound. The ratio W/SW/S is the average number of jobs that the workload can run at the same time. This ratio is 3.7 for RS and 7.9 for Stereo, and it grows in proportion to the number of vehicles in the fleets, up to 252 for Fleet-64. The message bytes of a simulator are the most bytes of messages that it holds at one time.

Results

Speedup. On Fleet-8, our simulator follows the bound and is 29.1 times faster than sequential simulation on 32 workers, which is 93 % of the bound (Figure 4(a)). Sync-W reaches 14.6, and Sync-I stays below 3, because the vehicles have different offsets and few jobs share an instant. When all vehicles have offset 0, Sync-I and Sync-W reach speedups of 15.1 and 18.0, and our simulator reaches 28.9. Aligning the release instants therefore improves the speedup of synchronous simulation, while the speedup of our simulator stays almost the same. With transport delays of 0 to 100 ms between the vehicles of Fleet-8, our simulator stays between 29.0 and 30.9 times faster than sequential simulation on 32 workers. RS and Stereo have bounds of only 3.7 and 7.9 (Figure 4(b)). Our simulator reaches the bound of RS on 4 workers, where Async and Sync-W reach 2.8 and 2.5. On Stereo, it reaches 6.7, and Async reaches 7.4.

Speedup over sequential simulation and message bytes on the industrial use cases

Figure 4. Speedup over sequential simulation and message bytes on the industrial use cases.

Scaling. On the whole machine, Fleet-64, with 1600 nodes and 566 353 jobs in 10 s, takes 228 s in sequential simulation (Figure 4(c)). Our simulator takes 1.0 s on 256 workers, so it is 228 times faster, which is 91 % of the bound of 252. Sync-W reaches 89, so our simulator is 2.6 times faster. In every window, Sync-W waits for the task with the most work, and our simulator does not.

Message bytes. Sync-W holds as many message bytes as our simulator, or 1.5 times as many on Stereo, but Async holds 12 to 42 times as many, since a task of Async can run far ahead of its readers and its records then wait in queues (Figure 4(d)). On Stereo, Async is about as fast, but it holds up to 6.3 GB of messages at one time, while our simulator holds at most 0.5 GB. A lead bounds the queues, but it has to be chosen for each workload (Figure 5(b)). On Fleet-8, Async without a lead is 1.4 times slower and holds 35 times as many message bytes, while leads from 25 to 200 ms make it as fast as our simulator with 1.4 to 2.9 times its message bytes.

Speedup of the synthetic graphs and time and message bytes of Async with leads

Figure 5. (a) Speedup of the synthetic graphs, with medians as lines. (b) Time and message bytes of Async with leads, relative to ours. Both on 32 workers.

Synthetic graphs. Figure 5(a) shows the speedups of our simulator and Sync-W on the synthetic graphs with 32 workers, plotted against the average number xx of jobs in a nonempty window of Sync-W. If all jobs take the same time, the speedup of Sync-W is at most min⁡(x,32)\min(x, 32). Across all 1385 synthetic graphs, our simulator is 1.98 times as fast as Sync-W on average (geometric mean). Async is about as fast as our simulator but holds 45 times as many message bytes. With leads of 0.25 to 8 times the longest timer period, Async still holds 2.2 to 27 times as many message bytes (Figure 5(b)).

Safety-critical embedded systems need behavior that is deterministic and predictable [3]. The time-triggered architecture was designed for this, with computation and communication at predefined time instants [26]. Henzinger et al. developed this idea into the logical execution time (LET) [27], which our coordination scheme follows. AUTOSAR supports LET [4]. LET fixes the instants of reads and writes on one machine, but messages between machines take a varying time. System-level LET [28] therefore gives the communication between machines a fixed delay, as our transport delays do. The Adaptive Platform of AUTOSAR [29] comes closest to ROS 2, since its applications also run on POSIX and communicate by publish and subscribe. Menard et al. show that it is not deterministic by itself and add a coordination layer to it [30]. Bellassai et al. instead bring system-level LET to it [31] and to its publish-subscribe communication [32]. In both works, LET applies only to time-triggered tasks. Our scheme also applies to event-driven callbacks. An empty record tells such a callback that no message comes. In this way, the absence of a message also carries information, as Lamport observed for bounded message delays and synchronized clocks [33].

Three recent approaches make the simulation or the execution of ROS 2 applications deterministic. Sagmeister et al. run the callbacks of all nodes sequentially on a single thread with a simulated clock [8]. Otto uses an orchestrator that forwards the messages between nodes in an order that it builds during the run [34]. Teper et al. map a ROS 2 application to Lingua Franca [35], a coordination language based on the deterministic reactor model [36]. Each node becomes a reactor, a component that reacts to timestamped events, and each callback becomes one of its reactions. The runtime of Lingua Franca then calls the unmodified callbacks in timestamp order. Kwok et al. instead build a robotic middleware on Lingua Franca to replace ROS 2, and show how to move ROS 2 programs to it [37]. Although Lingua Franca can also express LET [38], its runtime is synchronous by default and completes all reactions at one timestamp before it advances to the next. By default, none of the three runs callbacks of different timestamps in parallel, since a callback may or may not publish and which callback runs next is known only during the run. With empty records, the jobs and their dependencies are known before the run, so our simulator runs jobs out of order and in parallel. An empty record plays the role of a null message in conservative parallel simulation [11, 25], but it is part of our coordination scheme and not an extra message of the simulator.

Henzinger and Kirsch describe semantics-preserving compilation of LET programs for a single processor [39]. Biondi and Di Natale implement LET on multicore platforms [40]. We use LET to coordinate ROS 2 callbacks, defining the application behavior that our simulator reproduces. The final step would be to generate code that preserves validated behavior on the target platform.

Conclusion

We have shown that fixing when every callback reads and writes makes a ROS 2 application deterministic. With empty records, it also fixes the jobs and their dependencies before the run. Based on this, our simulator runs the jobs out of release order and in parallel. It reached 91 % of the theoretical speedup bound on 256 cores. Our coordination scheme currently does not support several publishers of one node on the same topic or applications whose structure changes during a run, and both are worth addressing in the future.

References

  1. [1]S. Macenski, T. Foote, B. Gerkey, C. Lalancette, and W. Woodall, “Robot Operating System 2: Design, architecture, and uses in the wild,” Sci. Robot., vol. 7, no. 66, p. eabm6074, 2022.DOI
  2. [2]E. A. Lee, “The problem with threads,” Computer, vol. 39, no. 5, pp. 33–42, 2006.DOI
  3. [3]———, “Determinism,” ACM Trans. Embedded Comput. Syst., vol. 20, no. 5, pp. 38:1–38:34, 2021.
  4. [4]AUTOSAR, “Specification of timing extensions,” Classic Platform, Release R22-11, 2022. [Online]. Available: https://www.autosar.org/fileadmin/standards/R22-11/CP/AUTOSAR_TPS_TimingExtensions.pdf
  5. [5]K. Keutzer, S. Malik, A. R. Newton, J. M. Rabaey, and A. Sangiovanni-Vincentelli, “System-level design: Orthogonalization of concerns and platform-based design,” IEEE Trans. Comput.-Aided Design Integr. Circuits Syst., vol. 19, no. 12, pp. 1523–1543, 2000.DOI
  6. [6]A. Hamann, D. Dasari, S. Kramer, M. Pressler, and F. Wurst, “Communication centric design in complex automotive embedded systems,” in Proc. Euromicro Conf. Real-Time Systems (ECRTS), 2017.DOI
  7. [7]V. Antinyan, “Revealing the complexity of automotive software,” in Proc. ACM Joint European Software Engineering Conf. and Symp. Foundations of Software Engineering (ESEC/FSE), 2020.DOI
  8. [8]S. Sagmeister, M. Weinmann, P. Pitschi, and M. Lienkamp, “RSLCPP—Deterministic simulations using ROS 2,” IEEE Robot. Autom. Pract., vol. 1, pp. 118–122, 2026.DOI
  9. [9]R. M. Fujimoto, Parallel and Distributed Simulation Systems. Wiley, 2000.
  10. [10]D. R. Jefferson, “Virtual time,” ACM Trans. Program. Lang. Syst., vol. 7, no. 3, pp. 404–425, 1985.DOI
  11. [11]K. M. Chandy and J. Misra, “Distributed simulation: A case study in design and verification of distributed programs,” IEEE Trans. Softw. Eng., vol. SE-5, no. 5, pp. 440–452, 1979.DOI
  12. [12]W. Chen, X. Han, C.-W. Chang, G. Liu, and R. Dömer, “Out-of-order parallel discrete event simulation for transaction level models,” IEEE Trans. Comput.-Aided Design Integr. Circuits Syst., vol. 33, no. 12, pp. 1859–1872, 2014.DOI
  13. [13]J. E. Jansen, J. Leathrum, Jr., C. Lynch, K. Smith, and R. Gore, “Out of order and causally correct: Ready-event discovery through data-dependence analysis,” in Proc. ACM SIGSIM Conf. Principles of Advanced Discrete Simulation (SIGSIM-PADS), 2025.DOI
  14. [14]Z. Xie, H. Kang, Y. Sheng, T. Krishna, K. Fathalian, and C. Koykrizis, “AI Metropolis: Scaling large language model-based multi-agent simulation with out-of-order execution,” in Proc. Conf. Machine Learning and Systems (MLSys), 2025.arxiv.org/abs/2411.03519
  15. [15]Open Robotics, “Using callback groups,” ROS 2 Jazzy documentation, accessed: Nov. 18, 2026. [Online]. Available: https://docs.ros.org/en/jazzy/How-To-Guides/Using-callback-groups.html
  16. [16]———, “Executors,” ROS 2 Jazzy documentation, accessed: Nov. 18, 2026. [Online]. Available: https://docs.ros.org/en/jazzy/Concepts/Intermediate/About-Executors.html
  17. [17]———, “rclcpp,” GitHub repository, branch jazzy, accessed: Nov. 18, 2026. [Online]. Available: https://github.com/ros2/rclcpp/tree/jazzy
  18. [18]R. D. Blumofe and C. E. Leiserson, “Scheduling multithreaded computations by work stealing,” J. ACM, vol. 46, no. 5, pp. 720–748, 1999.
  19. [19]Open Robotics, “rcl,” GitHub repository, branch jazzy, accessed: Nov. 18, 2026. [Online]. Available: https://github.com/ros2/rcl/tree/jazzy
  20. [20]Object Management Group, “Data Distribution Service (DDS), version 1.4,” OMG document formal/15-04-10, 2015. [Online]. Available: https://www.omg.org/spec/DDS/1.4
  21. [21]ROS 2 Real-Time Working Group, “reference-system,” GitHub repository, commit de8f3bc, accessed: Nov. 18, 2026. [Online]. Available: https://github.com/ros-realtime/reference-system
  22. [22]ROS Perception, “image_pipeline,” GitHub repository, accessed: Nov. 18, 2026. [Online]. Available: https://github.com/ros-perception/image_pipeline
  23. [23]NVIDIA, “r2b dataset 2024,” NGC catalog, accessed: Nov. 18, 2026. [Online]. Available: https://catalog.ngc.nvidia.com/orgs/nvidia/teams/isaac/resources/r2bdataset2024
  24. [24]S. Kramer, D. Ziegenbein, and A. Hamann, “Real world automotive benchmarks for free,” in Proc. Int. Workshop Analysis Tools and Methodologies for Embedded and Real-Time Systems (WATERS), 2015.
  25. [25]R. M. Fujimoto, “Parallel discrete event simulation,” Commun. ACM, vol. 33, no. 10, pp. 30–53, 1990.
  26. [26]H. Kopetz and G. Bauer, “The time-triggered architecture,” Proc. IEEE, vol. 91, no. 1, pp. 112–126, 2003.
  27. [27]T. A. Henzinger, B. Horowitz, and C. M. Kirsch, “Giotto: A time-triggered language for embedded programming,” Proc. IEEE, vol. 91, no. 1, pp. 84–99, 2003.
  28. [28]K.-B. Gemlau, L. Köhler, R. Ernst, and S. Quinton, “System-level logical execution time: Augmenting the logical execution time paradigm for distributed real-time automotive software,” ACM Trans. Cyber-Phys. Syst., vol. 5, no. 2, pp. 14:1–14:27, 2021.DOI
  29. [29]AUTOSAR, “Explanation of Adaptive Platform design,” Adaptive Platform, Release R24-11, 2024. [Online]. Available: https://www.autosar.org/fileadmin/standards/R24-11/AP/AUTOSAR_AP_EXP_PlatformDesign.pdf
  30. [30]C. Menard, A. Goens, M. Lohstroh, and J. Castrillon, “Achieving determinism in Adaptive AUTOSAR,” in Proc. Design, Automation and Test in Europe Conf. (DATE), 2020.arxiv.org/abs/1912.01367
  31. [31]D. Bellassai, G. Sciangula, C. Scordino, D. Casini, and A. Biondi, “Modeling the SL-LET paradigm in AUTOSAR Adaptive,” in Proc. Design, Automation and Test in Europe Conf. (DATE), 2025.DOI
  32. [32]D. Bellassai, C. Scordino, D. Casini, and A. Biondi, “AP-LET: Enabling deterministic pub/sub communication in AUTOSAR Adaptive,” J. Syst. Archit., vol. 162, p. 103390, 2025.DOI
  33. [33]L. Lamport, “Using time instead of timeout for fault-tolerant distributed systems,” ACM Trans. Program. Lang. Syst., vol. 6, no. 2, pp. 254–280, 1984.DOI
  34. [34]J. Otto, “Enabling reproducibility in ROS 2 by ensuring sequence deterministic callback execution,” Master’s thesis, Ulm University, 2023.
  35. [35]H. Teper, S. Lin, S. Li, E. A. Lee, and J.-J. Chen, “Deterministic execution of ROS 2 applications via Lingua Franca,” arXiv:2606.09203, 2026.arxiv.org/abs/2606.09203
  36. [36]M. Lohstroh, C. Menard, S. Bateni, and E. A. Lee, “Toward a Lingua Franca for deterministic concurrent systems,” ACM Trans. Embedded Comput. Syst., vol. 20, no. 4, pp. 36:1–36:27, 2021.DOI
  37. [37]J. Kwok, S. Li, M. Lohstroh, and E. A. Lee, “HPRM: High-performance robotic middleware for intelligent autonomous systems,” in Proc. IEEE Int. Conf. Robotics and Automation (ICRA), 2025.arxiv.org/abs/2412.01799
  38. [38]E. A. Lee and M. Lohstroh, “Generalizing logical execution time,” in Principles of Systems Design, ser. LNCS. Springer, 2022, vol. 13660, pp. 160–181.DOI
  39. [39]T. A. Henzinger and C. M. Kirsch, “The embedded machine: Predictable, portable real-time code,” in Proc. ACM SIGPLAN Conf. Programming Language Design and Implementation (PLDI), 2002.
  40. [40]A. Biondi and M. Di Natale, “Achieving predictable multicore execution of automotive applications using the LET paradigm,” in Proc. IEEE Real-Time and Embedded Technology and Applications Symp. (RTAS), 2018.DOI

Paper details

vlnc:W_hwthjxw4
Version
v1 · latest
Published
Fresh — added to the Hub within the last 30 days
Added
License
CC BY 4.0
Usage

views · 8

downloads · 0

A view counts once per browser per day, a download each time the PDF is requested.

  • Computer Science

Not recorded for this paper

View statement
Looking for related papers…
Contents