-
Notifications
You must be signed in to change notification settings - Fork 678
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
feat(autoware_pointcloud_preprocessor): reuse collectors to reduce creation of collector and timer #10074
base: main
Are you sure you want to change the base?
feat(autoware_pointcloud_preprocessor): reuse collectors to reduce creation of collector and timer #10074
Conversation
Signed-off-by: vividf <[email protected]>
Thank you for contributing to the Autoware project! 🚧 If your pull request is in progress, switch it to draft mode. Please ensure:
|
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #10074 +/- ##
=======================================
Coverage 28.32% 28.32%
=======================================
Files 1485 1486 +1
Lines 111090 111153 +63
Branches 43150 43176 +26
=======================================
+ Hits 31466 31487 +21
- Misses 76603 76643 +40
- Partials 3021 3023 +2
*This pull request uses carry forward flags. Click here to find out more. ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM in codespace, but I did not check with any rosbags.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good stuff!
I've left a few comments in places I think could be simplified or where I'd like the more safety guarantees.
for (auto & collector : cloud_collectors_) { | ||
if (collector->get_status() == CollectorStatus::Idle) { | ||
selected_collector = collector; | ||
break; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be expressed as a std::find_if
instead
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! fixed in c99f1fe
sensing/autoware_pointcloud_preprocessor/src/concatenate_data/cloud_collector.cpp
Outdated
Show resolved
Hide resolved
const auto period_ns = std::chrono::duration_cast<std::chrono::nanoseconds>( | ||
std::chrono::duration<double>(timeout_sec_)); | ||
try { | ||
set_period(period_ns.count()); | ||
} catch (rclcpp::exceptions::RCLError & ex) { | ||
RCLCPP_WARN_THROTTLE( | ||
ros2_parent_node_->get_logger(), *ros2_parent_node_->get_clock(), 5000, "%s", ex.what()); | ||
} | ||
timer_->reset(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this needed? It seems to me reading the RCL source code that the period is unaffected by cancel()
and so just calling reset()
without re-setting the period should be fine, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True, thanks for pointing out!
cbb94ec
...include/autoware/pointcloud_preprocessor/concatenate_data/concatenate_and_time_sync_node.hpp
Outdated
Show resolved
Hide resolved
if (cloud_collectors_.size() > collectors_threshold) { | ||
RCLCPP_WARN_STREAM_THROTTLE( | ||
get_logger(), *get_clock(), 1000, | ||
"The number of cloud collectors (" << cloud_collectors_.size() << ") exceeds the threshold (" | ||
<< collectors_threshold | ||
<< "), be careful if it keeps increasing."); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like this to be a hard limit. In production, nobody will look at those logs, so the memory footprint could increase forever.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fix logging: a8444cb
Signed-off-by: vividf <[email protected]>
Signed-off-by: vividf <[email protected]>
Signed-off-by: vividf <[email protected]>
Signed-off-by: vividf <[email protected]>
Signed-off-by: vividf <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably hard-coding number of collectors to 2 or 3 would be okay. I don't see a use case with more collectors at the moment.
Also would allow us to allocate all of them once on startup instead of dynamically.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As discussed with @drwnz just now, it's probably a goof idea to allocate (on startup) collectors_threshold
collectors and then not add/remove any during operation.
This makes it easier to reason about the program state.
(would also get rid of L251-L260)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!!!
Fixed in 85f75e6
|
||
// Reset the collector with the oldest timestamp if found | ||
if (min_it != cloud_collectors_.end()) { | ||
RCLCPP_WARN_STREAM( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably warn_throttle would be good here as this can run n_lidars x frequency
times per second in the worst case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, fixed in a8b512f
Signed-off-by: vividf <[email protected]>
if (!selected_collector) { | ||
// If no idle collector exists, create a new collector | ||
selected_collector = std::make_shared<CloudCollector>( | ||
std::dynamic_pointer_cast<PointCloudConcatenateDataSynchronizerComponent>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dynamic creation of a new collector may not be ideal. How about we have a fixed number of collectors that are initialized, and then use the first idle one - if none are idle, kick the oldest one and reuse.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!!!
Fixed in 85f75e6
Signed-off-by: vividf <[email protected]>
Description
#8300 introduces a collector and initializes a timer in each collector with a 100 ms interval, which leads to infinite object creation and deletion.
This PR reuses collectors that are no longer in use (i.e., those that have completed concatenation) by resetting their timers, effectively converting them into new collectors. This approach helps limit unnecessary collector creation and timer initialization.
Related links
Parent Issue:
How was this PR tested?
Notes for reviewers
None.
Interface changes
None.
Effects on system behavior
None.