Performance: Publish-subscribe communication model
This affects message delivery speed and CPU usage during communication between nodes in a ROS system.
Use message throttling with ros::Rate or message_filters to limit publish frequency and filter messages
publisher.publish(large_message) inside a tight loop without rate control or message filtering| Pattern | CPU Usage | Network Load | Message Latency | Verdict |
|---|---|---|---|---|
| Uncontrolled high-frequency publishing | High | High | High latency due to congestion | [X] Bad |
| Throttled publishing with message filtering | Low to Medium | Low to Medium | Low latency with smooth delivery | [OK] Good |
publisher in the ROS publish-subscribe model?import rospy
from std_msgs.msg import String
def callback(msg):
print(f'Received: {msg.data}')
rospy.init_node('listener')
sub = rospy.Subscriber('chatter', String, callback)
rospy.spin()import rospy
from std_msgs.msg import String
def callback(msg):
print(msg.data)
rospy.init_node('listener')
sub = rospy.Subscriber('chatter', String)
rospy.spin()Pass the test and this pattern moves unknown