#16022: Cyclic reference in FieldFile causes memory usage to grow considerably
-------------------------------------+-------------------------------------
               Reporter:  Gustavo    |          Owner:  nobody
                   Type:  Bug        |         Status:  closed
              Milestone:             |      Component:  Database layer
                Version:  1.1        |  (models, ORM)
             Resolution:  needsinfo  |       Severity:  Normal
           Triage Stage:             |       Keywords:  memory leak
  Unreviewed                         |      Has patch:  0
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
-------------------------------------+-------------------------------------
Changes (by aaugustin):

 * status:  reopened => closed
 * resolution:   => needsinfo


Comment:

 I read your email to django-users which had more info and I updated my
 test code above as follows.

 `receiver/models.py`:

 {{{
 from django import forms
 from django.db import models

 class UploadModel(models.Model):
     upload = models.FileField(upload_to='receiver')

 class UploadForm(forms.ModelForm):
     class Meta:
         model = UploadModel
 }}}

 `receiver/views.py`:
 {{{
 from django.http import HttpResponse
 from django.views.decorators.csrf import csrf_exempt

 from .models import UploadForm, UploadModel

 @csrf_exempt
 def upload(request, commit=False):
     form = UploadForm(request.POST, request.FILES)
     try:
         model = form.save(commit=commit)
         action = "Saved" if commit else "Received"
         return HttpResponse("%s %i bytes.\n" % (action,
 model.upload.size),
                 status=201, content_type='text/plain')
     except ValueError:
         return HttpResponse(repr(form.errors) + "\n",
                 status=400, content_type='text/plain')

 def names(request):
     upload_names = [model.upload.name for model in
 UploadModel.objects.all()]
     return HttpResponse("%i objects \n" % len(upload_names),
             status=200, content_type='text/plain')
 }}}

 `urls.py`:
 {{{
 from django.conf.urls.defaults import patterns, url

 urlpatterns = patterns('',
     url(r'^fake/$', 'receiver.views.upload', {'commit': False}),
     url(r'^save/$', 'receiver.views.upload', {'commit': True}),
     url(r'^read/$', 'receiver.views.names'),
 )
 }}}

 I added a database, etc. to the settings and ran `syncdb`.

 I uploaded 100 1kb files:

 {{{
 myk@mYk madupload % dd if=/dev/random of=1kb.bin bs=1024 count=1
 1+0 records in
 1+0 records out
 1024 bytes transferred in 0.000232 secs (4414149 bytes/sec)
 myk@mYk madupload % for i in {1..100}; do curl -F "upload=@1kb.bin"
 http://localhost:8000/save/; done
 Saved 1024 bytes.
 Saved 1024 bytes.
 Saved 1024 bytes.
 ...
 }}}

 And then I read them over and over:

 {{{
 myk@mYk madupload % while true; do curl http://localhost:8000/read/; done
 100 objects
 100 objects
 100 objects
 ...
 }}}

 I've been heating the planet like this for a few minutes and the memory
 curve climbed a little bit at the beginning, then stabilized.

 Initially, I was using Python 2.6; I switched to Python 2.5 but the result
 was the same.

 So, unfortunately, we still don't have a proof that the bug is in Django
 itself.

 At this point, I am afraid you didn't provide sufficient information for
 me to reproduce the bug. You could:

 - try to play with `gc.garbage` to see what happens in your app, see
 http://docs.python.org/library/gc.html
 - modify my example until it exhibits the memory leak
 - come up with your own reproducible example, and provide complete
 instructions of how to run it

 Thanks!

-- 
Ticket URL: <https://code.djangoproject.com/ticket/16022#comment:8>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

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

Reply via email to