On Mar 9, 2017 9:37 PM, "Web Architect" <pinak...@gmail.com> wrote:

Would like to further add - the python CPU Usage is hitting almost 100 %.
When I run  a Select * query on Mysql, its quite fast and CPU is normal. I
am not sure if anything more needs to be done in Django.


Ironically, things being done in Django is the reason for your CPU
utilization issue in the first place.

Calling a qs.all() is NOT the same as a SELECT * statement, even more so
when speaking to the scale of query that you mention.

Your SQL query is simply listing data in a table. A very easy thing to do,
hence the reason it runs quickly.

The qs.all() call is also running the same query (probably). However, in
addition to pulling all of the data, it is performing a transformation of
that data in to Django model objects. If you are pulling 10K items, then
Django is creating 10K objects, which is easily more intensive than a raw
SQL query, even for simple model objects.

In general, there's usually no practical reason to ever pull that many
objects from a DB for display on a page. Filter down to a reasonable number
(<100 for almost all sane cases) or implement a paging system to limit
returned results. It's also probably using a ton of RAM only to be
immediately thrown away at the end of the request. Browsers will
disintegrate trying to render that many HTML elements simultaneously.

Look at implementing a paging system, possibly through Django's built-in
mechanism, or something like Datatables and the infinite scroll plugin.

https://docs.djangoproject.com/en/dev/topics/pagination/

https://datatables.net/extensions/scroller/

-James

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2Be%2BciWjdK7wWKSUpyN-aR1b%3DkObuuerBYi85oTxCHMjrUstzg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to