How to optimize service calls
I'm trying to optimize my code so I was measuring how long different parts of ROS process take. Specifically
rospy.wait_for_service(rospy.get_param('~service_name'))
always seems to take little over 2 ms
service = rospy.ServiceProxy(rospy.get_param('~service_name'), MySrv)
always seems to take little under 1 ms
resp = service(MySrvRequest())
always seems to take little over 1 ms
This all causes the one service call to result in about 4 ms of delay and I want to get my program to 1 ms precision. What are the variables that effect how long those service calls take? Can I adjust the setting somewhere to make it faster?
Service calls use the networking functions to communicate with different nodes. So their speed is effected by many factors. If the service server node was on a different computer These numbers could be much higher! If you really need speed and consistency that much then you'll have to try and merge functionality into a single node (binary)