Performance: Why services handle request-response interactions
This concept affects how quickly a system can respond to requests and how efficiently resources are used during communication.
Using ROS services to handle request-response interactions explicitly
Using continuous topic subscriptions for single request-response interactions instead of services| Pattern | CPU Usage | Message Traffic | Latency | Verdict |
|---|---|---|---|---|
| Continuous topic subscription for request-response | High | High | High | [X] Bad |
| ROS service request-response | Low | Low | Low | [OK] Good |
import rospy
from beginner_tutorials.srv import AddTwoInts
rospy.wait_for_service('add_two_ints')
add_two_ints = rospy.ServiceProxy('add_two_ints', AddTwoInts)
response = add_two_ints(3, 4)
print(response.sum)def handle_add_two_ints(req):
return req.a + req.b
service = rospy.Service('add_two_ints', AddTwoInts, handle_add_two_ints)
rospy.spin()Pass the test and this pattern moves unknown