Ask Your Question
2

rosbridge CPU usage

asked 2012-01-28 07:57:51 -0500

Rodrigo Gutierrez gravatar image

I've noticed on two of the development environments that I've been using that rosbridge has a tendency to consume a large amount of the CPU's resources. One dev environment is a VirtualBox VM, and the other is a Linode 512 server, both running Ubuntu 11.04 with ros-electric-brown-remotelab version 0.0.15-s1326515606. In each case establishing a connection to rosbridge through my web browser is enough to produce this behavior. Have others seen this? Are there suggested minimum machine requirements for rosbridge? If this is a common problem, is there anything that I can do to reduce the machine load?

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
0

answered 2012-02-03 06:08:32 -0500

tjay gravatar image

Victor,

Thanks so much for the bug-fix and for cross-posting this to our Google Code issue tracker ( http://code.google.com/p/brown-ros-pkg/issues/detail?id=11 ). I've just incorporated this fix into our SVN version ( svn co https://brown-ros-pkg.googlecode.com/svn/trunk/experimental/rosbridge rosbridge ) and it will be available in the Electric and Diamondback binaries as soon as Willow refreshes their distribution (the packages will be labeled 0.0.19).

What your fix basically does is make the loop sensitive to the HZ parameter. Since the default HZ in your version is so low (200Hz) CPU usage drops dramatically. However, at the moment most of our users are expecting performance to favor throughput. I've thus changed the default HZ to 100000 (equivalent to 100 kHz) coincident with applying your fix. This will mean that if you want to cut down on CPU usage, you'll need to specify your own HZ as the default will do quite a bit of spinning.

One other thing I should mention is that the 100% usage is a bit misleading and you should always try to run rosbridge alongside your planned load. While select operations will dominate a CPU on an "empty" processor according to top, they are still blocking (as called in rosbridge) and present yield opportunities. The end result is that while rosbridge will take 100% of a CPU with no other load, it will not in general effect the performance of other applications very much (if at all). For example, when you run Gazebo (a CPU-bound process) on the same core, rosbridge will only take up ~1% of the proc according to top.

Thanks again for the patch!

_Trevor

edit flag offensive delete link more
2

answered 2012-02-01 01:02:30 -0500

Victor Lopez gravatar image

updated 2012-02-01 01:04:35 -0500

I'm having the same issue, with the latest publicly available version of rosbridge accessing using TCP Sockets.

Messing with the code and with some profilers, I've seen that there's a loop in the serveForever function in ws.py file that is what's consuming most of the cpu time.

What I've seen is that in the loop there are two calls to the select method. These calls have a timeout which is configurable using the --hz parameter. But in my case this parameter changed nothing.

The thing is, that these selects were returning immediately, because my socket was available for output (the outputReady list contained a connection to my socket). Therefore the loop spinned forever without control or sleeps.

My solution (though it might have many side effects, i've not tested it extensively) is to replaced the outgoing parameter in the first select, and the incoming parameter in the second select, with an empty list.

What this does is that the first select doesn't end immediately, and waits for its timeout, which reduces the CPU usage to 3% on my computer. Still a lot, but I guess you can play with the hz parameter to reduce it even more.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2012-01-28 07:57:51 -0500

Seen: 1,114 times

Last updated: Feb 03 '12