On 22 marras, 08:27, Dan Ancona <afightingfa...@gmail.com> wrote:
> python 2.7.3, django 1.4.2
>
> Our app (a fairly simple tastypie API that runs some machine learning foo on 
> mongodb records) is deployed to heroku and is leaking memory at a pretty good 
> clip. Hitting heroku memory errors after about an hour or two, under 
> significant load.
>
> Wandered through some various profiling options and eventually started to get 
> suspicious of tastypie. So I tried ripping that out. And then everything 
> else, until I finally got down to a django view that has nothing but this in 
> it:
>
> def stack(request):
>    gc.set_debug(gc.DEBUG_LEAK)
>    print "Uncollectable garbage", gc.garbage
>    return HttpResponse('hi')

If you set gc.DEBUG_LEAK then the GC will not free anything, instead
it will append garbage to gc.garbage. So, getting everything into
gc.garbage is expected in that case.

You will want to remove the gc.set_debug() call.

Here is an example without the call:

import gc
from django.http import HttpResponse

# Objects which have __del__ defined and are part of reference cycle
will be uncollectable.
class A(object):
    def __del__(self):
        pass
class B(object):
    pass

def stack(request):
    a = A()
    b = B()
    # Lets create a cycle
    a.b = b
    b.a = a
    print(gc.garbage)
    return HttpResponse('hi')


Load the view a couple of times and you will see garbage accumulating.
It will contain only the A objects - they are uncollectable because of
the __del__ method.

 - Anssi

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to