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

Improve behavior_velocity_planner's latency #2097

Closed
3 tasks done
soblin opened this issue Oct 18, 2022 · 4 comments
Closed
3 tasks done

Improve behavior_velocity_planner's latency #2097

soblin opened this issue Oct 18, 2022 · 4 comments
Assignees
Labels
component:control Vehicle control algorithms and mechanisms. (auto-assigned) component:planning Route planning, decision-making, and navigation. (auto-assigned) component:system System design and integration. (auto-assigned) type:new-feature New functionalities or additions, feature requests.

Comments

@soblin
Copy link
Contributor

soblin commented Oct 18, 2022

Checklist

  • I've read the contribution guidelines.
  • I've searched other issues and no duplicate issues were found.
  • I've agreed with the maintainers that I can plan this task.

Description

Report from @veqcc.

Currently the latency of onTrigger function in behavior_velocity_planner has a big influence in Autoware's entire latency. Below figures show (1) the latency of behavior_path_planner and (2) behavior_velocity_planner respectively, measured in planning_simulation tutorial.

image

image

image

Especially the latency of behavior_velocity_planner is constantly not negligible (about 200ms ) given the behavior_path_planner's publication rate of 10Hz, which indicates its latency is twice the subscription rate.

image

@veqcc and @soblin are working to lower this computation time as much as possible. I'm not sure about the lower bound of this latency, but it should be at least below the behavior_path_planner's publication rate of 10Hz.

Possible approaches

  • get statistics on the functions calls
    • measure elapsed time by binary search
    • get FlameGraph
  • refactor current implementation
    • check the logic flow and return instantly as much as possible
    • avoid and delay heavy computation
    • cache lanelet stuff because this data is expected to be almost the same in each unit of behavior_velocity module.
      • define a cache class for lanelet that has CompoundPolygon3d and tier4_autowawe_utils::Polygon2d in it
  • do calculation in-place

Definition of done

  • measure the performance in realistic cases with a massive map, various & numerous obstacles, with multiple lane elements and characteristics (turn_direction, walkway, turn_signal, occlusion spot, blind spot, etc.)
  • 2x ~ 3x performance improvement would be good.
@soblin soblin added component:planning Route planning, decision-making, and navigation. (auto-assigned) component:control Vehicle control algorithms and mechanisms. (auto-assigned) component:system System design and integration. (auto-assigned) labels Oct 18, 2022
@soblin soblin self-assigned this Oct 18, 2022
@VRichardJP
Copy link
Contributor

VRichardJP commented Oct 20, 2022

Which tools do you use for profiling? I have used gperftools in the past but is there any tool recommended for autoware?

Out of curiosity, I went on and tried profiling behavior_path_planner/behavior_velocity_planner.
I did the following:

  • added prefix="gnome-terminal -- env LD_PRELOAD=/lib/x86_64-linux-gnu/libprofiler.so CPUPROFILESIGNAL=12 CPUPROFILE_FREQUENCY=1000 CPUPROFILE=/tmp/behavior_velocity_planner.profile ", to behavior_planning_container in behavior_planning.launch.py
  • launched planning_simulator, and prepared a simple environment with a few obstacles.
  • started and stopped profiling with kill -12 <CONTAINER_PID> (see https://gperftools.github.io/gperftools/cpuprofile.html)
  • generated the call tree below with: google-pprof --web install/behavior_velocity_planner/lib/behavior_velocity_planner/behavior_velocity_planner_node /tmp/behavior_velocity_planner.profile (can also use --cachegrind option instead of --web to explore the logs with kcachegrind)

pprof198588 0

For example, my sample profile shows that most of the computing time is spent in the 4 functions:

  • behavior_path_planner::util::resamplePathWithSpline()
  • behavior_path_planner::util::imageToOccupancyGrid()
  • cv::Mat::operator=() (in behavior_path_planner::util::generateDrivableArea())
  • behavior_path_planner::AvoidanceModule::calcShiftLines()

Do you have any better way to track down the performance issues?

@veqcc
Copy link
Contributor

veqcc commented Oct 21, 2022

We have used CARET (https://github.com/tier4/caret), which is an open source performance analysis tool developed by TIER IV.
Please read the CARET documentatiion!! (https://tier4.github.io/CARET_doc/main/)

@veqcc
Copy link
Contributor

veqcc commented Jan 19, 2023

The performance improvement result is in the following figure.
At the peaks of the graph, 2~2.5x performance optimizations have been realized.
image

@soblin soblin closed this as completed Jan 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component:control Vehicle control algorithms and mechanisms. (auto-assigned) component:planning Route planning, decision-making, and navigation. (auto-assigned) component:system System design and integration. (auto-assigned) type:new-feature New functionalities or additions, feature requests.
Projects
None yet
Development

No branches or pull requests

4 participants