Performance: Request-response communication model
This concept affects the responsiveness and latency of message exchanges between nodes in a ROS system.
future = client.call_async(request)
future.add_done_callback(handle_response) # non-blocking async callresponse = client.call(request) # synchronous call blocks until reply| Pattern | Node Blocking | Latency Impact | Throughput | Verdict |
|---|---|---|---|---|
| Synchronous request-response | Blocks node execution | High latency due to waiting | Lower throughput | [X] Bad |
| Asynchronous request-response | No blocking, uses callbacks | Lower latency, faster response handling | Higher throughput | [OK] Good |
import rospy
from example.srv import AddTwoInts
def call_service():
rospy.wait_for_service('add_two_ints')
try:
add_two_ints = rospy.ServiceProxy('add_two_ints', AddTwoInts)
response = add_two_ints(20, 22)
print(response.result)
except rospy.ServiceException as e:
print("Service call failed", e)
call_service()import rospy
from example.srv import Multiply
def handle_multiply(req):
return req.a * req.b
rospy.init_node('multiply_server')
service = rospy.Service('multiply', Multiply, handle_multiply)
rospy.spin()Pass the test and this pattern moves unknown