1

I inherited a legacy app with the following structure:

gunicorn (with 64 workers) is started and pointed at a paste.deploy app, which looks like this:

from paste.deploy import loadapp
import gevent
import json

def ohmygod():
    while 1:
        time.sleep(30)
        horrible, extremely expensive debugging function()

gevent.spawn(ohmygod)

application = loadapp('config:scripts/production.ini', relative_to='/blah')

This app's performance is business critical, but my attempts to remove this code need some profiling evidence.

I'm a little out of my league when it comes to debugging gevents inside of gunicorn though.

If I created a cProfiler inside of that function, would it pick up data from outside of the gevent, ie.: from the main ? I think this would be desirable.

A further problem is that I can't modify production code. I have access to test environments, but I can't replicate live traffic. Is it possible to safely attach to running gunicorn processes and profile them without modifying production code?

Any tips or insights much appreciated.

gunicorn v18.0, gevent v1.0.1, pyramid 1.4.5, python 2.7.6 running on Ubuntu 12 x64

Danielle M.
  • 3,607
  • 1
  • 14
  • 31
  • [*Try this.*](http://stackoverflow.com/a/4299378/23771) It won't cost you anything. There is actually a lot of [*mathematical justification*](http://scicomp.stackexchange.com/a/2719/1262) behind it, if that's of any help. – Mike Dunlavey Oct 27 '16 at 21:58

1 Answers1

2

Try using app enlight middleware to figure out the bottlenecks: https://getappenlight.com/page/api/main.html

You can decorate some functions to time them separately.

Ergo
  • 1,205
  • 9
  • 16
  • Thanks Ergo. One of the reasons I posted this question is that I'm not sure where pyramid gunicorn ands and pyramid begins. Is the ohmygod() function inside pyramid? – Danielle M. Oct 28 '16 at 15:15
  • 1
    `ohmygod()` could be considered part of pyramid application if you spawn a separate greenlet from pyramid wsgi application - your example includes nothing related to pyramid for now - hard to guess without more concrete example. Generally gunicorn is just a WSGI server and your business logic lives wrapped in pyramid application. – Ergo Oct 29 '16 at 09:42