On Tue, Apr 7, 2009 at 6:02 PM, Christian Joergensen <m...@razor.dk> wrote:
> > AndyB wrote: > > I've got a Django app that seems to eat up a lot of memory. I posted a > > message on Stack Overflow and it got a little sidetracked into a > > debate about the merits of WSGI and Apache in Worker MPM mode. > > First thing - make sure DEBUG is set to off. > > If that's not the problem, Let me take a wild shoot in the dark; are you > by any chance looping through a large queryset? > > I recently had a proces hog about 1.8 GB RAM when looping through a > queryset with approx. 350k items as: > > for obj in Model.objects.all(): > do_something(obj) > > I rewrote it to: > > objs = Model.objects.all().values_list("id", flat=True) > for obj_id in objs: > obj = Model.object.get(pk=obj_id) > do_something(obj) > > ... and my RAM usage was below 30 MB at all time. > You also executed 350k SQL queries. A better idea would be to start with: for obj in Model.objects.all().iterator(): do_something(obj) > > > Maybe it's getting late and I deserve a nice gin and tonic... > > Cheers, > > -- > Christian Joergensen > http://www.technobabble.dk > > > > Alex -- "I disapprove of what you say, but I will defend to the death your right to say it." --Voltaire "The people's good is the highest law."--Cicero --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---