Hi all,

Fairly new to Django. I ended up pulling out all of the ORM-generated 
queries and writing my own SQL directly (I got fed up trying to work out 
how to achieve the kind of things I needed without Django adding in extra 
joins or unintended WHERE clauses etc). All my app's SQL uses 
cursor.execute() and the dictfetchall() method as referenced 
here<https://docs.djangoproject.com/en/dev/topics/db/sql/#django.db.models.Manager.raw>
. 

I've found that my app incurs a couple of seconds load time in production, 
with CPU time at 2532ms and overall time 4684ms (according to the debug 
toolbar). I'm seeing 8 SQL queries take 380ms, and each one seems to be 
several times slower when made by Django versus hitting the database 
through phpMyAdmin or something: eg, this query:

SELECT * FROM news 
JOIN news_categories ON news.news_category_id = news_categories.id 
LEFT JOIN writers ON news.writer_id = writers.id 
LEFT JOIN images ON news.image_id = images.id 
ORDER BY news.is_sticky DESC, news.date_posted DESC 
LIMIT 10


This takes 14.8ms when run in phpMyAdmin (against the production database) 
but Django reports it as 85.2ms. The same ratios are true for all my other 
queries.

All I can think of is the note on the dictfetchall() method in the Django 
docs which describes a "small performance hit". Is this it?!

I've profiled the app too, although I'm a bit hazy about what it all means. 
Here's a dump of the result: http://pastebin.com/raw.php?i=UHE9edVC (this 
is from running on my local server rather than production but performance 
is broadly similar).

Can anyone help me? I realise I've perhaps gone off-piste by writing raw 
SQL but I feel it was justified.

thanks,
Matt


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/Qiley9RqfngJ.
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