Skip to content

Improve RTF Stability and Precision (backport #3269)#3275

Merged
azeey merged 1 commit intomainfrom
mergify/bp/main/pr-3269
Jan 20, 2026
Merged

Improve RTF Stability and Precision (backport #3269)#3275
azeey merged 1 commit intomainfrom
mergify/bp/main/pr-3269

Conversation

@mergify
Copy link
Copy Markdown
Contributor

@mergify mergify Bot commented Jan 20, 2026

🦟 Bug fix

Summary

This PR addresses long standing issues with RTF stability and precision in Gazebo. The way we were calculating the amount of time to sleep between each time step was based on predicting the next steps duration based on the previous steps, leading to inaccuracies when CPU workloads fluctuated. There was also a moving average that caused a steady state error on the RTF, so 100% RTF was never reached

Additionally, when running Gazebo with high RTFs, the desired RTF could not be reached because we always relied on sleep_for sleeping for the precise amount of time. But due to the way OS scheduling and CPU power saving states work, sleep_for would almost always overshoot.

Changes Implemented:

  1. Shift to Reactive sleep_until Loop: Work for the current step is completed first, and then the thread sleeps only for the remaining time in its budget, eliminating the "cart before the horse" problem.

  2. High-Precision Hybrid Timing: To achieve sub-millisecond RTF accuracy, std::this_thread::sleep_until was replaced with a hybrid sleep/busy-wait strategy. For long waits, sleep_until is used for efficiency. For the final, critical few hundred microseconds before the deadline, a busy-wait (spin-wait) loop is employed.

Screenshots

The following plots were generated by piping the topic /stats/realtime_factor to plotjuggler. Gazebo was launched with gz sim -v4 default.sdf -s -r -z 2000 with a target RTF of 200% (2 in the plots).

RTF fluctates and has steady state error before this PR
Old_RTF

RTF is stable and achieves the desired RTF
New_RTF

RTF fluctates and has steady state error before this PR

Old_RTF.mov

RTF is stable and achieves the desired RTF

New_RTF.mov

Checklist

  • Signed all commits for DCO
  • Added tests
  • Updated documentation (as needed)
  • Updated migration guide (as needed)
  • Consider updating Python bindings (if the library has them)
  • codecheck passed (See contributing)
  • All tests passed (See test coverage)
  • While waiting for a review on your PR, please help review another open pull request to support the maintainers
  • Was GenAI used to generate this PR? If so, make sure to add "Generated-by" to your commits. (See this policy for more info.)

Generated-by: Gemini 2.5 Pro

Note to maintainers: Remember to use Squash-Merge and edit the commit message to match the pull request summary while retaining Signed-off-by and Generated-by messages.


This is an automatic backport of pull request #3269 done by [Mergify](https://mergify.com).

* Fix delay calculation in each time step to achieve desired RTF
* Use a hybrid sleep/busy-loop for better precision
* Make Server_TEST more robust

---------

Signed-off-by: Addisu Z. Taddese <addisu@openrobotics.org>
(cherry picked from commit 6759b33)
@mergify mergify Bot requested a review from arjo129 as a code owner January 20, 2026 19:26
@mergify mergify Bot mentioned this pull request Jan 20, 2026
9 tasks
@github-project-automation github-project-automation Bot moved this from Inbox to In review in Core development Jan 20, 2026
@azeey azeey merged commit 7dac4fb into main Jan 20, 2026
15 checks passed
@azeey azeey deleted the mergify/bp/main/pr-3269 branch January 20, 2026 23:16
@github-project-automation github-project-automation Bot moved this from In review to Done in Core development Jan 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

1 participant