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

change flushing behavior for spdlog log files, and add env var to use old style (no explicit flushing) #95

Merged
merged 3 commits into from
Nov 17, 2022

Conversation

wjwwood
Copy link
Member

@wjwwood wjwwood commented Nov 9, 2022

While working on a project we noticed some applications have missing log messages or no log file at all when it crashes. This isn't a good experience for users when debugging, so this pr changes the flushing behavior of spdlog to flush every five seconds as well as anytime the error log level is used.

A new environment variable is introduced to allow users to opt-out of this back to the old behavior (no explicit configuration) and is meant to be temporary until we support full config files (planned work).

The new env var is called RCL_LOGGING_SPDLOG_EXPERIMENTAL_OLD_FLUSHING_BEHAVIOR and setting it to 1 will get you the old behavior. I'm very open to other names, but the "EXPERIMENTAL" is in there in part to indicate we would like to remove this in the future in favor of the config files, i.e. this is experimental and you cannot rely on it in the next version of ROS.

… old style (no explicit flushing)

Signed-off-by: William Woodall <william@osrfoundation.org>
@wjwwood wjwwood added the enhancement New feature or request label Nov 9, 2022
@wjwwood wjwwood self-assigned this Nov 9, 2022
@wjwwood
Copy link
Member Author

wjwwood commented Nov 9, 2022

I also ran the (micro)benchmark tests with and without this change, but didn't see a difference:

william@markook-ubuntu-2204:~/ros2_ws$ ./build/rcl_logging_spdlog/benchmark_logging_interface
2022-11-08T18:00:15-08:00
Running ./build/rcl_logging_spdlog/benchmark_logging_interface
Run on (8 X 48 MHz CPU s)
Load Average: 0.05, 0.20, 0.27
***WARNING*** Library was built as DEBUG. Timings may be affected.
--------------------------------------------------------------------------------------
Benchmark                                            Time             CPU   Iterations
--------------------------------------------------------------------------------------
LoggingBenchmarkPerformance/log_level_hit         2486 ns         2485 ns       385499
LoggingBenchmarkPerformance/log_level_miss        79.4 ns         79.4 ns      8576005
PerformanceTest/logging_reinitialize              22.7 ns         22.7 ns     30958001
PerformanceTest/logging_initialize_shutdown      82145 ns        57918 ns        11809

<rebuilt on rolling here>

william@markook-ubuntu-2204:~/ros2_ws$ ./build/rcl_logging_spdlog/benchmark_logging_interface
2022-11-08T18:06:02-08:00
Running ./build/rcl_logging_spdlog/benchmark_logging_interface
Run on (8 X 48 MHz CPU s)
Load Average: 0.00, 0.07, 0.18
***WARNING*** Library was built as DEBUG. Timings may be affected.
--------------------------------------------------------------------------------------
Benchmark                                            Time             CPU   Iterations
--------------------------------------------------------------------------------------
LoggingBenchmarkPerformance/log_level_hit         2626 ns         2625 ns       293706
LoggingBenchmarkPerformance/log_level_miss        80.6 ns         80.6 ns      8780122
PerformanceTest/logging_reinitialize              23.0 ns         23.0 ns     30313922
PerformanceTest/logging_initialize_shutdown      13809 ns        13773 ns        51663

Though it was with a debug build and I'm not 100% sure the benchmarks cover all cases, or cases where this would impact performance (rapid error messages being logged).

Copy link
Member

@ivanpauno ivanpauno left a comment

Choose a reason for hiding this comment

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

LGTM with green CI!
I have left some minor suggestions

@wjwwood
Copy link
Member Author

wjwwood commented Nov 14, 2022

CI:

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

@wjwwood
Copy link
Member Author

wjwwood commented Nov 14, 2022

Working on the doc changes (release notes, etc).

Signed-off-by: William Woodall <william@osrfoundation.org>
@clalancette
Copy link
Contributor

With the latest changes in place, this is functioning like I expect. So I decided to do some testing.

In particular, I went back and repeated the test where I modified the talker to publish and print every 1 millisecond.

To start with, I wanted to measure the overhead of running the timer and publisher at this frequency, without any overhead from the RCLCPP_INFO call. So I ran the talker like this:

ros2 run demo_nodes_cpp talker --ros-args --disable-rosout-logs --disable-stdout-logs --disable-external-lib-logs

(that is, disable output to /rosout, stdout, and the external library which is spdlog in this case). With that setup, the talker takes about 38% CPU.

I then reenabled just the external library (the spdlog logger), by running:

ros2 run demo_nodes_cpp talker --ros-args --disable-rosout-logs --disable-stdout-logs

Now the talker is taking about 41% CPU.

Next I went back and checked out rcl_logging before this PR. I ran the same experiment without this PR in place, and the numbers I got were 39% CPU for no output, and 42% CPU with just the external library output enabled.

I should note that all of this was on my Raspberry Pi 4 with a slow SD card.

Thus, I'm more confident that this change should have minimal overhead. As far as I'm concerned, this is good to go in once @scpeters concerns have been addressed.

@wjwwood
Copy link
Member Author

wjwwood commented Nov 16, 2022

Thanks for the extra testing @clalancette!

Signed-off-by: William Woodall <william@osrfoundation.org>
@wjwwood
Copy link
Member Author

wjwwood commented Nov 16, 2022

CI:

  • Linux Build Status
  • Linux-aarch64 Build Status
  • Windows Build Status (restarted due to download failure)

