Thanks to the OP for asking this, and to all who answered. Ben, special stars to you - you just shared some very valuable insight into efficieint use of the ORM (wasn't obvious to me).
Kind regards, Lloyd On Thu, Sep 4, 2014 at 2:21 AM, Benjamin Scherrey <proteus...@gmail.com> wrote: > The short answer to your question is no, the Django ORM is not inherently > slower in that regard and it's very likely something you're doing. The > useful answer is probably more complicated. :-) Naive usage of the ORM > without an understanding of how it translates to SQL is likely to result in > some really awful non-performant database requests for any reasonably > complex models/queries. The good news is that it isn't very hard to get > quite good performance out of it. > > Impossible to give you any more specific to your particular problem > without seeing code, of course. That said, some common issues when grabbing > individual model instances related to a larger query are often dramatically > improved by using select_related() or fetch_related() as appropriate. Also > for doing large amounts of writes/updates you should look into doing the > transaction management yourself as Tom suggests. Postgres can really fly > once you understand how the ORM works with it. MySQL does nicely as well > but I have less experience with it. Ultimately, if your request can't be > efficiently modeled with the ORM (rare but does happen) then you can use > .extra() to pass in some direct SQL quite easily. > > Otherwise here's a decent little writeup of a good approach to providing > better access to your ORM models: > http://www.dabapps.com/blog/higher-level-query-api-django-orm/ > > Good luck, > > -- Ben > > > On Thu, Sep 4, 2014 at 6:22 AM, msoulier <msoul...@digitaltorque.ca> > wrote: > >> Hi, >> >> I am looking at Django's performance with respect to modifying large >> numbers of objects, each in a unique way that cannot be batched. If I make >> a simple change to one of my Django models and save(), and then do the same >> thing in sqlalchemy, I notice a performance difference of about 48 times as >> far as the rate that the objects are processed to my postgresql db. >> >> The code is a simple property update and save, in a loop, trying to >> process as many objects as possible. >> >> Is the Django ORM known to be slower in this regard, or is it likely >> something that I'm doing? >> >> Thanks, >> Mike >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Django users" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to django-users+unsubscr...@googlegroups.com. >> To post to this group, send email to django-users@googlegroups.com. >> Visit this group at http://groups.google.com/group/django-users. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/django-users/9049bff2-470e-4560-b93f-dee56bc924d4%40googlegroups.com >> <https://groups.google.com/d/msgid/django-users/9049bff2-470e-4560-b93f-dee56bc924d4%40googlegroups.com?utm_medium=email&utm_source=footer> >> . >> For more options, visit https://groups.google.com/d/optout. >> > > > > -- > Chief Systems Architect Proteus Technologies <http://proteus-tech.com> > Chief Fan Biggest Fan Productions <http://biggestfan.net> > Personal blog where I am not your demographic > <http://notyourdemographic.com>. > > This email intended solely for those who have received it. If you have > received this email by accident - well lucky you!! > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to django-users+unsubscr...@googlegroups.com. > To post to this group, send email to django-users@googlegroups.com. > Visit this group at http://groups.google.com/group/django-users. > To view this discussion on the web visit > https://groups.google.com/d/msgid/django-users/CAHN%3D9D6ATHXVzDhwoXBx1xG0hS9n%3Do6egG450Js1Hrwv9KQTBg%40mail.gmail.com > <https://groups.google.com/d/msgid/django-users/CAHN%3D9D6ATHXVzDhwoXBx1xG0hS9n%3Do6egG450Js1Hrwv9KQTBg%40mail.gmail.com?utm_medium=email&utm_source=footer> > . > > For more options, visit https://groups.google.com/d/optout. > -- Regards, Sithu Lloyd Dube -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAH-SnCCXzJYbdURYc2a-6ViouO8ZN4A-5FjJ%3Dk%3DSp2hNzgvNdQ%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.