run the profiler on the board: python web2py.py -F <profiles dir>
make your app operate as usual. Do so for a limited amount of time since the directory is going to be filled with profiling files. move the profiling files to your desktop machine and analyze them all together with runsnake (pip install runsnakerun). That should help to find the exact spot where the load is. mic 2014-02-12 21:13 GMT+01:00 Michael Ellis <michael.f.el...@gmail.com>: > I'm doing some embedded development with Web2py 2.8.2 on a BeagleBone > Black (specs here) running a no-gui ubuntu. Mostly it's going very well so > far, but I need some help reducing cpu usage for an ajax call that one of > my pages is running every 2 seconds. > > A typical sample of the data returned is at the bottom of this post along > with the code involved. The data length never exceeds about 1 kbyte. > > My problem is that when the page with the ajax call is being viewed, the > cpu usage is averaging 25% as measured by top. If I make a second > connection, the usage doubles to 50%, and so on. Obviously four users > viewing the page will make the system unusable. The nature of the > application is such that it would be rare to have more than one technician > logged in, but it's certainly possible that several people might try to > log in simultaneously, so I feel the performance does need to be addressed. > > I've already tried: > > Turning off migration > Putting the ajax function in it's own controller and view > > Those actions got me from 30% to 25%. I've verified, by running the > controller function in a standalone script, that the function itself only > consumes about 1.5% cpu when called every 2 seconds. The view is trivial. > It calls BEAUTIFY on the dict returned by the ajax function. Taking out the > BEAUTIFY helper made no measure difference. I've also verified that the > system is using less than 30% of available RAM. > > Web2py is serving the pages unencrypted through the board's ethernet > adapter. FWIW, when I simultaneously run 'top -s2' over ssh to a terminal > window the display shows that top itself and sshd together are using less > than 2% of cpu to send a comparable amount of data at the same update rate > (2 seconds) as my ajax call. > > Should I assume the rocket server is the culprit? I have apache available > on the board but have no idea if it's worth the trouble to get it running > and change the web2py config to use it. > > Can anyone suggest some further diagnostics? > Thanks (as always!) > Mike > > *Here's the part of the page view that calls the ajax:* > <div id="statehouse_component"> > </div> > {{=LOAD(c='ajax', f='statehouse_poll.load', ajax=True, > target="statehouse_component", > user_signature=True, > timeout=2000, times='infinity') }} > > *Here's the ajax view:* > {{=BEAUTIFY(state)}} > *The controller:* > @auth.requires_login() > def statehouse_poll(): """ Controller for monitor ajax polling page """ > from statehouse_ajax import _statehouse_poll > return _statehouse_poll() > > *and the function itself:* > def _statehouse_poll(): > > """ Function for Monitor ajax """ > import time > import zmq > from statehouse import STATEHOUSE_PORT > context = zmq.Context() > statehouse_socket = context.socket(zmq.REQ) > statehouse_socket.connect("tcp://localhost:{}".format(STATEHOUSE_PORT)) > statehouse_socket.send_json(dict(key='all', action='dump')) > state = statehouse_socket.recv_json() > > for s in state.values(): > for k in s.keys(): > if k == 'timestamp': > s[k] = time.asctime(time.localtime(s[k])) ## From unixtime > to human readable string > > return dict(state=state) > > *and, finally, a sample of the data* > > {u'cbs': {u'vbattery2': 13.5, u'vbattery1': 13.5, u'timestamp': 'Wed Feb > 12 19:00:27 2014', u'load_on': False, u'iload': 0.0, u'charging': True, > u'icharge': 0.8}, u'annualtest': {u'status': u'inactive'}, u'standbytest': > {u'status': u'completed', u'charger': u'pass', u'battery2': u'pass', > u'battery1': u'pass', u'timestamp': 'Wed Feb 12 16:13:06 2014'}, u'cbscmd': > {u'timestamp': 'Wed Feb 12 16:13:56 2014', u'charge': True, u'load_on': > False}, u'monthlytest': {u'load': u'pass', u'status': u'completed', > u'timestamp': 'Wed Feb 12 16:13:56 2014', u'switch': u'pass', u'battery1': > u'pass', u'battery2': u'pass'}} > > > -- > Resources: > - http://web2py.com > - http://web2py.com/book (Documentation) > - http://github.com/web2py/web2py (Source code) > - https://code.google.com/p/web2py/issues/list (Report Issues) > --- > You received this message because you are subscribed to the Google Groups > "web2py-users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to web2py+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/groups/opt_out. > -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.