@wjwwood
Copy link
Member Author

wjwwood commented Nov 17, 2022

Docs update: ros2/ros2_documentation#3193

@wjwwood wjwwood merged commit 0997e5d into rolling Nov 17, 2022
@delete-merged-branch delete-merged-branch bot deleted the change_spdlog_flushing_behavior branch November 17, 2022 05:59
@wjwwood
Copy link
Member Author

wjwwood commented Nov 18, 2022

I made a release for this: ros/rosdistro#35370

wjwwood added a commit to ros2/ros2_documentation that referenced this pull request Nov 18, 2022
* release note about change to log file flushing

ros2/rcl_logging#95

* mention the volatility of the env var

* Apply suggestions from code review

Co-authored-by: Ivan Santiago Paunovic <ivanpauno@ekumenlabs.com>
Co-authored-by: Audrow Nash <audrow@openrobotics.org>

* emphasize note about experimental status

also link to issue about logging config file plans

Co-authored-by: Ivan Santiago Paunovic <ivanpauno@ekumenlabs.com>
Co-authored-by: Audrow Nash <audrow@openrobotics.org>
mergify bot pushed a commit to ros2/ros2_documentation that referenced this pull request Nov 18, 2022
* release note about change to log file flushing

ros2/rcl_logging#95

* mention the volatility of the env var

* Apply suggestions from code review

Co-authored-by: Ivan Santiago Paunovic <ivanpauno@ekumenlabs.com>
Co-authored-by: Audrow Nash <audrow@openrobotics.org>

* emphasize note about experimental status

also link to issue about logging config file plans

Co-authored-by: Ivan Santiago Paunovic <ivanpauno@ekumenlabs.com>
Co-authored-by: Audrow Nash <audrow@openrobotics.org>
(cherry picked from commit 2002bbd)
mergify bot pushed a commit to ros2/ros2_documentation that referenced this pull request Nov 18, 2022
* release note about change to log file flushing

ros2/rcl_logging#95

* mention the volatility of the env var

* Apply suggestions from code review

Co-authored-by: Ivan Santiago Paunovic <ivanpauno@ekumenlabs.com>
Co-authored-by: Audrow Nash <audrow@openrobotics.org>

* emphasize note about experimental status

also link to issue about logging config file plans

Co-authored-by: Ivan Santiago Paunovic <ivanpauno@ekumenlabs.com>
Co-authored-by: Audrow Nash <audrow@openrobotics.org>
(cherry picked from commit 2002bbd)
mergify bot pushed a commit to ros2/ros2_documentation that referenced this pull request Nov 18, 2022
* release note about change to log file flushing

ros2/rcl_logging#95

* mention the volatility of the env var

* Apply suggestions from code review

Co-authored-by: Ivan Santiago Paunovic <ivanpauno@ekumenlabs.com>
Co-authored-by: Audrow Nash <audrow@openrobotics.org>

* emphasize note about experimental status

also link to issue about logging config file plans

Co-authored-by: Ivan Santiago Paunovic <ivanpauno@ekumenlabs.com>
Co-authored-by: Audrow Nash <audrow@openrobotics.org>
(cherry picked from commit 2002bbd)
clalancette pushed a commit to ros2/ros2_documentation that referenced this pull request Nov 21, 2022
* release note about change to log file flushing

ros2/rcl_logging#95

* mention the volatility of the env var

* Apply suggestions from code review

Co-authored-by: Ivan Santiago Paunovic <ivanpauno@ekumenlabs.com>
Co-authored-by: Audrow Nash <audrow@openrobotics.org>

* emphasize note about experimental status

also link to issue about logging config file plans

Co-authored-by: Ivan Santiago Paunovic <ivanpauno@ekumenlabs.com>
Co-authored-by: Audrow Nash <audrow@openrobotics.org>
(cherry picked from commit 2002bbd)

Co-authored-by: William Woodall <william@osrfoundation.org>
clalancette pushed a commit to ros2/ros2_documentation that referenced this pull request Nov 21, 2022
* release note about change to log file flushing

ros2/rcl_logging#95

* mention the volatility of the env var

* Apply suggestions from code review

Co-authored-by: Ivan Santiago Paunovic <ivanpauno@ekumenlabs.com>
Co-authored-by: Audrow Nash <audrow@openrobotics.org>

* emphasize note about experimental status

also link to issue about logging config file plans

Co-authored-by: Ivan Santiago Paunovic <ivanpauno@ekumenlabs.com>
Co-authored-by: Audrow Nash <audrow@openrobotics.org>
(cherry picked from commit 2002bbd)

Co-authored-by: William Woodall <william@osrfoundation.org>
clalancette pushed a commit to ros2/ros2_documentation that referenced this pull request Nov 21, 2022
* release note about change to log file flushing

ros2/rcl_logging#95

* mention the volatility of the env var

* Apply suggestions from code review

Co-authored-by: Ivan Santiago Paunovic <ivanpauno@ekumenlabs.com>
Co-authored-by: Audrow Nash <audrow@openrobotics.org>

* emphasize note about experimental status

also link to issue about logging config file plans

Co-authored-by: Ivan Santiago Paunovic <ivanpauno@ekumenlabs.com>
Co-authored-by: Audrow Nash <audrow@openrobotics.org>
(cherry picked from commit 2002bbd)

Co-authored-by: William Woodall <william@osrfoundation.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants