slow Win_ros service calls

120 views
Skip to first unread message

Major Xbla

unread,
Jan 16, 2014, 8:58:47 AM1/16/14
to win...@googlegroups.com
I builded win-ros for 64bit with MSVC and Boost 1_55
and now want to test ROS-Services.
I compiled the Beginner tutorial and run it but get realy slow behavior

source code:

#include "stdafx.h"
#include <ros/ros.h>
#include <custom_msgs\HelloDude.h>

int main(int argc, char **argv)
{
  ros::init(argc, argv, "client");

  ros::spinOnce();
  ros::NodeHandle n;
  ros::ServiceClient client = n.serviceClient<custom_msgs::HelloDude>("dude_service");
  //ros::ServiceClient client2 = n.serviceClient<custom_msgs::HelloDude>(

  custom_msgs::HelloDude srv;
  srv.request.greeting = "my testing hello";


  //beginner_tutorials::AddTwoInts srv;
  ros::service::waitForService("dude_service");
  ros::Time begin, end;
  for(int i = 0; i < 50; i++) {
      begin = ros::Time::now();
      if (client.call(srv))
      {
          ROS_INFO("Sum: %s",srv.response.dude.Dude.c_str());
      }
      else
      {
        ROS_ERROR("Failed to call service add_two_ints");
        return 1;
      }
      end = ros::Time::now();
      ROS_INFO("ellapsed : %f\n", end.toSec() - begin.toSec());

  }

  return 0;
}


the function client.call(srv) need around 100ms for a call. On linux the same code needs 10ms.
is there a possibility to get it faster???

many thanks
major

Major Xbla

unread,
Jan 20, 2014, 11:33:00 AM1/20/14
to win...@googlegroups.com
found a solution:
problem is the impizit persistent option in Constructer of serviceclient.

ServiceClient ros::NodeHandle::serviceClient ( const std::string &  service_name,


bool  persistent = false,


const M_string header_values = M_string() 

)

if i set these parameter true
ros::ServiceClient client = n.serviceClient<custom_msgs::HelloDude>("dude_service",true);
the timing behavior is fine(~5ms).

only disadvantage is:
if connection get broken erors accourt
so you need to Handle these by your own maybe with a try catch block
more information could be found here:
http://answers.ros.org/question/99746/win_ros-service-call-problems-its-reqres-speed-is-very-slow/



Daniel Stonier

unread,
Jan 29, 2014, 6:06:08 AM1/29/14
to win...@googlegroups.com
That's a really interesting observation. I've also noticed slowness in roslaunching programs as well - I suspect there's slowness in the execution of some (if not all) python components. I opened an issue for this a long time ago but I haven't had the time to nail down why. This may be a similar issue - xmlrpc connections are negotiated at the python rosmaster.

Major Xbla

unread,
Jan 29, 2014, 8:56:28 AM1/29/14
to win...@googlegroups.com
hmm i think this is not the problem,
I,ve tested with windows and linux roscore.
And with a Master on a linux-server , I've got different behavior:
With a client programm written in c++ on linux on same machine I got fast behavior (<5ms),
with a client programm written in c++ on linux but different machine I got fast behavior (<5ms),
with a client programm written in c++ on windows with winros on different machine I got slow behavior (>100ms).
I used the same clinet code for subscribing to the service. The Servercode didn't change.

Than i changed the code
old:
ros::ServiceClient client = n.serviceClient<custom_msgs::HelloDude>("dude_service");

new:
ros::ServiceClient client = n.serviceClient<custom_msgs::HelloDude>("dude_service"
,true);

only in the windows version. And now i get on the windows clinet machine a very fast behavior(<5ms).
There is also no use of rosrun and roscore in windows. the nodes are compiled as executable under VS2010 using roslibs:

roscpp.lib;roscpp_serialization.lib;rosconsole.lib;rostime.lib;

as explained here
http://wiki.ros.org/win_ros/hydro/Msvc%20SDK%20Projects

I think there is no use of python components under windows. My idea for this slow behavior is another implementation of the persistent option under win_ros, maybe the socket is created new in every call. So the bad timebehavior resulted from the socklet creation, maybe...

Daniel Stonier

unread,
Feb 3, 2014, 3:35:24 AM2/3/14
to win...@googlegroups.com
Great data, thanks. Don't have the resources to look at it here now, but at least it narrows it down for someone who is interested in solving the problem. Looks like it must be either in xmlrpclib or roscpp itself. Probably a good next step would be to write a simple xmlrpc node to node connection and see if there's problems there. I updated the github issue.

Daniel.
 

jmw...@cogsimtech.com

unread,
Aug 14, 2014, 4:18:10 PM8/14/14
to win...@googlegroups.com
(This was also posted under github issue #26 -> https://github.com/ros-windows/win_ros/issues/26 I'm cc:'ing here for the sake of people trying to google a fix)

Post for community knowledge. This bug was causing us some serious usability issues with rosbridge_suite on Win7 x64 to execution actionlib actions (C++ server) via roslibjs. Essentially, the our javascript code would run faster than rosbridge could keep up and all our results/feedback were dropping.

There may be numerous slowdown reasons in windows, but a clear culprit is the XMLRPC library in python.  Digging around on the web it seems that this library (or perhaps pythons) DNS resolution, including 'localhost', is tremendously slow on Win7/8. It does not matter if localhost is explicitly set in your hosts file. As a quick test I changed my ROS_MASTER_URI env variables to be the IP address of the machines (e.g. 192.168.0.1:11311) instead of 'localhost:11311' or any other domain name. Sure enough across the board things run much, much faster including ros process startup, actions, services, etc. A quick fix is to simply set these environment variable yourself, in the long run perhaps the XMLRPC code needs to change for the windows platform ( this might be a potential fix http://www.answermysearches.com/xmlrpc-server-slow-in-python-how-to-fix/2140/ )

Jon

Daniel Stonier

unread,
Nov 3, 2014, 3:29:24 AM11/3/14
to win...@googlegroups.com
Nice digging Jon!

--
You received this message because you are subscribed to the Google Groups "Ros on Windows" group.
To unsubscribe from this group and stop receiving emails from it, send an email to win-ros+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Reply all
Reply to author
Forward
0 new messages